asyncitems-asynciterator-exists.js (1102B)
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 tries the various properties in order 9 includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] 10 flags: [async] 11 features: [Array.fromAsync] 12 ---*/ 13 14 asyncTest(async function () { 15 async function * asyncGen() { 16 for (let i = 0; i < 4; i++) { 17 yield Promise.resolve(i * 2); 18 } 19 } 20 21 const actual = []; 22 const items = {}; 23 TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, asyncGen, "items"); 24 TemporalHelpers.observeProperty(actual, items, Symbol.iterator, undefined, "items"); 25 TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); 26 TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); 27 TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); 28 const result = await Array.fromAsync(items); 29 assert.compareArray(result, [0, 2, 4, 6]); 30 assert.compareArray(actual, [ 31 "get items[Symbol.asyncIterator]", 32 ]); 33 });