Debian Codegraph @

js/src/jit-test/tests/proxy/testDirectProxyDefinePropertyFailure.js

raw
1 // Test handling of false return from a handler.defineProperty() hook.
2
3 load(libdir + "asserts.js");
4
5 var obj = {x: 1, y: 2};
6 var nope = false;
7 var p = new Proxy(obj, {
8 defineProperty(target, key, desc) { return nope; }
9 });
10
11 // Object.defineProperty throws on failure.
12 print(1);
13 assertThrowsInstanceOf(() => Object.defineProperty(p, "z", {value: 3}), TypeError);
14 assertEq("z" in obj, false);
15 assertThrowsInstanceOf(() => Object.defineProperty(p, "x", {value: 0}), TypeError);
16
17 // Setting a property ultimately causes [[DefineOwnProperty]] to be called.
18 // In strict mode code only, this is a TypeError.
19 print(2);
20 assertEq(p.z = 3, 3);
21 assertThrowsInstanceOf(() => { "use strict"; p.z = 3; }, TypeError);
22
23 // Other falsy values also trigger failure.
24 print(3);
25 for (nope of [0, -0, NaN, ""])
26 assertThrowsInstanceOf(() => { "use strict"; p.z = 3; }, TypeError);