summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js')
-rw-r--r--js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-operations.js74
1 files changed, 74 insertions, 0 deletions
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");
+});