tor-browser

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

this-constructor-with-unsettable-element-closes-async-iterator.js (1236B)


      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  Closes an async iterator if setting an element fails on an instance of a
      9  custom this-value
     10 info: |
     11  3.j.ii.8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_).
     12  9. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _defineStatus_).
     13 includes: [asyncHelpers.js]
     14 flags: [async]
     15 features: [Array.fromAsync]
     16 ---*/
     17 
     18 asyncTest(async function () {
     19  function MyArray() {
     20    Object.defineProperty(this, 0, {
     21      enumerable: true,
     22      writable: true,
     23      configurable: false,
     24      value: 0
     25    });
     26  }
     27 
     28  let closed = false;
     29  const iterator = {
     30    next() {
     31      return Promise.resolve({ value: 1, done: false });
     32    },
     33    return() {
     34      closed = true;
     35      return Promise.resolve({ done: true });
     36    },
     37    [Symbol.asyncIterator]() {
     38      return this;
     39    }
     40  }
     41 
     42  await assert.throwsAsync(TypeError, () => Array.fromAsync.call(MyArray, iterator), "Promise rejected if defining element fails");
     43  assert(closed, "element define failure should close iterator");
     44 });