tor-browser

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

iter-next-val-err-no-close.js (1569B)


      1 // |reftest| async
      2 // Copyright (C) 2020 Rick Waldron. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-promise.any
      7 description: >
      8  Error when accessing an iterator result's `value` property (not closing
      9  iterator)
     10 info: |
     11  Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
     12  If result is an abrupt completion, then
     13    If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
     14    IfAbruptRejectPromise(result, promiseCapability).
     15 
     16  ...
     17 
     18  Runtime Semantics: PerformPromiseAny
     19 
     20  ...
     21  Repeat
     22    Let nextValue be IteratorValue(next).
     23    If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
     24    ReturnIfAbrupt(nextValue).
     25 
     26 features: [Promise.any, Symbol.iterator]
     27 flags: [async]
     28 ---*/
     29 let callCount = 0;
     30 let returnCount = 0;
     31 let error = new Test262Error();
     32 let poisoned = {
     33  done: false
     34 };
     35 Object.defineProperty(poisoned, 'value', {
     36  get() {
     37    callCount++;
     38    throw error;
     39  }
     40 });
     41 let iterNextValThrows = {
     42  [Symbol.iterator]() {
     43    callCount++;
     44    return {
     45      next() {
     46        callCount++;
     47        return poisoned;
     48      },
     49      return() {
     50        returnCount++;
     51        return {};
     52      }
     53    };
     54  }
     55 };
     56 
     57 Promise.any(iterNextValThrows).then(() => {
     58  $DONE('The promise should be rejected, but was resolved');
     59 }, (reason) => {
     60  assert(error instanceof Test262Error);
     61  assert.sameValue(reason, error);
     62  assert.sameValue(callCount, 3, 'callCount === 3');
     63  assert.sameValue(returnCount, 0);
     64 }).then($DONE, $DONE);