OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Make sure that eval can introduce a local variable called __proto__. | 28 // Make sure that eval can introduce a local variable called __proto__. |
29 // See http://code.google.com/p/v8/issues/detail?id=186 | 29 // See http://code.google.com/p/v8/issues/detail?id=186 |
30 | 30 |
31 var setterCalled = false; | 31 var setterCalled = false; |
32 | 32 |
33 var o = {}; | 33 var o = {}; |
34 o.__defineSetter__("x", function() { setterCalled = true; }); | 34 o.__defineSetter__("x", function() { setterCalled = true; }); |
35 | 35 |
| 36 function runTest(test) { |
| 37 setterCalled = false; |
| 38 test(); |
| 39 } |
| 40 |
36 function testLocal() { | 41 function testLocal() { |
37 // Add property called __proto__ to the extension object. | 42 // Add property called __proto__ to the extension object. |
38 eval("var __proto__ = o"); | 43 eval("var __proto__ = o"); |
39 // Check that the extension object's prototype did not change. | 44 // Check that the extension object's prototype did not change. |
40 eval("var x = 27"); | 45 eval("var x = 27"); |
41 assertFalse(setterCalled, "prototype of extension object changed"); | 46 assertFalse(setterCalled, "prototype of extension object changed"); |
| 47 assertEquals(o, eval("__proto__")); |
| 48 } |
| 49 |
| 50 function testConstLocal() { |
| 51 // Add const property called __proto__ to the extension object. |
| 52 eval("const __proto__ = o"); |
| 53 // Check that the extension object's prototype did not change. |
| 54 eval("var x = 27"); |
| 55 assertFalse(setterCalled, "prototype of extension object changed"); |
| 56 assertEquals(o, eval("__proto__")); |
42 } | 57 } |
43 | 58 |
44 function testGlobal() { | 59 function testGlobal() { |
45 // Assign to the global __proto__ property. | 60 // Assign to the global __proto__ property. |
46 eval("__proto__ = o"); | 61 eval("__proto__ = o"); |
47 // Check that the prototype of the global object changed. | 62 // Check that the prototype of the global object changed. |
48 eval("x = 27"); | 63 eval("x = 27"); |
49 assertTrue(setterCalled, "prototype of global object did not change"); | 64 assertTrue(setterCalled, "prototype of global object did not change"); |
50 setterCalled = false; | 65 setterCalled = false; |
| 66 assertEquals(o, eval("__proto__")); |
51 } | 67 } |
52 | 68 |
53 testLocal(); | 69 runTest(testLocal); |
54 testGlobal(); | 70 runTest(testConstLocal); |
| 71 runTest(testGlobal); |
55 | 72 |
OLD | NEW |