| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 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 |
| 5 function assertIteratorResult(value, done, result) { | 28 function assertIteratorResult(value, done, result) { |
| 6 assertEquals({value: value, done: done}, result); | 29 assertEquals({value: value, done: done}, result); |
| 7 } | 30 } |
| 8 | 31 |
| 9 function test(f) { | |
| 10 var cdesc = Object.getOwnPropertyDescriptor(f, "caller"); | |
| 11 var adesc = Object.getOwnPropertyDescriptor(f, "arguments"); | |
| 12 | 32 |
| 13 assertFalse(cdesc.enumerable); | 33 (function testIteratorResultStrict() { |
| 14 assertFalse(cdesc.configurable); | 34 function* generator() { "use strict"; } |
| 35 assertIteratorResult(undefined, true, generator().next()); |
| 36 })(); |
| 15 | 37 |
| 16 assertFalse(adesc.enumerable); | |
| 17 assertFalse(adesc.configurable); | |
| 18 | 38 |
| 19 assertSame(cdesc.get, cdesc.set); | 39 (function testIteratorResultSloppy() { |
| 20 assertSame(cdesc.get, adesc.get); | 40 function* generator() {} |
| 21 assertSame(cdesc.get, adesc.set); | 41 assertIteratorResult(undefined, true, generator().next()); |
| 22 | 42 })(); |
| 23 assertTrue(cdesc.get instanceof Function); | |
| 24 assertEquals(0, cdesc.get.length); | |
| 25 assertThrows(cdesc.get, TypeError); | |
| 26 | |
| 27 assertThrows(function() { return f.caller; }, TypeError); | |
| 28 assertThrows(function() { f.caller = 42; }, TypeError); | |
| 29 assertThrows(function() { return f.arguments; }, TypeError); | |
| 30 assertThrows(function() { f.arguments = 42; }, TypeError); | |
| 31 } | |
| 32 | |
| 33 function *sloppy() { test(sloppy); } | |
| 34 function *strict() { "use strict"; test(strict); } | |
| 35 | |
| 36 test(sloppy); | |
| 37 test(strict); | |
| 38 | |
| 39 assertIteratorResult(undefined, true, sloppy().next()); | |
| 40 assertIteratorResult(undefined, true, strict().next()); | |
| OLD | NEW |