Merge pull request #462 from jugglinmike/improve-promise-coverage-reject

Improve Promise coverage: Promise Reject Function
This commit is contained in:
Gorkem Yakin 2016-01-13 16:49:21 -08:00
commit 9d48bb0875
19 changed files with 742 additions and 2 deletions

View File

@ -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();
});

View File

@ -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.');
});

View File

@ -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.');
});

View File

@ -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();
});

View File

@ -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();

View File

@ -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();

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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.');
});

View File

@ -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.');
});

View File

@ -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();
});

View File

@ -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.');
});

View File

@ -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);

View File

@ -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.');
});

View File

@ -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();
});

View File

@ -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);

View File

@ -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();
});

View File

@ -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
---*/