diff --git a/test/built-ins/Promise/prototype/then/prfm-fulfilled.js b/test/built-ins/Promise/prototype/then/prfm-fulfilled.js new file mode 100644 index 0000000000000000000000000000000000000000..ac49fee03e547671a4560a88fc4e5b7286f99b35 --- /dev/null +++ b/test/built-ins/Promise/prototype/then/prfm-fulfilled.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.4.5.3 +description: PerformPromiseThen on a fulfilled promise +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. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, + «fulfillReaction, value»). + [...] +---*/ + +var value = {}; +var p = new Promise(function(resolve) { resolve(value); }); + +p.then(function(x) { + if (x !== value) { + $DONE('The `onFulfilled` handler should be invoked with the promise result.'); + return; + } + $DONE(); + }, function() { + $DONE('The `onRejected` handler should not be invoked.'); + }); diff --git a/test/built-ins/Promise/prototype/then/prfm-when-rejected-throw.js b/test/built-ins/Promise/prototype/then/prfm-rejected.js similarity index 62% rename from test/built-ins/Promise/prototype/then/prfm-when-rejected-throw.js rename to test/built-ins/Promise/prototype/then/prfm-rejected.js index b218329cff5a0c7826a80d2d295544444b7bce7b..727eea81f189861de21ef418cb2f50b47b372c83 100644 --- a/test/built-ins/Promise/prototype/then/prfm-when-rejected-throw.js +++ b/test/built-ins/Promise/prototype/then/prfm-rejected.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- es6id: 25.4.5.3 -description: The `onRejected` method throws an error +description: PerformPromiseThen on a rejected promise info: > 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability). @@ -15,19 +15,18 @@ info: > a. Let reason be the value of promise's [[PromiseResult]] internal slot. b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, «rejectReaction, reason»). + [...] ---*/ -var error = new Test262Error(); -var promise = new Promise(function(_, reject) { - reject(); -}); - -promise.then(null, function() { - throw error; - }).then(function(result) { - $DONE('This promise should not be fulfilled'); - }, function(reason) { - assert.sameValue(reason, error); +var value = {}; +var p = new Promise(function(_, reject) { reject(value); }); +p.then(function() { + $DONE('The `onFulfilled` handler should not be invoked.'); + }, function(x) { + if (x !== value) { + $DONE('The `onRejected` handler should be invoked with the promise result.'); + return; + } $DONE(); }); diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-poisoned-then.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-poisoned-then.js deleted file mode 100644 index 1b6fcb0c633decd34e395c2cc6ea55451dd36fe1..0000000000000000000000000000000000000000 --- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-poisoned-then.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -es6id: 25.4.5.3 -description: > - Access error for the `then` property of the object returned from the "on fulfilled" handler -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. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, - «fulfillReaction, value»). - - 25.4.1.3.2 Promise Resolve Functions - - [...] - 8. Let then be Get(resolution, "then"). - 9. If then is an abrupt completion, then - a. Return RejectPromise(promise, then.[[value]]). ----*/ - -var poisonedThen = {}; -var error = new Test262Error(); -Object.defineProperty(poisonedThen, 'then', { - get: function() { - throw error; - } -}); - -var p = new Promise(function(r) { r(); }); - -p.then(function() { - return poisonedThen; -}).then(function() { - $DONE('The promise should not be fulfilled'); -}, function(reason) { - assert.sameValue(reason, error); - - $DONE(); -}); diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-self.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-self.js deleted file mode 100644 index 42e2588ef4a66ca9436c0a145df5293f873388fb..0000000000000000000000000000000000000000 --- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-self.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -es6id: 25.4.5.3 -description: The return value of the `onFulfilled` method is a "thenable" object -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. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, - «fulfillReaction, value»). - - 25.4.1.3.2 Promise Resolve Functions - - [...] - 6. If SameValue(resolution, promise) is true, then - a. Let selfResolutionError be a newly created TypeError object. - b. Return RejectPromise(promise, selfResolutionError). ----*/ - -var promise1 = new Promise(function(resolve) { - resolve(); -}); - -var promise2 = promise1.then(function() { - return promise2; -}); - -promise2.then(function() { - $DONE('This promise should not be resolved'); -}, function(reason) { - assert.sameValue(reason.constructor, TypeError); - - $DONE(); -}); diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-throw.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-throw.js deleted file mode 100644 index 434cd57953c0202401e60210dc58f8e628a74ae3..0000000000000000000000000000000000000000 --- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-throw.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -es6id: 25.4.5.3 -description: The `onFulfilled` method throws an error -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. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, - «fulfillReaction, value»). - - 25.4.1.3.2 Promise Resolve Functions - - [...] - 8. Let then be Get(resolution, "then"). - 9. If then is an abrupt completion, then - a. Return RejectPromise(promise, then.[[value]]). - 10. Let thenAction be then.[[value]]. - 11. If IsCallable(thenAction) is false, then - a. Return FulfillPromise(promise, resolution). - 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, «promise, - resolution, thenAction») - 13. Return undefined. - - 25.4.2.2 PromiseResolveThenableJob - - 2. Let thenCallResult be Call(then, thenable, - «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). - 3. If thenCallResult is an abrupt completion, - a. Let status be Call(resolvingFunctions.[[Reject]], undefined, - «thenCallResult.[[value]]»). - b. NextJob Completion(status). ----*/ - -var error = new Test262Error(); -var promiseFulfilled = false; -var promiseRejected = false; -var promise = new Promise(function(resolve) { - resolve(); - }); - -promise.then(function() { - throw error; - }).then(function() { - $DONE('This promise should not be fulfilled'); - }, function(reason) { - assert.sameValue(reason, error); - - $DONE(); - }); diff --git a/test/built-ins/Promise/prototype/then/prfm-when-rejected-return-value.js b/test/built-ins/Promise/prototype/then/prfm-when-rejected-return-value.js deleted file mode 100644 index 14f7c2df910f917ffbe5901f822e69b21dac0b59..0000000000000000000000000000000000000000 --- a/test/built-ins/Promise/prototype/then/prfm-when-rejected-return-value.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -es6id: 25.4.5.3 -description: The return value of the `onRejected` method -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»). ----*/ - -var returnVal = {}; -var promise = new Promise(function(_, reject) { - reject(); -}); - -promise.then(null, function() { - return returnVal; -}).then(function(result) { - assert.sameValue(result, returnVal); - - $DONE(); -}, function() { - $DONE('The promise should not be rejected'); -}); diff --git a/test/built-ins/Promise/prototype/then/rxn-handler-fulfilled-return-abrupt.js b/test/built-ins/Promise/prototype/then/rxn-handler-fulfilled-return-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..429c3171f52e1dadaada48524ed1b57b11233e26 --- /dev/null +++ b/test/built-ins/Promise/prototype/then/rxn-handler-fulfilled-return-abrupt.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: An abrupt completion should trigger promise rejection +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]]»). + b. NextJob Completion(status). + 8. Let status be Call(promiseCapability.[[Resolve]], undefined, + «handlerResult.[[value]]»). + 9. NextJob Completion(status). +---*/ + +var value = {}; +var p1 = new Promise(function(resolve) { + resolve(); +}); +var p2; + +p2 = p1.then(function() { + throw value; + }, function() {}); + +p2.then(function() { + $DONE('The `onFulfilled` handler should not be invoked.'); + }, function(x) { + if (x !== value) { + $DONE('The `onRejected` handler should be invoked with the promise result.'); + return; + } + + $DONE(); + }); diff --git a/test/built-ins/Promise/prototype/then/rxn-handler-fulfilled-return-normal.js b/test/built-ins/Promise/prototype/then/rxn-handler-fulfilled-return-normal.js new file mode 100644 index 0000000000000000000000000000000000000000..4437d5fb7356a47ffe36b272d26fb2a71480921b --- /dev/null +++ b/test/built-ins/Promise/prototype/then/rxn-handler-fulfilled-return-normal.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: A normal completion should trigger promise fulfillment +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]]»). + b. NextJob Completion(status). + 8. Let status be Call(promiseCapability.[[Resolve]], undefined, + «handlerResult.[[value]]»). + 9. NextJob Completion(status). +---*/ + +var value = {}; +var p1 = new Promise(function(resolve) { + resolve(); +}); +var p2; + +p2 = p1.then(function() { + return value; + }, function() {}); + +p2.then(function(x) { + if (x !== value) { + $DONE('The `onFulfilled` handler should be invoked with the promise result.'); + return; + } + + $DONE(); + }, function() { + $DONE('The `onRejected` handler should not be invoked.'); + }); diff --git a/test/built-ins/Promise/prototype/then/rxn-handler-rejected-return-abrupt.js b/test/built-ins/Promise/prototype/then/rxn-handler-rejected-return-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..5b95a5a042a3e18bbcaf85de6a2ba2c18359447e --- /dev/null +++ b/test/built-ins/Promise/prototype/then/rxn-handler-rejected-return-abrupt.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: An abrupt completion should trigger promise rejection +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]]»). + b. NextJob Completion(status). + 8. Let status be Call(promiseCapability.[[Resolve]], undefined, + «handlerResult.[[value]]»). + 9. NextJob Completion(status). +---*/ + +var value = {}; +var p1 = new Promise(function(_, reject) { + reject(); +}); +var p2; + +p2 = p1.then(function() {}, function() { + throw value; + }); + +p2.then(function() { + $DONE('The `onFulfilled` handler should not be invoked.'); + }, function(x) { + if (x !== value) { + $DONE('The `onRejected` handler should be invoked with the promise result.'); + return; + } + + $DONE(); + });