tor-browser

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

mapfn-sync-iterable-async.js (975B)


      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: >
      8  A synchronous mapping function is applied to each item yielded by an
      9  asynchronous iterable.
     10 info: |
     11  3.j.ii.6. If _mapping_ is *true*, then
     12    a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »).
     13    ...
     14  ...
     15  8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_).
     16 flags: [async]
     17 includes: [asyncHelpers.js, compareArray.js]
     18 features: [Array.fromAsync]
     19 ---*/
     20 
     21 async function* asyncGen() {
     22  for (let i = 0; i < 4; i++) {
     23    yield Promise.resolve(i * 2);
     24  }
     25 }
     26 
     27 function syncMap(val, ix) {
     28  return val * ix;
     29 }
     30 
     31 asyncTest(async () => {
     32  const result = await Array.fromAsync({ [Symbol.asyncIterator]: asyncGen }, syncMap);
     33  assert.compareArray(result, [0, 2, 8, 18], "sync mapfn should be applied to async iterable");
     34 });