reject-via-fn-deferred-queue.js (1780B)
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 deferred 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 7. If promise.[[PromiseState]] is "pending", then 34 ... 35 b. Append rejectReaction as the last element of the List that is 36 promise.[[PromiseRejectReactions]]. 37 ... 38 flags: [async] 39 ---*/ 40 41 var thenable = Promise.resolve(); 42 var returnValue = null; 43 var reject; 44 var p = new Promise(function(_, _reject) { 45 reject = _reject; 46 }); 47 48 p.then(function() { 49 $DONE('The promise should not be fulfilled.'); 50 }).then(function() { 51 $DONE('The promise should not be fulfilled.'); 52 }, function(x) { 53 if (x !== thenable) { 54 $DONE('The promise should be rejected with the resolution value.'); 55 return; 56 } 57 58 $DONE(); 59 }); 60 61 returnValue = reject(thenable); 62 63 assert.sameValue(returnValue, undefined, '"reject" function return value');