Debian Codegraph @

js/src/tests/test262/built-ins/Array/fromAsync/asyncitems-iterator-promise.js

raw
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 handles an async iterator returned from @@iterator
9 includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js]
10 flags: [async]
11 features: [Array.fromAsync]
12 ---*/
13
14 asyncTest(async function () {
15 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, undefined, "items");
24 TemporalHelpers.observeProperty(actual, items, Symbol.iterator, asyncGen, "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 "get items[Symbol.iterator]",
33 ]);
34 });