summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Proxy/revoke-as-side-effect.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/Proxy/revoke-as-side-effect.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/Proxy/revoke-as-side-effect.js')
-rw-r--r--js/src/tests/ecma_6/Proxy/revoke-as-side-effect.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Proxy/revoke-as-side-effect.js b/js/src/tests/ecma_6/Proxy/revoke-as-side-effect.js
new file mode 100644
index 000000000..25d4c9bf9
--- /dev/null
+++ b/js/src/tests/ecma_6/Proxy/revoke-as-side-effect.js
@@ -0,0 +1,73 @@
+function createProxy(proxyTarget) {
+ var {proxy, revoke} = Proxy.revocable(proxyTarget, new Proxy({}, {
+ get(target, propertyKey, receiver) {
+ print("trap get:", propertyKey);
+ revoke();
+ }
+ }));
+ return proxy;
+}
+
+var obj;
+
+// [[GetPrototypeOf]]
+assertEq(Object.getPrototypeOf(createProxy({})), Object.prototype);
+assertEq(Object.getPrototypeOf(createProxy([])), Array.prototype);
+
+// [[SetPrototypeOf]]
+obj = {};
+Object.setPrototypeOf(createProxy(obj), Array.prototype);
+assertEq(Object.getPrototypeOf(obj), Array.prototype);
+
+// [[IsExtensible]]
+assertEq(Object.isExtensible(createProxy({})), true);
+assertEq(Object.isExtensible(createProxy(Object.preventExtensions({}))), false);
+
+// [[PreventExtensions]]
+obj = {};
+Object.preventExtensions(createProxy(obj));
+assertEq(Object.isExtensible(obj), false);
+
+// [[GetOwnProperty]]
+assertEq(Object.getOwnPropertyDescriptor(createProxy({}), "a"), undefined);
+assertEq(Object.getOwnPropertyDescriptor(createProxy({a: 5}), "a").value, 5);
+
+// [[DefineOwnProperty]]
+obj = {};
+Object.defineProperty(createProxy(obj), "a", {value: 5});
+assertEq(obj.a, 5);
+
+// [[HasProperty]]
+assertEq("a" in createProxy({}), false);
+assertEq("a" in createProxy({a: 5}), true);
+
+// [[Get]]
+assertEq(createProxy({}).a, undefined);
+assertEq(createProxy({a: 5}).a, 5);
+
+// [[Set]]
+assertThrowsInstanceOf(() => createProxy({}).a = 0, TypeError);
+assertThrowsInstanceOf(() => createProxy({a: 5}).a = 0, TypeError);
+
+// [[Delete]]
+assertEq(delete createProxy({}).a, true);
+assertEq(delete createProxy(Object.defineProperty({}, "a", {configurable: false})).a, false);
+
+// [[OwnPropertyKeys]]
+assertEq(Object.getOwnPropertyNames(createProxy({})).length, 0);
+assertEq(Object.getOwnPropertyNames(createProxy({a: 5})).length, 1);
+
+// [[Call]]
+assertEq(createProxy(function() { return "ok" })(), "ok");
+
+// [[Construct]]
+// This throws because after the "construct" trap on the proxy is consulted,
+// OrdinaryCreateFromConstructor (called because the |q| function's
+// [[ConstructorKind]] is "base" per FunctionAllocate) accesses
+// |new.target.prototype| to create the |this| for the construct operation, that
+// would be returned if |return obj;| didn't override it.
+assertThrowsInstanceOf(() => new (createProxy(function q(){ return obj; })),
+ TypeError);
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);