tor-browser

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

asyncitems-uses-intrinsic-iterator-symbols.js (1204B)


      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  Use the intrinsic @@iterator and @@asyncIterator to check iterability
      9 includes: [compareArray.js, asyncHelpers.js]
     10 flags: [async]
     11 features: [Array.fromAsync]
     12 ---*/
     13 
     14 asyncTest(async function () {
     15  // Replace the user-reachable Symbol.iterator and Symbol.asyncIterator with
     16  // fake symbol keys
     17  const originalSymbol = globalThis.Symbol;
     18  const fakeIteratorSymbol = Symbol("iterator");
     19  const fakeAsyncIteratorSymbol = Symbol("asyncIterator");
     20  globalThis.Symbol = {
     21    iterator: fakeIteratorSymbol,
     22    asyncIterator: fakeAsyncIteratorSymbol,
     23  };
     24 
     25  const input = {
     26    length: 3,
     27    0: 0,
     28    1: 1,
     29    2: 2,
     30    [fakeIteratorSymbol]() {
     31      throw new Test262Error("The fake Symbol.iterator method should not be called");
     32    },
     33    [fakeAsyncIteratorSymbol]() {
     34      throw new Test262Error("The fake Symbol.asyncIterator method should not be called");
     35    }
     36  };
     37  const output = await Array.fromAsync(input);
     38  assert.compareArray(output, [0, 1, 2]);
     39 
     40  globalThis.Symbol = originalSymbol;
     41 });