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

Extend coverage for PromiseReactionJob

Add tests that assert sequential job execution
parent eded6b26
No related branches found
No related tags found
No related merge requests found
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Abrupt completions should not preclude additional jobs
es6id: 25.4.2.1
info: >
[...]
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 promise = new Promise(function(resolve) {
resolve();
});
var fulfilledCallCount = 0;
var rejectedCallCount = 0;
promise.then(function() {
fulfilledCallCount += 1;
throw new Error();
}, function() {
rejectedCallCount += 1;
});
promise.then(function() {
if (fulfilledCallCount !== 1) {
$DONE('Expected "onFulfilled" handler to be invoked exactly once.');
return;
}
if (rejectedCallCount !== 0) {
$DONE('Expected "onRejected" handler to not be invoked.');
return;
}
$DONE();
}, function() {
$DONE('This promise should not be rejected.');
});
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: All queued jobs should be executed in series
es6id: 25.4.2.1
info: >
[...]
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 promise = new Promise(function(resolve) {
resolve();
});
var log = '';
promise.then(function() {
log += 'a';
}, function() {
log += 'A';
});
promise.then(function() {
log += 'b';
}, function() {
log += 'B';
});
promise.then(function() {
log += 'c';
}, function() {
log += 'C';
});
promise.then(function() {
if (log !== 'abc') {
$DONE(
'Expected each "onFulfilled" handler to be invoked exactly once in series. ' +
'Expected: abc. Actual: ' + log
);
return;
}
$DONE();
}, function() {
$DONE('This promise should not be rejected.');
});
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Abrupt completions should not preclude additional jobs
es6id: 25.4.2.1
info: >
[...]
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 promise = new Promise(function(_, reject) {
reject();
});
var fulfilledCallCount = 0;
var rejectedCallCount = 0;
promise.then(function() {
fulfilledCallCount += 1;
}, function() {
rejectedCallCount += 1;
throw new Error();
});
promise.then(function() {
$DONE('This promise should not be fulfilled.');
}, function() {
if (fulfilledCallCount !== 0) {
$DONE('Expected "onFulfilled" handler to not be invoked.');
return;
}
if (rejectedCallCount !== 1) {
$DONE('Expected "onRejected" handler to be invoked exactly once.');
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: All queued jobs should be executed in series
es6id: 25.4.2.1
info: >
[...]
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 promise = new Promise(function(_, reject) {
reject();
});
var log = '';
promise.then(function() {
log += 'A';
}, function() {
log += 'a';
});
promise.then(function() {
log += 'B';
}, function() {
log += 'b';
});
promise.then(function() {
log += 'C';
}, function() {
log += 'c';
});
promise.then(function() {
$DONE('This promise should not be fulfilled.');
}, function() {
if (log !== 'abc') {
$DONE(
'Expected each "onFulfilled" handler to be invoked exactly once in series. ' +
'Expected: abc. Actual: ' + log
);
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
[...]
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() {
return value;
});
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.');
});
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