summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/fromAsync/asyncitems-array-mutate.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/fromAsync/asyncitems-array-mutate.js')
-rw-r--r--js/src/tests/test262/built-ins/Array/fromAsync/asyncitems-array-mutate.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/fromAsync/asyncitems-array-mutate.js b/js/src/tests/test262/built-ins/Array/fromAsync/asyncitems-array-mutate.js
new file mode 100644
index 0000000000..2d910d2524
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/fromAsync/asyncitems-array-mutate.js
@@ -0,0 +1,45 @@
+// |reftest| async
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-array.fromasync
+description: >
+ Array.fromAsync respects array mutation
+info: |
+ Array.fromAsync
+ 3.j.ii.3. Let next be ? Await(IteratorStep(iteratorRecord)).
+
+ IteratorStep
+ 1. Let result be ? IteratorNext(iteratorRecord).
+
+ IteratorNext
+ 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]).
+
+ %AsyncFromSyncIteratorPrototype%.next
+ 6.a. Let result be Completion(IteratorNext(syncIteratorRecord)).
+
+ IteratorNext
+ 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]).
+
+ Array.prototype [ @@iterator ] ( )
+ Array.prototype.values ( )
+ 2. Return CreateArrayIterator(O, value).
+
+ CreateArrayIterator
+ 1.b.iii. If index ≥ len, return NormalCompletion(undefined).
+includes: [asyncHelpers.js, compareArray.js]
+flags: [async]
+features: [Array.fromAsync]
+---*/
+
+asyncTest(async function () {
+ const items = [1, 2, 3];
+ const promise = Array.fromAsync(items);
+ // At this point, the first element of `items` has been read, but the iterator will take other
+ // changes into account.
+ items[0] = 7;
+ items[1] = 8;
+ const result = await promise;
+ assert.compareArray(result, [1, 8, 3]);
+});