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