mirror of https://github.com/tc39/test262.git
Promise.any: coverage update r3 (#2658)
This commit is contained in:
parent
c4c978b7ed
commit
f2ab5b6ca1
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: Rejecting with a non-thenable object value
|
||||||
|
esid: sec-promise.any
|
||||||
|
info: |
|
||||||
|
PerformPromiseAny
|
||||||
|
|
||||||
|
Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
|
||||||
|
Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
|
||||||
|
|
||||||
|
Promise.any Reject Element Functions
|
||||||
|
|
||||||
|
Let alreadyCalled be F.[[AlreadyCalled]].
|
||||||
|
If alreadyCalled.[[Value]] is true, return undefined.
|
||||||
|
Set alreadyCalled.[[Value]] to true.
|
||||||
|
...
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let callCount = 0;
|
||||||
|
let error;
|
||||||
|
|
||||||
|
function Constructor(executor) {
|
||||||
|
function reject(result) {
|
||||||
|
callCount += 1;
|
||||||
|
error = result;
|
||||||
|
}
|
||||||
|
executor(() => {throw new Test262Error()}, reject);
|
||||||
|
}
|
||||||
|
Constructor.resolve = function(v) {
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
|
||||||
|
let p1OnRejected, p2OnRejected, p3OnRejected;
|
||||||
|
|
||||||
|
let p1 = {
|
||||||
|
then(_, onRejected) {
|
||||||
|
p1OnRejected = onRejected;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let p2 = {
|
||||||
|
then(_, onRejected) {
|
||||||
|
p2OnRejected = onRejected;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let p3 = {
|
||||||
|
then(_, onRejected) {
|
||||||
|
p3OnRejected = onRejected;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 0, 'callCount before call to any()');
|
||||||
|
|
||||||
|
Promise.any.call(Constructor, [p1, p2, p3]);
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 0, 'callCount after call to any()');
|
||||||
|
|
||||||
|
p1OnRejected('p1-rejection');
|
||||||
|
p1OnRejected('p1-rejection-unexpected-1');
|
||||||
|
p1OnRejected('p1-rejection-unexpected-2');
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 0, 'callCount after resolving p1');
|
||||||
|
|
||||||
|
p2OnRejected('p2-rejection');
|
||||||
|
p3OnRejected('p3-rejection');
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1, 'callCount after resolving all elements');
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: Resolving with a non-thenable object value
|
||||||
|
esid: sec-promise.any
|
||||||
|
info: |
|
||||||
|
PerformPromiseAny
|
||||||
|
|
||||||
|
Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
|
||||||
|
Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const a = {};
|
||||||
|
const b = {};
|
||||||
|
const c = {};
|
||||||
|
|
||||||
|
Promise.any([a, b, c])
|
||||||
|
.then((value) => {
|
||||||
|
assert.sameValue(value, a);
|
||||||
|
}, () => {
|
||||||
|
$DONE('The promise should not be rejected.');
|
||||||
|
}).then($DONE, $DONE);
|
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.any
|
||||||
|
description: Resolution ticks are set in a predictable sequence with extra then calls
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability )
|
||||||
|
|
||||||
|
Let remainingElementsCount be a new Record { [[Value]]: 1 }.
|
||||||
|
...
|
||||||
|
|
||||||
|
Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
|
||||||
|
If remainingElementsCount.[[Value]] is 0, then
|
||||||
|
Let error be a newly created AggregateError object.
|
||||||
|
Perform ! DefinePropertyOrThrow(error, "errors",
|
||||||
|
Property Descriptor {
|
||||||
|
[[Configurable]]: true,
|
||||||
|
[[Enumerable]]: false,
|
||||||
|
[[Writable]]: true,
|
||||||
|
[[Value]]: errors
|
||||||
|
}).
|
||||||
|
Return ? Call(promiseCapability.[[Reject]], undefined, « error »).
|
||||||
|
...
|
||||||
|
flags: [async]
|
||||||
|
includes: [promiseHelper.js]
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let sequence = [];
|
||||||
|
|
||||||
|
let p1 = new Promise(resolve => {
|
||||||
|
resolve({});
|
||||||
|
});
|
||||||
|
|
||||||
|
sequence.push(1);
|
||||||
|
|
||||||
|
Promise.any([p1]).then((resolved) => {
|
||||||
|
sequence.push(4);
|
||||||
|
checkSequence(sequence, 'Expected Promise.any().then to queue second');
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
p1.then(() => {
|
||||||
|
sequence.push(3);
|
||||||
|
checkSequence(sequence, 'Expected p1.then to queue first');
|
||||||
|
}).then(() => {
|
||||||
|
sequence.push(5);
|
||||||
|
checkSequence(sequence, 'Expected final then to queue last');
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
sequence.push(2);
|
|
@ -0,0 +1,65 @@
|
||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.any
|
||||||
|
description: >
|
||||||
|
Resolution ticks are set in a predictable sequence of mixed fulfilled and rejected promises
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability )
|
||||||
|
|
||||||
|
Let remainingElementsCount be a new Record { [[Value]]: 1 }.
|
||||||
|
...
|
||||||
|
|
||||||
|
Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
|
||||||
|
If remainingElementsCount.[[Value]] is 0, then
|
||||||
|
Let error be a newly created AggregateError object.
|
||||||
|
Perform ! DefinePropertyOrThrow(error, "errors",
|
||||||
|
Property Descriptor {
|
||||||
|
[[Configurable]]: true,
|
||||||
|
[[Enumerable]]: false,
|
||||||
|
[[Writable]]: true,
|
||||||
|
[[Value]]: errors
|
||||||
|
}).
|
||||||
|
Return ? Call(promiseCapability.[[Reject]], undefined, « error »).
|
||||||
|
...
|
||||||
|
flags: [async]
|
||||||
|
includes: [promiseHelper.js]
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let sequence = [];
|
||||||
|
|
||||||
|
let p1 = new Promise((_, reject) => {
|
||||||
|
reject('');
|
||||||
|
});
|
||||||
|
let p2 = new Promise(resolve => {
|
||||||
|
resolve('');
|
||||||
|
});
|
||||||
|
let p3 = new Promise((_, reject) => {
|
||||||
|
reject('');
|
||||||
|
});
|
||||||
|
|
||||||
|
sequence.push(1);
|
||||||
|
|
||||||
|
p1.catch(() => {
|
||||||
|
sequence.push(3);
|
||||||
|
checkSequence(sequence, 'Expected to be called first.');
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
Promise.any([p1, p2, p3]).then(() => {
|
||||||
|
sequence.push(6);
|
||||||
|
checkSequence(sequence, 'Expected to be called fourth.');
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
p2.then(() => {
|
||||||
|
sequence.push(4);
|
||||||
|
checkSequence(sequence, 'Expected to be called second.');
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
sequence.push(2);
|
||||||
|
|
||||||
|
p3.catch(() => {
|
||||||
|
sequence.push(5);
|
||||||
|
checkSequence(sequence, 'Expected to be called third.');
|
||||||
|
}).catch($DONE);
|
|
@ -0,0 +1,61 @@
|
||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.any
|
||||||
|
description: Resolution ticks are set in a predictable sequence
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability )
|
||||||
|
|
||||||
|
Let remainingElementsCount be a new Record { [[Value]]: 1 }.
|
||||||
|
...
|
||||||
|
|
||||||
|
Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
|
||||||
|
If remainingElementsCount.[[Value]] is 0, then
|
||||||
|
Let error be a newly created AggregateError object.
|
||||||
|
Perform ! DefinePropertyOrThrow(error, "errors",
|
||||||
|
Property Descriptor {
|
||||||
|
[[Configurable]]: true,
|
||||||
|
[[Enumerable]]: false,
|
||||||
|
[[Writable]]: true,
|
||||||
|
[[Value]]: errors
|
||||||
|
}).
|
||||||
|
Return ? Call(promiseCapability.[[Reject]], undefined, « error »).
|
||||||
|
...
|
||||||
|
flags: [async]
|
||||||
|
includes: [promiseHelper.js]
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let sequence = [];
|
||||||
|
|
||||||
|
let p1 = new Promise((_, reject) => {
|
||||||
|
reject('foo');
|
||||||
|
});
|
||||||
|
let p2 = new Promise((_, reject) => {
|
||||||
|
reject('bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
sequence.push(1);
|
||||||
|
|
||||||
|
p1.catch(() => {
|
||||||
|
sequence.push(3);
|
||||||
|
checkSequence(sequence, 'Expected to be called first.');
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
Promise.any([p1, p2]).then(() => {
|
||||||
|
sequence.push(5);
|
||||||
|
checkSequence(sequence, 'Expected to be called third.');
|
||||||
|
}).then($DONE, outcome => {
|
||||||
|
assert(outcome instanceof AggregateError);
|
||||||
|
assert.sameValue(outcome.errors.length, 2);
|
||||||
|
assert.sameValue(outcome.errors[0], 'foo');
|
||||||
|
assert.sameValue(outcome.errors[1], 'bar');
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
p2.catch(() => {
|
||||||
|
sequence.push(4);
|
||||||
|
checkSequence(sequence, 'Expected to be called second.');
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
sequence.push(2);
|
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.any
|
||||||
|
description: Resolution ticks are set in a predictable sequence
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability )
|
||||||
|
|
||||||
|
Let remainingElementsCount be a new Record { [[Value]]: 1 }.
|
||||||
|
...
|
||||||
|
6.d ...
|
||||||
|
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
|
||||||
|
iii. If remainingElementsCount.[[value]] is 0, then
|
||||||
|
Let error be a newly created AggregateError object.
|
||||||
|
Perform ! DefinePropertyOrThrow(error, "errors",
|
||||||
|
Property Descriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: errors }).
|
||||||
|
Return ThrowCompletion(error).
|
||||||
|
...
|
||||||
|
flags: [async]
|
||||||
|
includes: [promiseHelper.js]
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var sequence = [];
|
||||||
|
|
||||||
|
var p1 = new Promise(resolve => {
|
||||||
|
resolve(1);
|
||||||
|
});
|
||||||
|
var p2 = new Promise(resolve => {
|
||||||
|
resolve(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
sequence.push(1);
|
||||||
|
|
||||||
|
p1.then(function() {
|
||||||
|
sequence.push(3);
|
||||||
|
checkSequence(sequence, 'Expected to be called first.');
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
Promise.any([p1, p2]).then(function() {
|
||||||
|
sequence.push(5);
|
||||||
|
checkSequence(sequence, 'Expected to be called third.');
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
p2.then(function() {
|
||||||
|
sequence.push(4);
|
||||||
|
checkSequence(sequence, 'Expected to be called second.');
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
sequence.push(2);
|
Loading…
Reference in New Issue