tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

non-iterable-input-with-thenable-async-mapped-awaits-callback-result-once.js (887B)


      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: Non-iterable input with thenable result with async mapped awaits each callback result once.
      8 includes: [asyncHelpers.js]
      9 flags: [async]
     10 features: [Array.fromAsync]
     11 ---*/
     12 
     13 asyncTest(async function () {
     14  let awaitCounter = 0;
     15  const input = {
     16    length: 3,
     17    0: 0,
     18    1: Promise.resolve(1),
     19    2: Promise.resolve(2),
     20    3: Promise.resolve(3), // This is ignored because the length is 3.
     21  };
     22  await Array.fromAsync(input, async v => {
     23    return {
     24      // This “then” method should occur three times:
     25      // one for each value from the input.
     26      then (resolve, reject) {
     27        awaitCounter ++;
     28        resolve(v);
     29      },
     30    };
     31  });
     32  assert.sameValue(awaitCounter, 3);
     33 });