tor-browser

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

invoke-then-get-error-close.js (1416B)


      1 // |reftest| async
      2 // Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 description: >
      6  Error thrown when accesing the instance's `then` method (closing iterator)
      7 esid: sec-promise.any
      8 info: |
      9  5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
     10  6. If result is an abrupt completion, then
     11    a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
     12    b. IfAbruptRejectPromise(result, promiseCapability).
     13 
     14  Runtime Semantics: PerformPromiseAny
     15 
     16  r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
     17 
     18 flags: [async]
     19 features: [Promise.any, Symbol.iterator, arrow-function, computed-property-names, Symbol]
     20 ---*/
     21 let error = new Test262Error();
     22 let promise = Promise.resolve();
     23 let returnCount = 0;
     24 let iter = {
     25  [Symbol.iterator]() {
     26    return {
     27      next() {
     28        return {
     29          done: false,
     30          value: promise
     31        };
     32      },
     33      return() {
     34        returnCount += 1;
     35        return {};
     36      }
     37    };
     38  }
     39 };
     40 
     41 Object.defineProperty(promise, 'then', {
     42  get() {
     43    throw error;
     44  }
     45 });
     46 
     47 Promise.any(iter).then(() => {
     48  $DONE('The promise should be rejected, but was resolved');
     49 }, (reason) => {
     50  assert.sameValue(returnCount, 1);
     51  assert.sameValue(reason, error);
     52 }).then($DONE, $DONE);