tor-browser

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

capability-resolve-throws-reject.js (1998B)


      1 // |reftest| async
      2 // Copyright (C) 2016 the V8 project authors. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 esid: sec-promise.all
      6 description: >
      7  Promise is rejected when the "resolve" capability returns an abrupt
      8  completion.
      9 info: |
     10  1. Let C be the this value.
     11  [...]
     12  3. Let promiseCapability be ? NewPromiseCapability(C).
     13  [...]
     14  7. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
     15  8. If result is an abrupt completion, then
     16     a. If iteratorRecord.[[Done]] is false, let result be
     17        IteratorClose(iterator, result).
     18     b. IfAbruptRejectPromise(result, promiseCapability).
     19 
     20  25.4.4.1.1 Runtime Semantics: PerformPromiseAll
     21 
     22  [...]
     23  6. Repeat
     24     [...]
     25     d. If next is false, then
     26        [...]
     27        iii. If remainingElementsCount.[[Value]] is 0, then
     28             1. Let valuesArray be CreateArrayFromList(values).
     29             2. Perform ? Call(resultCapability.[[Resolve]], undefined, «
     30                valuesArray »).
     31 
     32  25.4.1.1.1 IfAbruptRejectPromise
     33 
     34  IfAbruptRejectPromise is a short hand for a sequence of algorithm steps that
     35  use a PromiseCapability Record. An algorithm step of the form:
     36 
     37  1. IfAbruptRejectPromise(value, capability).
     38 
     39  means the same thing as:
     40 
     41  1. If value is an abrupt completion, then
     42     a. Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »).
     43     b. Return capability.[[Promise]].
     44  2. Else if value is a Completion Record, let value be value.[[Value]].
     45 flags: [async]
     46 ---*/
     47 
     48 var thrown = new Test262Error();
     49 var P = function(executor) {
     50  return new Promise(function(_, reject) {
     51    executor(function() {
     52      throw thrown;
     53    }, reject);
     54  });
     55 };
     56 
     57 P.resolve = Promise.resolve;
     58 
     59 Promise.all.call(P, [])
     60  .then(function() {
     61    $DONE('Promise incorrectly fulfilled.');
     62  }, function(reason) {
     63    if (reason !== thrown) {
     64      $DONE('Promise rejected with incorrect "reason."');
     65      return;
     66    }
     67    $DONE();
     68  });