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 | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | (function testRestrictedPropertiesStrict() { |
| 6 | function* generator() { "use strict"; } |
| 7 | assertFalse(generator.hasOwnProperty("arguments")); |
| 8 | assertThrows(function() { return generator.arguments; }, TypeError); |
| 9 | assertThrows(function() { return generator.arguments = {}; }, TypeError); |
| 10 | |
| 11 | assertFalse(generator.hasOwnProperty("caller")); |
| 12 | assertThrows(function() { return generator.caller; }, TypeError); |
| 13 | assertThrows(function() { return generator.caller = {}; }, TypeError); |
| 14 | })(); |
| 15 | |
| 16 | |
| 17 | (function testRestrictedPropertiesSloppy() { |
| 18 | function* generator() {} |
| 19 | assertFalse(generator.hasOwnProperty("arguments")); |
| 20 | assertThrows(function() { return generator.arguments; }, TypeError); |
| 21 | assertThrows(function() { return generator.arguments = {}; }, TypeError); |
| 22 | |
| 23 | assertFalse(generator.hasOwnProperty("caller")); |
| 24 | assertThrows(function() { return generator.caller; }, TypeError); |
| 25 | assertThrows(function() { return generator.caller = {}; }, TypeError); |
| 26 | })(); |
| 27 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | function assertIteratorResult(value, done, result) { |
| 29 | assertEquals({value: value, done: done}, result); |
| 30 | } |
| 31 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 32 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 33 | (function testIteratorResultStrict() { |
| 34 | function* generator() { "use strict"; } |
| 35 | assertIteratorResult(undefined, true, generator().next()); |
| 36 | })(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 39 | (function testIteratorResultSloppy() { |
| 40 | function* generator() {} |
| 41 | assertIteratorResult(undefined, true, generator().next()); |
| 42 | })(); |