asyncitems-array-add-to-empty.js (1435B)
1 // |reftest| async 2 // Copyright (C) 2022 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-array.fromasync 7 description: > 8 Array.fromAsync respects array mutation 9 info: | 10 Array.fromAsync 11 3.j.ii.3. Let next be ? Await(IteratorStep(iteratorRecord)). 12 13 IteratorStep 14 1. Let result be ? IteratorNext(iteratorRecord). 15 16 IteratorNext 17 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). 18 19 %AsyncFromSyncIteratorPrototype%.next 20 6.a. Let result be Completion(IteratorNext(syncIteratorRecord)). 21 22 IteratorNext 23 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). 24 25 Array.prototype [ @@iterator ] ( ) 26 Array.prototype.values ( ) 27 2. Return CreateArrayIterator(O, value). 28 29 CreateArrayIterator 30 1.b.iii. If index ≥ len, return NormalCompletion(undefined). 31 includes: [asyncHelpers.js, compareArray.js] 32 flags: [async] 33 features: [Array.fromAsync] 34 ---*/ 35 36 asyncTest(async function () { 37 const items = []; 38 const promise = Array.fromAsync(items); 39 // By the time we get here, the first next() call has already happened, and returned 40 // { done: true }. We then return from the loop in Array.fromAsync 3.j.ii. with the empty array, 41 // and the following line no longer affects that. 42 items.push(7); 43 const result = await promise; 44 assert.compareArray(result, []); 45 });