asyncitems-array-remove.js (1330B)
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 = [1, 2, 3]; 38 const promise = Array.fromAsync(items); 39 // At this point, the first element of `items` has been read, but the iterator will take other 40 // changes into account. 41 items.pop(); 42 const result = await promise; 43 assert.compareArray(result, [1, 2]); 44 });