Skip to content
Snippets Groups Projects
Commit 5a8d1fdf authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Re-organize tests according to internal operations

By organizing files according to the structure of the specification,
test coverage can be more methodically evaluated.
parent 29cdc454
No related branches found
No related tags found
No related merge requests found
// Copyright (C) 2015 the V8 project authors. All rights reserved. // Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
es6id: 25.4.5.3 es6id: 25.4.5.3
description: The return value of the `onFulfilled` method is a "thenable" object description: PerformPromiseThen on a fulfilled promise
info: > info: >
7. Return PerformPromiseThen(promise, onFulfilled, onRejected, 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
resultCapability). resultCapability).
...@@ -15,27 +15,18 @@ info: > ...@@ -15,27 +15,18 @@ info: >
a. Let value be the value of promise's [[PromiseResult]] internal slot. a. Let value be the value of promise's [[PromiseResult]] internal slot.
b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
«fulfillReaction, value»). «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) { var value = {};
resolve(); var p = new Promise(function(resolve) { resolve(value); });
});
p.then(function(x) {
var promise2 = promise1.then(function() { if (x !== value) {
return promise2; $DONE('The `onFulfilled` handler should be invoked with the promise result.');
}); return;
}
promise2.then(function() { $DONE();
$DONE('This promise should not be resolved'); }, function() {
}, function(reason) { $DONE('The `onRejected` handler should not be invoked.');
assert.sameValue(reason.constructor, TypeError); });
$DONE();
});
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
es6id: 25.4.5.3 es6id: 25.4.5.3
description: The `onRejected` method throws an error description: PerformPromiseThen on a rejected promise
info: > info: >
7. Return PerformPromiseThen(promise, onFulfilled, onRejected, 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
resultCapability). resultCapability).
...@@ -15,19 +15,18 @@ info: > ...@@ -15,19 +15,18 @@ info: >
a. Let reason be the value of promise's [[PromiseResult]] internal slot. a. Let reason be the value of promise's [[PromiseResult]] internal slot.
b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
«rejectReaction, reason»). «rejectReaction, reason»).
[...]
---*/ ---*/
var error = new Test262Error(); var value = {};
var promise = new Promise(function(_, reject) { var p = new Promise(function(_, reject) { reject(value); });
reject();
});
promise.then(null, function() {
throw error;
}).then(function(result) {
$DONE('This promise should not be fulfilled');
}, function(reason) {
assert.sameValue(reason, error);
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(); $DONE();
}); });
// 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();
});
// Copyright (C) 2015 the V8 project authors. All rights reserved. // Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // 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 es6id: 25.4.5.3
description: >
Access error for the `then` property of the object returned from the "on fulfilled" handler
info: > info: >
[...]
7. Return PerformPromiseThen(promise, onFulfilled, onRejected, 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
resultCapability). resultCapability).
25.4.5.3.1 PerformPromiseThen 25.4.5.3.1 PerformPromiseThen
[...] [...]
8. Else if the value of promise's [[PromiseState]] internal slot is 8. Else if the value of promise's [[PromiseState]] internal slot is
"fulfilled", "fulfilled",
a. Let value be the value of promise's [[PromiseResult]] internal slot. a. Let value be the value of promise's [[PromiseResult]] internal slot.
b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, b. EnqueueJob("PromiseJobs", PromiseReactionJob, «fulfillReaction,
«fulfillReaction, value»). value»).
25.4.1.3.2 Promise Resolve Functions
25.4.2.1 PromiseReactionJob
[...] [...]
8. Let then be Get(resolution, "then"). 7. If handlerResult is an abrupt completion, then
9. If then is an abrupt completion, then a. Let status be Call(promiseCapability.[[Reject]], undefined,
a. Return RejectPromise(promise, then.[[value]]). «handlerResult.[[value]]»).
b. NextJob Completion(status).
8. Let status be Call(promiseCapability.[[Resolve]], undefined,
«handlerResult.[[value]]»).
9. NextJob Completion(status).
---*/ ---*/
var poisonedThen = {}; var value = {};
var error = new Test262Error(); var p1 = new Promise(function(resolve) {
Object.defineProperty(poisonedThen, 'then', { resolve();
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();
}); });
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();
});
// 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.');
});
// Copyright (C) 2015 the V8 project authors. All rights reserved. // Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // 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 es6id: 25.4.5.3
description: The return value of the `onRejected` method
info: > info: >
[...]
7. Return PerformPromiseThen(promise, onFulfilled, onRejected, 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
resultCapability). resultCapability).
25.4.5.3.1 PerformPromiseThen 25.4.5.3.1 PerformPromiseThen
[...] [...]
9. Else if the value of promise's [[PromiseState]] internal slot is 9. Else if the value of promise's [[PromiseState]] internal slot is
"rejected", "rejected",
a. Let reason be the value of promise's [[PromiseResult]] internal slot. a. Let reason be the value of promise's [[PromiseResult]] internal slot.
b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
«rejectReaction, reason»). «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 returnVal = {}; var value = {};
var promise = new Promise(function(_, reject) { var p1 = new Promise(function(_, reject) {
reject(); reject();
}); });
var p2;
promise.then(null, function() { p2 = p1.then(function() {}, function() {
return returnVal; throw value;
}).then(function(result) { });
assert.sameValue(result, returnVal);
$DONE(); p2.then(function() {
}, function() { $DONE('The `onFulfilled` handler should not be invoked.');
$DONE('The promise should not be rejected'); }, function(x) {
}); if (x !== value) {
$DONE('The `onRejected` handler should be invoked with the promise result.');
return;
}
$DONE();
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment