Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 5 | // Flags: --ignition-generators |
| 6 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7 | (function testRestrictedPropertiesStrict() { |
| 8 | function* generator() { "use strict"; } |
| 9 | assertFalse(generator.hasOwnProperty("arguments")); |
| 10 | assertThrows(function() { return generator.arguments; }, TypeError); |
| 11 | assertThrows(function() { return generator.arguments = {}; }, TypeError); |
| 12 | |
| 13 | assertFalse(generator.hasOwnProperty("caller")); |
| 14 | assertThrows(function() { return generator.caller; }, TypeError); |
| 15 | assertThrows(function() { return generator.caller = {}; }, TypeError); |
| 16 | })(); |
| 17 | |
| 18 | |
| 19 | (function testRestrictedPropertiesSloppy() { |
| 20 | function* generator() {} |
| 21 | assertFalse(generator.hasOwnProperty("arguments")); |
| 22 | assertThrows(function() { return generator.arguments; }, TypeError); |
| 23 | assertThrows(function() { return generator.arguments = {}; }, TypeError); |
| 24 | |
| 25 | assertFalse(generator.hasOwnProperty("caller")); |
| 26 | assertThrows(function() { return generator.caller; }, TypeError); |
| 27 | assertThrows(function() { return generator.caller = {}; }, TypeError); |
| 28 | })(); |
| 29 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 30 | function assertIteratorResult(value, done, result) { |
| 31 | assertEquals({value: value, done: done}, result); |
| 32 | } |
| 33 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 34 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | (function testIteratorResultStrict() { |
| 36 | function* generator() { "use strict"; } |
| 37 | assertIteratorResult(undefined, true, generator().next()); |
| 38 | })(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 39 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 40 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | (function testIteratorResultSloppy() { |
| 42 | function* generator() {} |
| 43 | assertIteratorResult(undefined, true, generator().next()); |
| 44 | })(); |