From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- js/src/tests/non262/Proxy/trap-null.js | 103 +++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 js/src/tests/non262/Proxy/trap-null.js (limited to 'js/src/tests/non262/Proxy/trap-null.js') diff --git a/js/src/tests/non262/Proxy/trap-null.js b/js/src/tests/non262/Proxy/trap-null.js new file mode 100644 index 0000000000..703649e7c8 --- /dev/null +++ b/js/src/tests/non262/Proxy/trap-null.js @@ -0,0 +1,103 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +var gTestfile = 'trap-null.js'; +var BUGNUMBER = 1257102; +var summary = "null as a trap value on a handler should operate on the target"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// This might seem like overkill, but this proxying trick caught typos of +// several trap names before this test landed. \o/ /o\ +var allTraps = { + getPrototypeOf: null, + setPrototypeOf: null, + isExtensible: null, + preventExtensions: null, + getOwnPropertyDescriptor: null, + defineProperty: null, + has: null, + get: null, + set: null, + deleteProperty: null, + ownKeys: null, + apply: null, + construct: null, +}; + +var complainingHandler = new Proxy(allTraps, { + get(target, p, receiver) { + var v = Reflect.get(target, p, receiver); + if (v !== null) + throw new TypeError("failed to set one of the traps to null? " + p); + + return v; + } +}); + +var proxyTarget = function(x) { + "use strict"; + var str = this + x; + str += new.target ? "constructing" : "calling"; + return new.target ? new String(str) : str; +}; +proxyTarget.prototype.toString = () => "###"; +proxyTarget.prototype.valueOf = () => "@@@"; + +var proxy = new Proxy(proxyTarget, complainingHandler); + +assertEq(Reflect.getPrototypeOf(proxy), Function.prototype); + +assertEq(Object.getPrototypeOf(proxyTarget), Function.prototype); +assertEq(Reflect.setPrototypeOf(proxy, null), true); +assertEq(Object.getPrototypeOf(proxyTarget), null); + +assertEq(Reflect.isExtensible(proxy), true); + +assertEq(Reflect.isExtensible(proxyTarget), true); +assertEq(Reflect.preventExtensions(proxy), true); +assertEq(Reflect.isExtensible(proxy), false); +assertEq(Reflect.isExtensible(proxyTarget), false); + +var desc = Reflect.getOwnPropertyDescriptor(proxy, "length"); +assertEq(desc.value, 1); + +assertEq(desc.configurable, true); +assertEq(Reflect.defineProperty(proxy, "length", { value: 3, configurable: false }), true); +desc = Reflect.getOwnPropertyDescriptor(proxy, "length"); +assertEq(desc.configurable, false); + +assertEq(Reflect.has(proxy, "length"), true); + +assertEq(Reflect.get(proxy, "length"), 3); + +assertEq(Reflect.set(proxy, "length", 3), false); + +assertEq(Reflect.deleteProperty(proxy, "length"), false); + +var keys = Reflect.ownKeys(proxy); +assertEq(keys.length, 3); +keys.sort(); +assertEq(keys[0], "length"); +assertEq(keys[1], "name"); +assertEq(keys[2], "prototype"); + +assertEq(Reflect.apply(proxy, "hi!", [" "]), "hi! calling"); + +var res = Reflect.construct(proxy, [" - "]); +assertEq(typeof res, "object"); +assertEq(res instanceof String, true); +assertEq(res.valueOf(), "@@@ - constructing"); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete"); -- cgit v1.2.3