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 --- .../Array/fromAsync/this-constructor-operations.js | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js (limited to 'js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js') diff --git a/js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js b/js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js new file mode 100644 index 0000000000..ee96890677 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js @@ -0,0 +1,74 @@ +// |reftest| async +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.fromasync +description: > + Order of user-observable operations on a custom this-value and its instances +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [Array.fromAsync] +---*/ + +function formatPropertyName(propertyKey, objectName = "") { + switch (typeof propertyKey) { + case "symbol": + if (Symbol.keyFor(propertyKey) !== undefined) { + return `${objectName}[Symbol.for('${Symbol.keyFor(propertyKey)}')]`; + } else if (propertyKey.description.startsWith('Symbol.')) { + return `${objectName}[${propertyKey.description}]`; + } else { + return `${objectName}[Symbol('${propertyKey.description}')]` + } + case "string": + if (propertyKey !== String(Number(propertyKey))) + return objectName ? `${objectName}.${propertyKey}` : propertyKey; + // fall through + default: + // integer or string integer-index + return `${objectName}[${propertyKey}]`; + } +} + +asyncTest(async function () { + const expectedCalls = [ + "construct MyArray", + "defineProperty A[0]", + "defineProperty A[1]", + "set A.length" + ]; + const actualCalls = []; + + function MyArray(...args) { + actualCalls.push("construct MyArray"); + return new Proxy(Object.create(null), { + set(target, key, value) { + actualCalls.push(`set ${formatPropertyName(key, "A")}`); + return Reflect.set(target, key, value); + }, + defineProperty(target, key, descriptor) { + actualCalls.push(`defineProperty ${formatPropertyName(key, "A")}`); + return Reflect.defineProperty(target, key, descriptor); + } + }); + } + + let result = await Array.fromAsync.call(MyArray, [1, 2]); + assert.compareArray(expectedCalls, actualCalls, "order of operations for array argument"); + + actualCalls.splice(0); // reset + + const expectedCallsForArrayLike = [ + "construct MyArray", + "defineProperty A[0]", + "defineProperty A[1]", + "set A.length" + ]; + result = await Array.fromAsync.call(MyArray, { + length: 2, + 0: 1, + 1: 2 + }); + assert.compareArray(expectedCallsForArrayLike, actualCalls, "order of operations for array-like argument"); +}); -- cgit v1.2.3