From 7fab70bb21c4f1c676372e4a525e71d1df018e5d Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Wed, 30 Dec 2015 14:15:30 -0500 Subject: [PATCH] Add tests for Promise Reject Functions --- test/built-ins/Promise/all/reject-deferred.js | 39 ++++++++++++++ .../Promise/all/reject-ignored-deferred.js | 53 +++++++++++++++++++ .../Promise/all/reject-ignored-immed.js | 47 ++++++++++++++++ test/built-ins/Promise/all/reject-immed.js | 36 +++++++++++++ .../then/reject-pending-fulfilled.js | 43 +++++++++++++++ .../prototype/then/reject-pending-rejected.js | 44 +++++++++++++++ .../then/reject-settled-fulfilled.js | 48 +++++++++++++++++ .../prototype/then/reject-settled-rejected.js | 48 +++++++++++++++++ .../built-ins/Promise/race/reject-deferred.js | 38 +++++++++++++ .../Promise/race/reject-ignored-deferred.js | 51 ++++++++++++++++++ .../Promise/race/reject-ignored-immed.js | 45 ++++++++++++++++ test/built-ins/Promise/race/reject-immed.js | 35 ++++++++++++ .../Promise/reject-ignored-via-abrupt.js | 33 ++++++++++++ .../Promise/reject-ignored-via-fn-deferred.js | 37 +++++++++++++ .../Promise/reject-ignored-via-fn-immed.js | 33 ++++++++++++ test/built-ins/Promise/reject-via-abrupt.js | 35 ++++++++++++ .../Promise/reject-via-fn-deferred.js | 36 +++++++++++++ test/built-ins/Promise/reject-via-fn-immed.js | 33 ++++++++++++ .../Promise/reject/S25.4.4.4_A2.1_T1.js | 10 +++- 19 files changed, 742 insertions(+), 2 deletions(-) create mode 100644 test/built-ins/Promise/all/reject-deferred.js create mode 100644 test/built-ins/Promise/all/reject-ignored-deferred.js create mode 100644 test/built-ins/Promise/all/reject-ignored-immed.js create mode 100644 test/built-ins/Promise/all/reject-immed.js create mode 100644 test/built-ins/Promise/prototype/then/reject-pending-fulfilled.js create mode 100644 test/built-ins/Promise/prototype/then/reject-pending-rejected.js create mode 100644 test/built-ins/Promise/prototype/then/reject-settled-fulfilled.js create mode 100644 test/built-ins/Promise/prototype/then/reject-settled-rejected.js create mode 100644 test/built-ins/Promise/race/reject-deferred.js create mode 100644 test/built-ins/Promise/race/reject-ignored-deferred.js create mode 100644 test/built-ins/Promise/race/reject-ignored-immed.js create mode 100644 test/built-ins/Promise/race/reject-immed.js create mode 100644 test/built-ins/Promise/reject-ignored-via-abrupt.js create mode 100644 test/built-ins/Promise/reject-ignored-via-fn-deferred.js create mode 100644 test/built-ins/Promise/reject-ignored-via-fn-immed.js create mode 100644 test/built-ins/Promise/reject-via-abrupt.js create mode 100644 test/built-ins/Promise/reject-via-fn-deferred.js create mode 100644 test/built-ins/Promise/reject-via-fn-immed.js diff --git a/test/built-ins/Promise/all/reject-deferred.js b/test/built-ins/Promise/all/reject-deferred.js new file mode 100644 index 0000000000..6b7d43a1ea --- /dev/null +++ b/test/built-ins/Promise/all/reject-deferred.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting through deferred invocation of the provided resolving function +es6id: 25.4.4.1 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseAll(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.1.1 Runtime Semantics: PerformPromiseAll + [...] + 6. Repeat + [...] + r. Let result be Invoke(nextPromise, "then", resolveElement, + promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = { + then: function(_, reject) { + new Promise(function(resolve) { resolve(); }) + .then(function() { + reject(); + }); + } +}; + +Promise.all([thenable]) + .then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + $DONE(); + }); diff --git a/test/built-ins/Promise/all/reject-ignored-deferred.js b/test/built-ins/Promise/all/reject-ignored-deferred.js new file mode 100644 index 0000000000..874e1d40f4 --- /dev/null +++ b/test/built-ins/Promise/all/reject-ignored-deferred.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolved promises ignore rejections through deferred invocation of the + provided resolving function +es6id: 25.4.4.1 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseAll(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.1.1 Runtime Semantics: PerformPromiseAll + [...] + 6. Repeat + [...] + r. Let result be Invoke(nextPromise, "then", resolveElement, + promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 2. Let promise be the value of F's [[Promise]] internal slot. + 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal + slot. + 4. If alreadyResolved.[[value]] is true, return undefined. +---*/ + +var fulfiller = { + then: function(resolve) { + new Promise(function(resolve) { resolve(); }) + .then(function() { + resolve(); + }); + } +}; +var rejector = { + then: function(resolve, reject) { + new Promise(function(resolve) { resolve(); }) + .then(function() { + resolve(); + reject(); + }); + } +}; + +Promise.all([fulfiller, rejector]) + .then(function() { + $DONE(); + }, function() { + $DONE('The promise should not be rejected.'); + }); diff --git a/test/built-ins/Promise/all/reject-ignored-immed.js b/test/built-ins/Promise/all/reject-ignored-immed.js new file mode 100644 index 0000000000..6ef29d1c6b --- /dev/null +++ b/test/built-ins/Promise/all/reject-ignored-immed.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolved promises ignore rejections through immediate invocation of the + provided resolving function +es6id: 25.4.4.1 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseAll(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.1.1 Runtime Semantics: PerformPromiseAll + [...] + 6. Repeat + [...] + r. Let result be Invoke(nextPromise, "then", resolveElement, + promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 2. Let promise be the value of F's [[Promise]] internal slot. + 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal + slot. + 4. If alreadyResolved.[[value]] is true, return undefined. +---*/ + +var fulfiller = { + then: function(resolve) { + resolve(); + } +}; +var lateRejector = { + then: function(resolve, reject) { + resolve(); + reject(); + } +}; + +Promise.all([fulfiller, lateRejector]) + .then(function() { + $DONE(); + }, function() { + $DONE('The promise should not be rejected.'); + }); diff --git a/test/built-ins/Promise/all/reject-immed.js b/test/built-ins/Promise/all/reject-immed.js new file mode 100644 index 0000000000..ce7ff4c490 --- /dev/null +++ b/test/built-ins/Promise/all/reject-immed.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting through immediate invocation of the provided resolving function +es6id: 25.4.4.1 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseAll(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.1.1 Runtime Semantics: PerformPromiseAll + [...] + 6. Repeat + [...] + r. Let result be Invoke(nextPromise, "then", resolveElement, + promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = { + then: function(_, reject) { + reject(); + } +}; + +Promise.all([thenable]) + .then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + $DONE(); + }); diff --git a/test/built-ins/Promise/prototype/then/reject-pending-fulfilled.js b/test/built-ins/Promise/prototype/then/reject-pending-fulfilled.js new file mode 100644 index 0000000000..f89ea8a8a8 --- /dev/null +++ b/test/built-ins/Promise/prototype/then/reject-pending-fulfilled.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting from a pending promise that is later fulfilled +es6id: 25.4.5.3 +info: > + [...] + 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, + resultCapability). + + 25.4.5.3.1 PerformPromiseThen + [...] + 7. If the value of promise's [[PromiseState]] internal slot is "pending", + a. Append fulfillReaction as the last element of the List that is the + value of promise's [[PromiseFulfillReactions]] internal slot. + [...] + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var resolve; +var thenable = new Promise(function(_resolve) { resolve = _resolve; }); +var p1 = new Promise(function(resolve) { resolve(); }); +var p2; + +p2 = p1.then(function() { + throw thenable; + }); + +p2.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + if (x !== thenable) { + $DONE('The promise should be rejected with the resolution value of the provided promise.'); + return; + } + + $DONE(); + }); + +resolve(); diff --git a/test/built-ins/Promise/prototype/then/reject-pending-rejected.js b/test/built-ins/Promise/prototype/then/reject-pending-rejected.js new file mode 100644 index 0000000000..fee4066199 --- /dev/null +++ b/test/built-ins/Promise/prototype/then/reject-pending-rejected.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting from a pending promise that is later rejected +es6id: 25.4.5.3 +info: > + [...] + 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, + resultCapability). + + 25.4.5.3.1 PerformPromiseThen + [...] + 7. If the value of promise's [[PromiseState]] internal slot is "pending", + [...] + b. Append rejectReaction as the last element of the List that is the + value of promise's [[PromiseRejectReactions]] internal slot. + [...] + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var reject; +var thenable = new Promise(function(resolve) { resolve(); }); +var p1 = new Promise(function(_, _reject) { reject = _reject; }); +var p2; + +p2 = p1.then(function() {}, function() { + throw thenable; + }); + +p2.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + if (x !== thenable) { + $DONE('The promise should be rejected with the resolution value of the provided promise.'); + return; + } + + $DONE(); + }); + +reject(); diff --git a/test/built-ins/Promise/prototype/then/reject-settled-fulfilled.js b/test/built-ins/Promise/prototype/then/reject-settled-fulfilled.js new file mode 100644 index 0000000000..bc638eaf51 --- /dev/null +++ b/test/built-ins/Promise/prototype/then/reject-settled-fulfilled.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting from a fulfilled promise +es6id: 25.4.5.3 +info: > + [...] + 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, + resultCapability). + + 25.4.5.3.1 PerformPromiseThen + [...] + 8. Else if the value of promise's [[PromiseState]] internal slot is + "fulfilled", + a. Let value be the value of promise's [[PromiseResult]] internal slot. + b. EnqueueJob("PromiseJobs", PromiseReactionJob, «fulfillReaction, + value»). + + 25.4.2.1 PromiseReactionJob + [...] + 7. If handlerResult is an abrupt completion, then + a. Let status be Call(promiseCapability.[[Reject]], undefined, + «handlerResult.[[value]]»). + [...] + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = new Promise(function(resolve) { resolve(); }); +var p1 = new Promise(function(resolve) { resolve(); }); +var p2; + +p2 = p1.then(function() { + throw thenable; + }); + +p2.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + if (x !== thenable) { + $DONE('The promise should be rejected with the resolution value of the provided promise.'); + return; + } + + $DONE(); + }); diff --git a/test/built-ins/Promise/prototype/then/reject-settled-rejected.js b/test/built-ins/Promise/prototype/then/reject-settled-rejected.js new file mode 100644 index 0000000000..487b94444c --- /dev/null +++ b/test/built-ins/Promise/prototype/then/reject-settled-rejected.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting from a rejected promise +es6id: 25.4.5.3 +info: > + [...] + 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, + resultCapability). + + 25.4.5.3.1 PerformPromiseThen + [...] + 9. Else if the value of promise's [[PromiseState]] internal slot is + "rejected", + a. Let reason be the value of promise's [[PromiseResult]] internal slot. + b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, + «rejectReaction, reason»). + + 25.4.2.1 PromiseReactionJob + [...] + 7. If handlerResult is an abrupt completion, then + a. Let status be Call(promiseCapability.[[Reject]], undefined, + «handlerResult.[[value]]»). + [...] + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = new Promise(function(resolve) { resolve(); }); +var p1 = new Promise(function(_, reject) { reject(); }); +var p2; + +p2 = p1.then(function() {}, function() { + throw thenable; + }); + +p2.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + if (x !== thenable) { + $DONE('The promise should be rejected with the resolution value of the provided promise.'); + return; + } + + $DONE(); + }); diff --git a/test/built-ins/Promise/race/reject-deferred.js b/test/built-ins/Promise/race/reject-deferred.js new file mode 100644 index 0000000000..e070cef6e2 --- /dev/null +++ b/test/built-ins/Promise/race/reject-deferred.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting through deferred invocation of the provided resolving function +es6id: 25.4.4.3 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.3.1 Runtime Semantics: PerformPromiseRace + 1. Repeat + [...] + j. Let result be Invoke(nextPromise, "then", + «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = { + then: function(_, reject) { + new Promise(function(resolve) { resolve(); }) + .then(function() { + reject(); + }); + } +}; + +Promise.race([thenable]) + .then(function() { + $DONE('The promise should not be fulfilled.'); + }, function() { + $DONE(); + }); diff --git a/test/built-ins/Promise/race/reject-ignored-deferred.js b/test/built-ins/Promise/race/reject-ignored-deferred.js new file mode 100644 index 0000000000..bf63e7328b --- /dev/null +++ b/test/built-ins/Promise/race/reject-ignored-deferred.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolved promises ignore rejections through deferred invocation of the + provided resolving function +es6id: 25.4.4.3 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.3.1 Runtime Semantics: PerformPromiseRace + 1. Repeat + [...] + j. Let result be Invoke(nextPromise, "then", + «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 2. Let promise be the value of F's [[Promise]] internal slot. + 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal + slot. + 4. If alreadyResolved.[[value]] is true, return undefined. +---*/ + +var fulfiller = { + then: function(resolve) { + new Promise(function(resolve) { resolve(); }) + .then(function() { + resolve(); + }); + } +}; +var rejector = { + then: function(_, reject) { + new Promise(function(resolve) { resolve(); }) + .then(function() { + reject(); + }); + } +}; + +Promise.race([fulfiller, rejector]) + .then(function() { + $DONE(); + }, function() { + $DONE('The promise should not be rejected.'); + }); diff --git a/test/built-ins/Promise/race/reject-ignored-immed.js b/test/built-ins/Promise/race/reject-ignored-immed.js new file mode 100644 index 0000000000..a22eac484f --- /dev/null +++ b/test/built-ins/Promise/race/reject-ignored-immed.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolved promises ignore rejections through immediate invocation of the + provided resolving function +es6id: 25.4.4.3 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.3.1 Runtime Semantics: PerformPromiseRace + 1. Repeat + [...] + j. Let result be Invoke(nextPromise, "then", + «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 2. Let promise be the value of F's [[Promise]] internal slot. + 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal + slot. + 4. If alreadyResolved.[[value]] is true, return undefined. +---*/ + +var fulfiller = { + then: function(resolve) { + resolve(); + } +}; +var rejector = { + then: function(_, reject) { + reject(); + } +}; + +Promise.race([fulfiller, rejector]) + .then(function() { + $DONE(); + }, function() { + $DONE('The promise should not be rejected.'); + }); diff --git a/test/built-ins/Promise/race/reject-immed.js b/test/built-ins/Promise/race/reject-immed.js new file mode 100644 index 0000000000..4cfc9a925f --- /dev/null +++ b/test/built-ins/Promise/race/reject-immed.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting through immediate invocation of the provided resolving function +es6id: 25.4.4.3 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.3.1 Runtime Semantics: PerformPromiseRace + 1. Repeat + [...] + j. Let result be Invoke(nextPromise, "then", + «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = { + then: function(_, reject) { + reject(); + } +}; + +Promise.race([thenable]) + .then(function() { + $DONE('The promise should not be fulfilled.'); + }, function() { + $DONE(); + }); diff --git a/test/built-ins/Promise/reject-ignored-via-abrupt.js b/test/built-ins/Promise/reject-ignored-via-abrupt.js new file mode 100644 index 0000000000..f3cb6c7a77 --- /dev/null +++ b/test/built-ins/Promise/reject-ignored-via-abrupt.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolved promises ignore rejections through an abrupt completion +es6id: 25.4.3.1 +info: > + [...] + 9. Let completion be Call(executor, undefined, + «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). + 10. If completion is an abrupt completion, then + a. Let status be Call(resolvingFunctions.[[Reject]], undefined, + «completion.[[value]]»). + b. ReturnIfAbrupt(status). + 11. Return promise. + + 25.4.1.3.1 Promise Reject Functions + [...] + 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal + slot. + 4. If alreadyResolved.[[value]] is true, return undefined. +---*/ + +var thenable = new Promise(function() {}); +var p = new Promise(function(resolve) { + resolve(); + throw thenable; +}); + +p.then(function() { + $DONE(); + }, function() { + $DONE('The promise should not be rejected.'); + }); diff --git a/test/built-ins/Promise/reject-ignored-via-fn-deferred.js b/test/built-ins/Promise/reject-ignored-via-fn-deferred.js new file mode 100644 index 0000000000..10b0d81e03 --- /dev/null +++ b/test/built-ins/Promise/reject-ignored-via-fn-deferred.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolved promises ignore rejections through deferred invocation of the + provided resolving function +es6id: 25.4.3.1 +info: > + [...] + 9. Let completion be Call(executor, undefined, + «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). + 10. If completion is an abrupt completion, then + [...] + 11. Return promise. + + 25.4.1.3.1 Promise Reject Functions + [...] + 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal + slot. + 4. If alreadyResolved.[[value]] is true, return undefined. +---*/ + +var thenable = new Promise(function() {}); +var resolve, reject; +var p = new Promise(function(_resolve, _reject) { + resolve = _resolve; + reject = _reject; +}); + +p.then(function() { + $DONE(); + }, function() { + $DONE('The promise should not be rejected.'); + }); + +resolve(); +reject(thenable); diff --git a/test/built-ins/Promise/reject-ignored-via-fn-immed.js b/test/built-ins/Promise/reject-ignored-via-fn-immed.js new file mode 100644 index 0000000000..bd856a342f --- /dev/null +++ b/test/built-ins/Promise/reject-ignored-via-fn-immed.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Resolved promises ignore rejections through immediate invocation of the + provided resolving function +es6id: 25.4.3.1 +info: > + [...] + 9. Let completion be Call(executor, undefined, + «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). + 10. If completion is an abrupt completion, then + [...] + 11. Return promise. + + 25.4.1.3.1 Promise Reject Functions + [...] + 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal + slot. + 4. If alreadyResolved.[[value]] is true, return undefined. +---*/ + +var thenable = new Promise(function() {}); +var p = new Promise(function(resolve, reject) { + resolve(); + reject(thenable); +}); + +p.then(function() { + $DONE(); + }, function() { + $DONE('The promise should not be rejected.'); + }); diff --git a/test/built-ins/Promise/reject-via-abrupt.js b/test/built-ins/Promise/reject-via-abrupt.js new file mode 100644 index 0000000000..6e608bdc22 --- /dev/null +++ b/test/built-ins/Promise/reject-via-abrupt.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting through an abrupt completion +es6id: 25.4.3.1 +info: > + [...] + 9. Let completion be Call(executor, undefined, + «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). + 10. If completion is an abrupt completion, then + a. Let status be Call(resolvingFunctions.[[Reject]], undefined, + «completion.[[value]]»). + b. ReturnIfAbrupt(status). + 11. Return promise. + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = new Promise(function() {}); +var p = new Promise(function() { + throw thenable; +}); + +p.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + if (x !== thenable) { + $DONE('The promise should be rejected with the resolution value.'); + return; + } + + $DONE(); + }); diff --git a/test/built-ins/Promise/reject-via-fn-deferred.js b/test/built-ins/Promise/reject-via-fn-deferred.js new file mode 100644 index 0000000000..855d92b410 --- /dev/null +++ b/test/built-ins/Promise/reject-via-fn-deferred.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting through deferred invocation of the provided resolving function +es6id: 25.4.3.1 +info: > + [...] + 9. Let completion be Call(executor, undefined, + «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). + 10. If completion is an abrupt completion, then + [...] + 11. Return promise. + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = new Promise(function() {}); +var reject; +var p = new Promise(function(_, _reject) { + reject = _reject; +}); + +p.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + if (x !== thenable) { + $DONE('The promise should be rejected with the resolution value.'); + return; + } + + $DONE(); + }); + +reject(thenable); diff --git a/test/built-ins/Promise/reject-via-fn-immed.js b/test/built-ins/Promise/reject-via-fn-immed.js new file mode 100644 index 0000000000..474db80d8b --- /dev/null +++ b/test/built-ins/Promise/reject-via-fn-immed.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Rejecting through immediate invocation of the provided resolving function +es6id: 25.4.3.1 +info: > + [...] + 9. Let completion be Call(executor, undefined, + «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). + 10. If completion is an abrupt completion, then + [...] + 11. Return promise. + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +---*/ + +var thenable = new Promise(function() {}); +var p = new Promise(function(_, reject) { + reject(thenable); +}); + +p.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(x) { + if (x !== thenable) { + $DONE('The promise should be rejected with the resolution value.'); + return; + } + + $DONE(); + }); diff --git a/test/built-ins/Promise/reject/S25.4.4.4_A2.1_T1.js b/test/built-ins/Promise/reject/S25.4.4.4_A2.1_T1.js index 1c721b3d72..bc589ac13f 100644 --- a/test/built-ins/Promise/reject/S25.4.4.4_A2.1_T1.js +++ b/test/built-ins/Promise/reject/S25.4.4.4_A2.1_T1.js @@ -3,8 +3,14 @@ /*--- info: > - Promise.reject -es6id: S25.4.4.4_A2.1_T1 + [...] + 5. Let rejectResult be Call(promiseCapability.[[Reject]], undefined, «r»). + [...] + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +es6id: 25.4.4.4 author: Sam Mikes description: Promise.reject creates a new settled promise ---*/