Debian Codegraph @

js/src/tests/test262/built-ins/Array/fromAsync/async-iterable-input-does-not-await-input.js

raw
1 // |reftest| async
2 // Copyright (C) 2023 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: Async-iterable input does not await input values.
8 includes: [compareArray.js, asyncHelpers.js]
9 flags: [async]
10 features: [Array.fromAsync]
11 ---*/
12
13 asyncTest(async function () {
14 const prom = Promise.resolve({});
15 const expected = [ prom ];
16
17 function createInput () {
18 return {
19 // The following async iterator will yield one value
20 // (the promise named “prom”).
21 [Symbol.asyncIterator]() {
22 let i = 0;
23 return {
24 async next() {
25 if (i > 0) {
26 return { done: true };
27 }
28 i++;
29 return { value: prom, done: false }
30 },
31 };
32 },
33 };
34 }
35
36 const input = createInput();
37 const output = await Array.fromAsync(input);
38 assert.compareArray(output, expected);
39 });