OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 // Flags: --harmony-proxies --harmony-reflect | 5 // Flags: --harmony-proxies --harmony-reflect |
6 | 6 |
7 // Test that traps that involve walking the target object's prototype chain | 7 // Test that traps that involve walking the target object's prototype chain |
8 // don't overflow the stack when the original proxy is on that chain. | 8 // don't overflow the stack when the original proxy is on that chain. |
9 function test(fn) { | |
10 return () => { | |
11 print(fn.name); | |
12 fn(); | |
13 print(" done"); | |
14 } | |
neis
2016/03/01 13:40:31
Not sure if this was temporary debugging code or n
Camillo Bruni
2016/03/01 19:04:57
is debugging code :)
| |
15 } | |
9 | 16 |
10 (function TestGetPrototype() { | 17 test(function TestGetPrototype() { |
11 var p = new Proxy({}, {}); | 18 var p = new Proxy({}, {}); |
12 p.__proto__ = p; | 19 p.__proto__ = p; |
13 try { return p.__proto__; } catch(e) { assertInstanceof(e, RangeError); } | 20 try { return p.__proto__; } catch(e) { assertInstanceof(e, RangeError); } |
14 })(); | 21 })(); |
15 | 22 |
16 (function TestSetPrototype() { | 23 test(function TestSetPrototype() { |
17 var p = new Proxy({}, {}); | 24 var p = new Proxy({}, {}); |
18 p.__proto__ = p; | 25 p.__proto__ = p; |
19 try { p.__proto__ = p; } catch(e) { assertInstanceof(e, RangeError); } | 26 try { p.__proto__ = p; } catch(e) { assertInstanceof(e, RangeError); } |
20 })(); | 27 })(); |
21 | 28 |
22 (function TestHasProperty() { | 29 test(function TestHasProperty() { |
23 var p = new Proxy({}, {}); | 30 var p = new Proxy({}, {}); |
24 p.__proto__ = p; | 31 p.__proto__ = p; |
25 try { | 32 try { |
26 return Reflect.has(p, "foo"); | 33 return Reflect.has(p, "foo"); |
27 } catch(e) { assertInstanceof(e, RangeError); } | 34 } catch(e) { assertInstanceof(e, RangeError); } |
28 })(); | 35 })(); |
29 | 36 |
30 (function TestSet() { | 37 test(function TestSet() { |
31 var p = new Proxy({}, {}); | 38 var p = new Proxy({}, {}); |
32 p.__proto__ = p; | 39 p.__proto__ = p; |
33 try { p.foo = 1; } catch(e) { assertInstanceof(e, RangeError); } | 40 try { p.foo = 1; } catch(e) { assertInstanceof(e, RangeError); } |
34 })(); | 41 })(); |
35 | 42 |
36 (function TestGet() { | 43 test(function TestGet() { |
37 var p = new Proxy({}, {}); | 44 var p = new Proxy({}, {}); |
38 p.__proto__ = p; | 45 p.__proto__ = p; |
39 try { return p.foo; } catch(e) { assertInstanceof(e, RangeError); } | 46 try { return p.foo; } catch(e) { assertInstanceof(e, RangeError); } |
40 })(); | 47 })(); |
41 | 48 |
42 (function TestEnumerate() { | 49 test(function TestEnumerate() { |
43 var p = new Proxy({}, {}); | 50 var p = new Proxy({}, {}); |
44 p.__proto__ = p; | 51 p.__proto__ = p; |
45 try { for (var x in p) {} } catch(e) { assertInstanceof(e, RangeError); } | 52 try { for (var x in p) {} } catch(e) { assertInstanceof(e, RangeError); } |
46 })(); | 53 })(); |
47 | 54 |
48 // The following traps don't involve the target object's prototype chain; | 55 // The following traps don't involve the target object's prototype chain; |
49 // we test them anyway for completeness. | 56 // we test them anyway for completeness. |
50 | 57 |
51 (function TestIsExtensible() { | 58 test(function TestIsExtensible() { |
52 var p = new Proxy({}, {}); | 59 var p = new Proxy({}, {}); |
53 p.__proto__ = p; | 60 p.__proto__ = p; |
54 return Reflect.isExtensible(p); | 61 return Reflect.isExtensible(p); |
55 })(); | 62 })(); |
56 | 63 |
57 (function TestPreventExtensions() { | 64 test(function TestPreventExtensions() { |
58 var p = new Proxy({}, {}); | 65 var p = new Proxy({}, {}); |
59 p.__proto__ = p; | 66 p.__proto__ = p; |
60 Reflect.preventExtensions(p); | 67 Reflect.preventExtensions(p); |
61 })(); | 68 })(); |
62 | 69 |
63 (function TestGetOwnPropertyDescriptor() { | 70 test(function TestGetOwnPropertyDescriptor() { |
64 var p = new Proxy({}, {}); | 71 var p = new Proxy({}, {}); |
65 p.__proto__ = p; | 72 p.__proto__ = p; |
66 return Object.getOwnPropertyDescriptor(p, "foo"); | 73 return Object.getOwnPropertyDescriptor(p, "foo"); |
67 })(); | 74 })(); |
68 | 75 |
69 (function TestDeleteProperty() { | 76 test(function TestDeleteProperty() { |
70 var p = new Proxy({}, {}); | 77 var p = new Proxy({}, {}); |
71 p.__proto__ = p; | 78 p.__proto__ = p; |
72 delete p.foo; | 79 delete p.foo; |
73 })(); | 80 })(); |
74 | 81 |
75 (function TestDefineProperty() { | 82 test(function TestDefineProperty() { |
76 var p = new Proxy({}, {}); | 83 var p = new Proxy({}, {}); |
77 p.__proto__ = p; | 84 p.__proto__ = p; |
78 Object.defineProperty(p, "foo", {value: "bar"}); | 85 Object.defineProperty(p, "foo", {value: "bar"}); |
79 })(); | 86 })(); |
80 | 87 |
81 (function TestOwnKeys() { | 88 test(function TestOwnKeys() { |
82 var p = new Proxy({}, {}); | 89 var p = new Proxy({}, {}); |
83 p.__proto__ = p; | 90 p.__proto__ = p; |
84 return Reflect.ownKeys(p); | 91 return Reflect.ownKeys(p); |
85 })(); | 92 })(); |
86 | 93 |
87 (function TestCall() { | 94 test(function TestCall() { |
88 var p = new Proxy(function() {}, {}); | 95 var p = new Proxy(function() {}, {}); |
89 p.__proto__ = p; | 96 p.__proto__ = p; |
90 return p(); | 97 return p(); |
91 })(); | 98 })(); |
92 | 99 |
93 (function TestConstruct() { | 100 test(function TestConstruct() { |
94 var p = new Proxy(function() { this.foo = 1; }, {}); | 101 var p = new Proxy(function() { this.foo = 1; }, {}); |
95 p.__proto__ = p; | 102 p.__proto__ = p; |
96 return new p(); | 103 return new p(); |
97 })(); | 104 })(); |
OLD | NEW |