tor-browser

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

reject-via-fn-immed-queue.js (1757B)


      1 // |reftest| async
      2 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 description: >
      7  Rejecting through immediate invocation of the provided resolving function,
      8  captured in a queued job.
      9 esid: sec-promise-executor
     10 info: |
     11  25.4.3.1 Promise ( executor )
     12 
     13  ...
     14  9. Let completion be Call(executor, undefined, « resolvingFunctions.[[Resolve]],
     15    resolvingFunctions.[[Reject]] »).
     16  10. If completion is an abrupt completion, then
     17    a. Perform ? Call(resolvingFunctions.[[Reject]], undefined, « completion.[[Value]] »).
     18  11. Return promise.
     19 
     20  25.4.1.3.1 Promise Reject Functions
     21 
     22  ...
     23  6. Return RejectPromise(promise, reason).
     24 
     25  25.4.5.3.1 PerformPromiseThen ( promise, onFulfilled, onRejected, resultCapability )
     26 
     27  ...
     28  4. If IsCallable(onRejected) is false, then
     29    a. Set onRejected to undefined.
     30  ...
     31  6. Let rejectReaction be the PromiseReaction { [[Capability]]: resultCapability,
     32    [[Type]]: "Reject", [[Handler]]: onRejected }.
     33  ...
     34  9. Else,
     35    a. Assert: The value of promise.[[PromiseState]] is "rejected".
     36    ...
     37    d. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, « rejectReaction, reason »).
     38 flags: [async]
     39 ---*/
     40 
     41 var thenable = Promise.resolve();
     42 var returnValue = null;
     43 var p = new Promise(function(_, reject) {
     44  returnValue = reject(thenable);
     45 });
     46 
     47 assert.sameValue(returnValue, undefined, '"reject" function return value');
     48 
     49 p.then(function() {
     50  $DONE('The promise should not be fulfilled.');
     51 }).then(function() {
     52  $DONE('The promise should not be fulfilled.');
     53 }, function(x) {
     54  if (x !== thenable) {
     55    $DONE('The promise should be rejected with the resolution value.');
     56    return;
     57  }
     58 
     59  $DONE();
     60 });