From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/Array/shift-no-has-trap.js | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 js/src/tests/non262/Array/shift-no-has-trap.js (limited to 'js/src/tests/non262/Array/shift-no-has-trap.js') diff --git a/js/src/tests/non262/Array/shift-no-has-trap.js b/js/src/tests/non262/Array/shift-no-has-trap.js new file mode 100644 index 0000000000..e941ba7205 --- /dev/null +++ b/js/src/tests/non262/Array/shift-no-has-trap.js @@ -0,0 +1,64 @@ +// Test that Array.prototype.shift doesn't call the [[HasProperty]] internal +// method of objects when retrieving the element at index 0. + +var log = []; +var array = []; +var proxy = new Proxy(array, new Proxy({}, { + get(t, trap, r) { + return (t, pk, ...more) => { + log.push(`${trap}:${String(pk)}`); + return Reflect[trap](t, pk, ...more); + }; + } +})); + +var result; + +result = Array.prototype.shift.call(proxy); +assertEqArray(log, [ + "get:length", + "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length" +]); +assertEq(result, undefined); + +log.length = 0; +array.push(1); + +result = Array.prototype.shift.call(proxy); +assertEqArray(log, [ + "get:length", + "get:0", + "deleteProperty:0", + "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length" +]); +assertEq(result, 1); + +log.length = 0; +array.push(2, 3); + +result = Array.prototype.shift.call(proxy); +assertEqArray(log, [ + "get:length", + "get:0", + "has:1", "get:1", "set:0", "getOwnPropertyDescriptor:0", "defineProperty:0", + "deleteProperty:1", + "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length" +]); +assertEq(result, 2); + +log.length = 0; +array.push(4, 5); + +result = Array.prototype.shift.call(proxy); +assertEqArray(log, [ + "get:length", + "get:0", + "has:1", "get:1", "set:0", "getOwnPropertyDescriptor:0", "defineProperty:0", + "has:2", "get:2", "set:1", "getOwnPropertyDescriptor:1", "defineProperty:1", + "deleteProperty:2", + "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length" +]); +assertEq(result, 3); + +if (typeof reportCompare === "function") + reportCompare(true, true); -- cgit v1.2.3