blob: 741a8b0ed5728da2150774fc856fd4e7cd8d1cf2 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
3// found in the LICENSE file.
4
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005// Test that traps that involve walking the target object's prototype chain
6// don't overflow the stack when the original proxy is on that chain.
7
8(function TestGetPrototype() {
9 var p = new Proxy({}, {});
10 p.__proto__ = p;
11 try { return p.__proto__; } catch(e) { assertInstanceof(e, RangeError); }
12})();
13
14(function TestSetPrototype() {
15 var p = new Proxy({}, {});
16 p.__proto__ = p;
17 try { p.__proto__ = p; } catch(e) { assertInstanceof(e, RangeError); }
18})();
19
20(function TestHasProperty() {
21 var p = new Proxy({}, {});
22 p.__proto__ = p;
23 try {
24 return Reflect.has(p, "foo");
25 } catch(e) { assertInstanceof(e, RangeError); }
26})();
27
28(function TestSet() {
29 var p = new Proxy({}, {});
30 p.__proto__ = p;
31 try { p.foo = 1; } catch(e) { assertInstanceof(e, RangeError); }
32})();
33
34(function TestGet() {
35 var p = new Proxy({}, {});
36 p.__proto__ = p;
37 try { return p.foo; } catch(e) { assertInstanceof(e, RangeError); }
38})();
39
40(function TestEnumerate() {
41 var p = new Proxy({}, {});
42 p.__proto__ = p;
43 try { for (var x in p) {} } catch(e) { assertInstanceof(e, RangeError); }
44})();
45
46// The following traps don't involve the target object's prototype chain;
47// we test them anyway for completeness.
48
49(function TestIsExtensible() {
50 var p = new Proxy({}, {});
51 p.__proto__ = p;
52 return Reflect.isExtensible(p);
53})();
54
55(function TestPreventExtensions() {
56 var p = new Proxy({}, {});
57 p.__proto__ = p;
58 Reflect.preventExtensions(p);
59})();
60
61(function TestGetOwnPropertyDescriptor() {
62 var p = new Proxy({}, {});
63 p.__proto__ = p;
64 return Object.getOwnPropertyDescriptor(p, "foo");
65})();
66
67(function TestDeleteProperty() {
68 var p = new Proxy({}, {});
69 p.__proto__ = p;
70 delete p.foo;
71})();
72
73(function TestDefineProperty() {
74 var p = new Proxy({}, {});
75 p.__proto__ = p;
76 Object.defineProperty(p, "foo", {value: "bar"});
77})();
78
79(function TestOwnKeys() {
80 var p = new Proxy({}, {});
81 p.__proto__ = p;
82 return Reflect.ownKeys(p);
83})();
84
85(function TestCall() {
86 var p = new Proxy(function() {}, {});
87 p.__proto__ = p;
88 return p();
89})();
90
91(function TestConstruct() {
92 var p = new Proxy(function() { this.foo = 1; }, {});
93 p.__proto__ = p;
94 return new p();
95})();