mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 04:54:44 +02:00
Promise.any: coverage updates, R1
This commit is contained in:
parent
0fcc51c9e2
commit
3604a65a29
@ -0,0 +1,56 @@
|
|||||||
|
// 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-reject-element-functions
|
||||||
|
description: >
|
||||||
|
Cannot change result value of rejected Promise.any element after Promise.any() returned.
|
||||||
|
info: |
|
||||||
|
Promise.any Reject Element Functions
|
||||||
|
|
||||||
|
Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot.
|
||||||
|
If alreadyCalled.[[value]] is true, return undefined.
|
||||||
|
Set alreadyCalled.[[value]] to true.
|
||||||
|
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let callCount = 0;
|
||||||
|
let errorArray;
|
||||||
|
|
||||||
|
function Constructor(executor) {
|
||||||
|
function reject(error) {
|
||||||
|
callCount += 1;
|
||||||
|
errorArray = error.errors;
|
||||||
|
|
||||||
|
assert(Array.isArray(error.errors), "error is array");
|
||||||
|
assert.sameValue(error.errors.length, 1, "error.length");
|
||||||
|
assert.sameValue(error.errors[0], "onRejectedValue", "error[0]");
|
||||||
|
assert(error instanceof AggregateError, "error instanceof AggregateError");
|
||||||
|
}
|
||||||
|
executor($ERROR, reject);
|
||||||
|
}
|
||||||
|
Constructor.resolve = function(v) {
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
|
||||||
|
let p1OnRejected;
|
||||||
|
|
||||||
|
let p1 = {
|
||||||
|
then(onFulfilled, onRejected) {
|
||||||
|
p1OnRejected = onRejected;
|
||||||
|
onRejected("onRejectedValue");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 0, "callCount before call to any()");
|
||||||
|
|
||||||
|
Promise.any.call(Constructor, [p1]);
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1, "callCount after call to any()");
|
||||||
|
assert.sameValue(errorArray[0], "onRejectedValue", "errorArray after call to any()");
|
||||||
|
|
||||||
|
p1OnRejected("unexpectedonRejectedValue");
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1, "callCount after call to onRejected()");
|
||||||
|
assert.sameValue(errorArray[0], "onRejectedValue", "errorArray after call to onRejected()");
|
51
test/built-ins/Promise/any/call-reject-element-items.js
Normal file
51
test/built-ins/Promise/any/call-reject-element-items.js
Normal file
@ -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-reject-element-functions
|
||||||
|
description: >
|
||||||
|
Cannot change result value of rejected Promise.any elements.
|
||||||
|
info: |
|
||||||
|
Promise.any Reject Element Functions
|
||||||
|
|
||||||
|
Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot.
|
||||||
|
If alreadyCalled.[[value]] is true, return undefined.
|
||||||
|
Set alreadyCalled.[[value]] to true.
|
||||||
|
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let callCount = 0;
|
||||||
|
|
||||||
|
function Constructor(executor) {
|
||||||
|
function reject(error) {
|
||||||
|
callCount += 1;
|
||||||
|
assert(Array.isArray(error.errors), "error.errors is array");
|
||||||
|
assert.sameValue(error.errors.length, 2, "error.errors length");
|
||||||
|
assert.sameValue(error.errors[0], "expectedValue-p1", "error.errors[0]");
|
||||||
|
assert.sameValue(error.errors[1], "expectedValue-p2", "error.errors[1]");
|
||||||
|
}
|
||||||
|
executor($ERROR, reject);
|
||||||
|
}
|
||||||
|
Constructor.resolve = function(v) {
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
|
||||||
|
let p1 = {
|
||||||
|
then(onFulfilled, onRejected) {
|
||||||
|
onRejected("expectedValue-p1");
|
||||||
|
onRejected("unexpectedValue-p1");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let p2 = {
|
||||||
|
then(onFulfilled, onRejected) {
|
||||||
|
onRejected("expectedValue-p2");
|
||||||
|
onRejected("unexpectedValue-p2");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 0, "callCount before call to any()");
|
||||||
|
|
||||||
|
Promise.any.call(Constructor, [p1, p2]);
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1, "callCount after call to any()");
|
@ -0,0 +1,52 @@
|
|||||||
|
// 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: >
|
||||||
|
Iterator is not closed when the "resolve" capability returns an abrupt
|
||||||
|
completion.
|
||||||
|
info: |
|
||||||
|
Let C be the this value.
|
||||||
|
Let promiseCapability be ? NewPromiseCapability(C).
|
||||||
|
Let iteratorRecord be GetIterator(iterable).
|
||||||
|
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
|
||||||
|
Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
|
||||||
|
If result is an abrupt completion, then
|
||||||
|
If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
|
||||||
|
IfAbruptRejectPromise(result, promiseCapability).
|
||||||
|
Return Completion(result).
|
||||||
|
|
||||||
|
features: [Promise.any, Symbol.iterator]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let nextCount = 0;
|
||||||
|
let returnCount = 0;
|
||||||
|
let iter = {};
|
||||||
|
iter[Symbol.iterator] = function() {
|
||||||
|
return {
|
||||||
|
next() {
|
||||||
|
nextCount += 1;
|
||||||
|
return {
|
||||||
|
done: true
|
||||||
|
};
|
||||||
|
},
|
||||||
|
return() {
|
||||||
|
returnCount += 1;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
let P = function(executor) {
|
||||||
|
return new Promise(function(resolve) {
|
||||||
|
executor(resolve, function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
P.resolve = Promise.resolve;
|
||||||
|
|
||||||
|
Promise.any.call(P, iter);
|
||||||
|
|
||||||
|
assert.sameValue(nextCount, 1);
|
||||||
|
assert.sameValue(returnCount, 0);
|
@ -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: >
|
||||||
|
Iterator is not closed when the "resolve" capability returns an abrupt
|
||||||
|
completion.
|
||||||
|
info: |
|
||||||
|
Let C be the this value.
|
||||||
|
Let promiseCapability be ? NewPromiseCapability(C).
|
||||||
|
Let iteratorRecord be GetIterator(iterable).
|
||||||
|
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
|
||||||
|
Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
|
||||||
|
If result is an abrupt completion, then
|
||||||
|
If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
|
||||||
|
IfAbruptRejectPromise(result, promiseCapability).
|
||||||
|
Return Completion(result).
|
||||||
|
|
||||||
|
features: [Promise.any, Symbol.iterator]
|
||||||
|
---*/
|
||||||
|
let nextCount = 0;
|
||||||
|
let returnCount = 0;
|
||||||
|
let iter = {};
|
||||||
|
iter[Symbol.iterator] = function() {
|
||||||
|
return {
|
||||||
|
next() {
|
||||||
|
nextCount += 1;
|
||||||
|
return {
|
||||||
|
done: true
|
||||||
|
};
|
||||||
|
},
|
||||||
|
return() {
|
||||||
|
returnCount += 1;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
let P = function(executor) {
|
||||||
|
return new Promise(function(_, reject) {
|
||||||
|
executor(function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}, reject);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
P.resolve = Promise.resolve;
|
||||||
|
|
||||||
|
Promise.any.call(P, iter);
|
||||||
|
|
||||||
|
assert.sameValue(nextCount, 1);
|
||||||
|
assert.sameValue(returnCount, 0);
|
@ -0,0 +1,42 @@
|
|||||||
|
// 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: >
|
||||||
|
Iterator is not closed when the "resolve" capability returns an abrupt
|
||||||
|
completion.
|
||||||
|
info: |
|
||||||
|
Let C be the this value.
|
||||||
|
Let promiseCapability be ? NewPromiseCapability(C).
|
||||||
|
Let iteratorRecord be GetIterator(iterable).
|
||||||
|
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
|
||||||
|
Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
|
||||||
|
If result is an abrupt completion, then
|
||||||
|
If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
|
||||||
|
IfAbruptRejectPromise(result, promiseCapability).
|
||||||
|
Return Completion(result).
|
||||||
|
|
||||||
|
features: [Promise.any, Symbol.iterator]
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
let thrown = new Test262Error();
|
||||||
|
let P = function(executor) {
|
||||||
|
return new Promise((_, reject) => {
|
||||||
|
executor(() => {
|
||||||
|
throw thrown;
|
||||||
|
}, reject);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
P.resolve = Promise.resolve;
|
||||||
|
|
||||||
|
Promise.any.call(P, [1])
|
||||||
|
.then(() => {
|
||||||
|
$DONE('Promise incorrectly fulfilled.');
|
||||||
|
}, (error) => {
|
||||||
|
// The error was not the result of promise
|
||||||
|
// resolution, so will not be an AggregateError
|
||||||
|
assert.sameValue(thrown, error);
|
||||||
|
$DONE();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -21,27 +21,3 @@ assert.sameValue(typeof Promise.any, 'function');
|
|||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
Promise.any.call(eval);
|
Promise.any.call(eval);
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
Promise.any.call(undefined, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
Promise.any.call(null, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
Promise.any.call(86, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
Promise.any.call('string', []);
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
Promise.any.call(true, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
Promise.any.call(Symbol(), []);
|
|
||||||
});
|
|
||||||
|
41
test/built-ins/Promise/any/ctx-non-object.js
Normal file
41
test/built-ins/Promise/any/ctx-non-object.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Promise.any invoked on a non-object value
|
||||||
|
esid: sec-promise.any
|
||||||
|
info: |
|
||||||
|
...
|
||||||
|
2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||||
|
|
||||||
|
NewPromiseCapability ( C )
|
||||||
|
|
||||||
|
1. If IsConstructor(C) is false, throw a TypeError exception.
|
||||||
|
|
||||||
|
features: [Promise.any, Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.any.call(undefined, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.any.call(null, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.any.call(86, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.any.call('string', []);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.any.call(true, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.any.call(Symbol(), []);
|
||||||
|
});
|
@ -1,28 +0,0 @@
|
|||||||
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
description: >
|
|
||||||
If the constructor's `resolve` method is not callable, reject with a TypeError.
|
|
||||||
esid: sec-promise.any
|
|
||||||
info: |
|
|
||||||
5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
|
|
||||||
|
|
||||||
Runtime Semantics: PerformPromiseAny
|
|
||||||
|
|
||||||
6. Let promiseResolve be ? Get(constructor, "resolve").
|
|
||||||
7. If ! IsCallable(promiseResolve) is false, throw a TypeError exception.
|
|
||||||
|
|
||||||
flags: [async]
|
|
||||||
features: [Promise.any, arrow-function]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
Promise.resolve = null;
|
|
||||||
|
|
||||||
Promise.any([1])
|
|
||||||
.then(
|
|
||||||
() => $DONE('The promise should not be resolved.'),
|
|
||||||
error => {
|
|
||||||
assert(error instanceof TypeError);
|
|
||||||
}
|
|
||||||
).then($DONE, $DONE);
|
|
43
test/built-ins/Promise/any/invoke-resolve-return.js
Normal file
43
test/built-ins/Promise/any/invoke-resolve-return.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: Use of the value returned by the constructor's `resolve` method.
|
||||||
|
esid: sec-promise.any
|
||||||
|
info: |
|
||||||
|
Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
|
||||||
|
|
||||||
|
PerformPromiseAny
|
||||||
|
|
||||||
|
Repeat
|
||||||
|
...
|
||||||
|
i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
|
||||||
|
...
|
||||||
|
r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
|
||||||
|
|
||||||
|
features: [Promise.any]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let originalCallCount = 0;
|
||||||
|
let newCallCount = 0;
|
||||||
|
let P = function(executor) {
|
||||||
|
executor(function() {}, function() {});
|
||||||
|
};
|
||||||
|
P.resolve = function() {
|
||||||
|
return newThenable;
|
||||||
|
};
|
||||||
|
|
||||||
|
let originalThenable = {
|
||||||
|
then() {
|
||||||
|
originalCallCount += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let newThenable = {
|
||||||
|
then() {
|
||||||
|
newCallCount += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Promise.any.call(P, [originalThenable]);
|
||||||
|
|
||||||
|
assert.sameValue(originalCallCount, 0, 'original `then` method not invoked');
|
||||||
|
assert.sameValue(newCallCount, 1, 'new `then` method invoked exactly once');
|
@ -21,6 +21,7 @@ features: [Promise.any, arrow-function]
|
|||||||
|
|
||||||
let promise = Promise.resolve();
|
let promise = Promise.resolve();
|
||||||
let boundThen = promise.then.bind(promise);
|
let boundThen = promise.then.bind(promise);
|
||||||
|
let callCount = 0;
|
||||||
|
|
||||||
promise.then = function(resolver, rejectElement) {
|
promise.then = function(resolver, rejectElement) {
|
||||||
assert.sameValue(this, promise);
|
assert.sameValue(this, promise);
|
||||||
@ -28,7 +29,11 @@ promise.then = function(resolver, rejectElement) {
|
|||||||
assert.sameValue(resolver.length, 1, 'resolver.length is 1');
|
assert.sameValue(resolver.length, 1, 'resolver.length is 1');
|
||||||
assert.sameValue(typeof rejectElement, 'function');
|
assert.sameValue(typeof rejectElement, 'function');
|
||||||
assert.sameValue(rejectElement.length, 1, 'rejectElement.length is 0');
|
assert.sameValue(rejectElement.length, 1, 'rejectElement.length is 0');
|
||||||
|
callCount++;
|
||||||
return boundThen(resolver, rejectElement);
|
return boundThen(resolver, rejectElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
Promise.any([promise]).then(() => $DONE(), $DONE);
|
Promise.any([promise]).then(() => {
|
||||||
|
assert.sameValue(callCount, 1);
|
||||||
|
$DONE();
|
||||||
|
}, $DONE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user