From 715964b16b7433f71bf1445046d82a7498ddfe77 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 16:21:10 +0300 Subject: [PATCH 01/29] Add Capability Executor tests --- .../any/capability-executor-called-twice.js | 106 +++++++++++++++++ .../any/capability-executor-not-callable.js | 107 ++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 test/built-ins/Promise/any/capability-executor-called-twice.js create mode 100644 test/built-ins/Promise/any/capability-executor-not-callable.js diff --git a/test/built-ins/Promise/any/capability-executor-called-twice.js b/test/built-ins/Promise/any/capability-executor-called-twice.js new file mode 100644 index 0000000000..c40485f222 --- /dev/null +++ b/test/built-ins/Promise/any/capability-executor-called-twice.js @@ -0,0 +1,106 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Throws a TypeError if capabilities executor already called with non-undefined values. +info: | + Promise.any ( iterable ) + + ... + 2. Let promiseCapability be ? NewPromiseCapability(C). + ... + + GetCapabilitiesExecutor Functions + + ... + 4. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception. + 5. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception. + 6. Set promiseCapability.[[Resolve]] to resolve. + 7. Set promiseCapability.[[Reject]] to reject. + ... +features: [Promise.any] +---*/ + +var checkPoint = ''; +function fn1(executor) { + checkPoint += 'a'; + executor(); + checkPoint += 'b'; + executor(function() {}, function() {}); + checkPoint += 'c'; +} +fn1.resolve = function() { + throw new Test262Error(); +}; +Promise.any.call(fn1, []); +assert.sameValue(checkPoint, 'abc', 'executor initially called with no arguments'); + +checkPoint = ''; +function fn2(executor) { + checkPoint += 'a'; + executor(undefined, undefined); + checkPoint += 'b'; + executor(function() {}, function() {}); + checkPoint += 'c'; +} +fn2.resolve = function() { + throw new Test262Error(); +}; +Promise.any.call(fn2, []); +assert.sameValue(checkPoint, 'abc', 'executor initially called with (undefined, undefined)'); + +checkPoint = ''; +function fn3(executor) { + checkPoint += 'a'; + executor(undefined, function() {}); + checkPoint += 'b'; + executor(function() {}, function() {}); + checkPoint += 'c'; +} +Object.defineProperty(fn3, 'resolve', { + get() { + throw new Test262Error(); + } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn3, []); +}, 'executor initially called with (undefined, function)'); +assert.sameValue(checkPoint, 'ab', 'executor initially called with (undefined, function)'); + +checkPoint = ''; +function fn4(executor) { + checkPoint += 'a'; + executor(function() {}, undefined); + checkPoint += 'b'; + executor(function() {}, function() {}); + checkPoint += 'c'; +} +Object.defineProperty(fn4, 'resolve', { + get() { + throw new Test262Error(); + } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn4, []); +}, 'executor initially called with (function, undefined)'); +assert.sameValue(checkPoint, 'ab', 'executor initially called with (function, undefined)'); + +checkPoint = ''; +function fn5(executor) { + checkPoint += 'a'; + executor('invalid value', 123); + checkPoint += 'b'; + executor(function() {}, function() {}); + checkPoint += 'c'; +} +Object.defineProperty(fn5, 'resolve', { + get() { + throw new Test262Error(); + } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn5, []); +}, 'executor initially called with (String, Number)'); +assert.sameValue(checkPoint, 'ab', 'executor initially called with (String, Number)'); diff --git a/test/built-ins/Promise/any/capability-executor-not-callable.js b/test/built-ins/Promise/any/capability-executor-not-callable.js new file mode 100644 index 0000000000..c8be9cd252 --- /dev/null +++ b/test/built-ins/Promise/any/capability-executor-not-callable.js @@ -0,0 +1,107 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Throws a TypeError if either resolve or reject capability is not callable. +info: | + Promise.any ( iterable ) + + ... + 2. Let promiseCapability be ? NewPromiseCapability(C). + ... + + NewPromiseCapability ( C ) + + ... + 5. Let executor be ! CreateBuiltinFunction(steps, « [[Capability]] »). + 6. Set executor.[[Capability]] to promiseCapability. + 7. Let promise be ? Construct(C, « executor »). + 8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception. + 9. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception. + ... +features: [Promise.any] +---*/ + +var checkPoint = ''; +function fn1(executor) { + checkPoint += 'a'; +} +Object.defineProperty(fn1, 'resolve', { + get() { throw new Test262Error(); } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn1, []); +}, 'executor not called at all'); +assert.sameValue(checkPoint, 'a', 'executor not called at all'); + +checkPoint = ''; +function fn2(executor) { + checkPoint += 'a'; + executor(); + checkPoint += 'b'; +} +Object.defineProperty(fn2, 'resolve', { + get() { throw new Test262Error(); } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn2, []); +}, 'executor called with no arguments'); +assert.sameValue(checkPoint, 'ab', 'executor called with no arguments'); + +checkPoint = ''; +function fn3(executor) { + checkPoint += 'a'; + executor(undefined, undefined); + checkPoint += 'b'; +} +Object.defineProperty(fn3, 'resolve', { + get() { throw new Test262Error(); } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn3, []); +}, 'executor called with (undefined, undefined)'); +assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, undefined)'); + +checkPoint = ''; +function fn4(executor) { + checkPoint += 'a'; + executor(undefined, function() {}); + checkPoint += 'b'; +} +Object.defineProperty(fn4, 'resolve', { + get() { throw new Test262Error(); } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn4, []); +}, 'executor called with (undefined, function)'); +assert.sameValue(checkPoint, 'ab', 'executor called with (undefined, function)'); + +checkPoint = ''; +function fn5(executor) { + checkPoint += 'a'; + executor(function() {}, undefined); + checkPoint += 'b'; +} +Object.defineProperty(fn5, 'resolve', { + get() { throw new Test262Error(); } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn5, []); +}, 'executor called with (function, undefined)'); +assert.sameValue(checkPoint, 'ab', 'executor called with (function, undefined)'); + +checkPoint = ''; +function fn6(executor) { + checkPoint += 'a'; + executor(123, 'invalid value'); + checkPoint += 'b'; +} +Object.defineProperty(fn6, 'resolve', { + get() { throw new Test262Error(); } +}); +assert.throws(TypeError, function() { + Promise.any.call(fn6, []); +}, 'executor called with (Number, String)'); +assert.sameValue(checkPoint, 'ab', 'executor called with (Number, String)'); From aca10842a2b02184e1f88a899882c1d9389c42a8 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 16:36:09 +0300 Subject: [PATCH 02/29] Add context tests --- test/built-ins/Promise/any/ctx-ctor-throws.js | 24 +++++++++++++ test/built-ins/Promise/any/ctx-ctor.js | 34 ++++++++++++++++++ test/built-ins/Promise/any/ctx-non-ctor.js | 20 +++++++++++ test/built-ins/Promise/any/ctx-non-object.js | 36 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 test/built-ins/Promise/any/ctx-ctor-throws.js create mode 100644 test/built-ins/Promise/any/ctx-ctor.js create mode 100644 test/built-ins/Promise/any/ctx-non-ctor.js create mode 100644 test/built-ins/Promise/any/ctx-non-object.js diff --git a/test/built-ins/Promise/any/ctx-ctor-throws.js b/test/built-ins/Promise/any/ctx-ctor-throws.js new file mode 100644 index 0000000000..b3e567acb5 --- /dev/null +++ b/test/built-ins/Promise/any/ctx-ctor-throws.js @@ -0,0 +1,24 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any invoked on a constructor value that throws an error +esid: sec-promise.any +info: | + 2. Let promiseCapability be ? NewPromiseCapability(C). + + NewPromiseCapability + + ... + 7. Let promise be ? Construct(C, « executor »). +features: [Promise.any] +---*/ + +var CustomPromise = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + Promise.any.call(CustomPromise); +}); diff --git a/test/built-ins/Promise/any/ctx-ctor.js b/test/built-ins/Promise/any/ctx-ctor.js new file mode 100644 index 0000000000..e9b9461656 --- /dev/null +++ b/test/built-ins/Promise/any/ctx-ctor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any invoked on a constructor value +esid: sec-promise.any +info: | + 2. Let promiseCapability be ? NewPromiseCapability(C). + ... + 5. Let result be PerformPromiseany(iteratorRecord, C, promiseCapability). + ... + 7. Return Completion(result). +features: [Promise.any, class] +---*/ + +var executor = null; +var callCount = 0; + +class SubPromise extends Promise { + constructor(a) { + super(a); + executor = a; + callCount += 1; + } +} + +var instance = Promise.any.call(SubPromise, []); + +assert.sameValue(instance.constructor, SubPromise); +assert.sameValue(instance instanceof SubPromise, true); + +assert.sameValue(callCount, 1); +assert.sameValue(typeof executor, 'function'); diff --git a/test/built-ins/Promise/any/ctx-non-ctor.js b/test/built-ins/Promise/any/ctx-non-ctor.js new file mode 100644 index 0000000000..f9de14efcd --- /dev/null +++ b/test/built-ins/Promise/any/ctx-non-ctor.js @@ -0,0 +1,20 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any invoked on a non-constructor 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] +---*/ + +assert.throws(TypeError, function() { + Promise.any.call(eval); +}); diff --git a/test/built-ins/Promise/any/ctx-non-object.js b/test/built-ins/Promise/any/ctx-non-object.js new file mode 100644 index 0000000000..1031e25728 --- /dev/null +++ b/test/built-ins/Promise/any/ctx-non-object.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Sergey Rubanov. 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: | + 1. Let C be the this value. + 2. If Type(C) is not Object, 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(), []); +}); From f0fd4e0d4d2b6b32153a1e7cf14599ffdac3b390 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 16:37:42 +0300 Subject: [PATCH 03/29] update features.txt - --- features.txt | 4 ++++ test/built-ins/Promise/any/ctx-ctor.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/features.txt b/features.txt index 764e39746b..4e000ec8b9 100644 --- a/features.txt +++ b/features.txt @@ -7,6 +7,10 @@ # # https://github.com/tc39/process-document +# Promise.any +# https://github.com/tc39/proposal-promise-any +Promise.any + # Missing checks in Proxy internal methods # https://github.com/tc39/ecma262/pull/666 proxy-missing-checks diff --git a/test/built-ins/Promise/any/ctx-ctor.js b/test/built-ins/Promise/any/ctx-ctor.js index e9b9461656..7600458ebc 100644 --- a/test/built-ins/Promise/any/ctx-ctor.js +++ b/test/built-ins/Promise/any/ctx-ctor.js @@ -8,7 +8,7 @@ esid: sec-promise.any info: | 2. Let promiseCapability be ? NewPromiseCapability(C). ... - 5. Let result be PerformPromiseany(iteratorRecord, C, promiseCapability). + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). ... 7. Return Completion(result). features: [Promise.any, class] From 23d7f0b79d516c09aefe4ca70054e5e847a6de89 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 17:00:26 +0300 Subject: [PATCH 04/29] add Invocation of the constructor's `resolve` method test --- test/built-ins/Promise/any/invoke-resolve.js | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/built-ins/Promise/any/invoke-resolve.js diff --git a/test/built-ins/Promise/any/invoke-resolve.js b/test/built-ins/Promise/any/invoke-resolve.js new file mode 100644 index 0000000000..860dde810b --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Invocation of the constructor's `resolve` method +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 6. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + ... + z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »). +features: [Promise.any] +---*/ + +var p1 = new Promise(function() {}); +var p2 = new Promise(function() {}); +var p3 = new Promise(function() {}); +var resolve = Promise.resolve; +var callCount = 0; +var current = p1; +var next = p2; +var afterNext = p3; + +Promise.resolve = function(nextValue) { + assert.sameValue( + nextValue, current, '`resolve` invoked with next iterated value' + ); + assert.sameValue( + arguments.length, 1, '`resolve` invoked with a single argument' + ); + assert.sameValue(this, Promise, '`this` value is the constructor'); + + current = next; + next = afterNext; + afterNext = null; + + callCount += 1; + + return resolve.apply(Promise, arguments); +}; + +Promise.any([p1, p2, p3]); + +assert.sameValue( + callCount, 3, '`resolve` invoked once for each iterated value' +); From be1bf6391e9b150dcb4e3d3353357cfc67a80f83 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 17:10:37 +0300 Subject: [PATCH 05/29] Add Promise and Promise.any properties tests --- test/built-ins/Promise/any/length.js | 28 ++++++++++++++++++++++++ test/built-ins/Promise/any/name.js | 29 +++++++++++++++++++++++++ test/built-ins/Promise/any/prop-desc.js | 21 ++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 test/built-ins/Promise/any/length.js create mode 100644 test/built-ins/Promise/any/name.js create mode 100644 test/built-ins/Promise/any/prop-desc.js diff --git a/test/built-ins/Promise/any/length.js b/test/built-ins/Promise/any/length.js new file mode 100644 index 0000000000..d043a88ede --- /dev/null +++ b/test/built-ins/Promise/any/length.js @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: Promise.any `length` property +info: | + ES Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Promise.any] +---*/ + +verifyProperty(Promise.any, 'length', { + configurable: true, + writable: false, + enumerable: false, + value: 1, +}); diff --git a/test/built-ins/Promise/any/name.js b/test/built-ins/Promise/any/name.js new file mode 100644 index 0000000000..91a0664eae --- /dev/null +++ b/test/built-ins/Promise/any/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: Promise.any `name` property +info: | + ES Section 17: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + + [...] + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Promise.any] +---*/ + +verifyProperty(Promise.any, 'name', { + configurable: true, + writable: false, + enumerable: false, + value: 'any', +}); diff --git a/test/built-ins/Promise/any/prop-desc.js b/test/built-ins/Promise/any/prop-desc.js new file mode 100644 index 0000000000..d6676a40bc --- /dev/null +++ b/test/built-ins/Promise/any/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: Promise.any property descriptor +info: | + ES Section 17 + + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Promise.any] +---*/ + +verifyProperty(Promise, 'any', { + configurable: true, + writable: true, + enumerable: false, +}); From 88d058b59e34de11a77bd0bb2e7a52e6ecd4db5e Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 17:12:50 +0300 Subject: [PATCH 06/29] Add returns promise test --- test/built-ins/Promise/any/returns-promise.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/built-ins/Promise/any/returns-promise.js diff --git a/test/built-ins/Promise/any/returns-promise.js b/test/built-ins/Promise/any/returns-promise.js new file mode 100644 index 0000000000..745696fec6 --- /dev/null +++ b/test/built-ins/Promise/any/returns-promise.js @@ -0,0 +1,24 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: Promise.any returns a Promise +info: | + Promise.any ( iterable ) + + 2. Let promiseCapability be ? NewPromiseCapability(C). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + 7. Return Completion(result). +features: [Promise.any] +---*/ + +var p = Promise.any([]); + +assert(p instanceof Promise); +assert.sameValue(Object.getPrototypeOf(p), Promise.prototype); From adcd162c10e2e60465c20a859d7b69ec1f01837f Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 17:17:42 +0300 Subject: [PATCH 07/29] add is callable test --- test/built-ins/Promise/any/is-function.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/built-ins/Promise/any/is-function.js diff --git a/test/built-ins/Promise/any/is-function.js b/test/built-ins/Promise/any/is-function.js new file mode 100644 index 0000000000..a55b7c7cdf --- /dev/null +++ b/test/built-ins/Promise/any/is-function.js @@ -0,0 +1,10 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: Promise.any is callable +features: [Promise.any] +---*/ + +assert.sameValue(typeof Promise.any, 'function'); From afe3f0bb50828e759933627fe57d85fb26499dca Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 17:30:12 +0300 Subject: [PATCH 08/29] add reject-immed test --- test/built-ins/Promise/any/reject-immed.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/built-ins/Promise/any/reject-immed.js diff --git a/test/built-ins/Promise/any/reject-immed.js b/test/built-ins/Promise/any/reject-immed.js new file mode 100644 index 0000000000..18636e5e6e --- /dev/null +++ b/test/built-ins/Promise/any/reject-immed.js @@ -0,0 +1,15 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Promise.any([]) rejects immediately +esid: sec-promise.any +flags: [async] +includes: [promiseHelper.js] +features: [Promise.any] +---*/ + +Promise.any([]) + .then(function() { + $DONE('The promise should not be fulfilled.'); + }, $DONE); From e3d48f244af7045671f0144ea076c8d7cc741bb3 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 23:58:14 +0300 Subject: [PATCH 09/29] add Invocation of the instance's `then` method test --- test/built-ins/Promise/any/invoke-then.js | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/built-ins/Promise/any/invoke-then.js diff --git a/test/built-ins/Promise/any/invoke-then.js b/test/built-ins/Promise/any/invoke-then.js new file mode 100644 index 0000000000..57329e5691 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-then.js @@ -0,0 +1,53 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Invocation of the instance's `then` method +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). +features: [Promise.any] +---*/ + +var p1 = new Promise(function() {}); +var p2 = new Promise(function() {}); +var p3 = new Promise(function() {}); +var callCount = 0; +var currentThis = p1; +var nextThis = p2; +var afterNextThis = p3; + +p1.then = p2.then = p3.then = function(a, b) { + assert.sameValue(typeof a, 'function', 'type of first argument'); + assert.sameValue( + a.length, + 1, + 'The length property of a promise resolve function is 1.' + ); + assert.sameValue(typeof b, 'function', 'type of second argument'); + assert.sameValue( + b.length, + 1, + 'The length property of a promise reject function is 1.' + ); + assert.sameValue(arguments.length, 2, '`then` invoked with two arguments'); + assert.sameValue(this, currentThis, '`this` value'); + + currentThis = nextThis; + nextThis = afterNextThis; + afterNextThis = null; + + callCount += 1; +}; + +Promise.any([p1, p2, p3]); + +assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); From 094ddc7f75edf01db1410f2c711140c6f06e2d79 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Thu, 28 Nov 2019 00:04:46 +0300 Subject: [PATCH 10/29] add species-get-error test --- .../Promise/any/species-get-error.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/built-ins/Promise/any/species-get-error.js diff --git a/test/built-ins/Promise/any/species-get-error.js b/test/built-ins/Promise/any/species-get-error.js new file mode 100644 index 0000000000..1957172c48 --- /dev/null +++ b/test/built-ins/Promise/any/species-get-error.js @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any() does not retrieve `Symbol.species` property of the `this` value +esid: sec-promise.any +info: | + 1. Let C be the this value. + 2. If Type(C) is not Object, throw a TypeError exception. + 3. Let promiseCapability be ? NewPromiseCapability(C). + ... +features: [Promise.any, Symbol.species] +---*/ + +function C(executor) { + executor(function() {}, function() {}); +} +Object.defineProperty(C, Symbol.species, { + get() { + throw new Test262Error('Getter for Symbol.species called'); + } +}); + +C.resolve = function() { + throw new Test262Error(); +}; + +Promise.any.call(C, []); From 9567abd85aaf9a4c7687e2931a725fc7c47b8269 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Thu, 28 Nov 2019 00:07:46 +0300 Subject: [PATCH 11/29] Add iter-arg tests --- .../Promise/any/iter-arg-is-false-reject.js | 36 ++++++++++++++ .../Promise/any/iter-arg-is-null-reject.js | 36 ++++++++++++++ .../Promise/any/iter-arg-is-number-reject.js | 36 ++++++++++++++ .../Promise/any/iter-arg-is-poisoned.js | 42 ++++++++++++++++ .../Promise/any/iter-arg-is-string-resolve.js | 35 +++++++++++++ .../Promise/any/iter-arg-is-symbol-reject.js | 49 +++++++++++++++++++ .../Promise/any/iter-arg-is-true-reject.js | 49 +++++++++++++++++++ .../any/iter-arg-is-undefined-reject.js | 49 +++++++++++++++++++ 8 files changed, 332 insertions(+) create mode 100644 test/built-ins/Promise/any/iter-arg-is-false-reject.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-null-reject.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-number-reject.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-poisoned.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-string-resolve.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-symbol-reject.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-true-reject.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-undefined-reject.js diff --git a/test/built-ins/Promise/any/iter-arg-is-false-reject.js b/test/built-ins/Promise/any/iter-arg-is-false-reject.js new file mode 100644 index 0000000000..5ba6712ddc --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-false-reject.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument is `false` +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + #sec-getiterator + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + Let iterator be ? Call(method, obj). + If Type(iterator) is not Object, throw a TypeError exception. + ... +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any(false).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-arg-is-null-reject.js b/test/built-ins/Promise/any/iter-arg-is-null-reject.js new file mode 100644 index 0000000000..a2ee093b21 --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-null-reject.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument is `null` +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + #sec-getiterator + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + Let iterator be ? Call(method, obj). + If Type(iterator) is not Object, throw a TypeError exception. + ... +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any(null).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-arg-is-number-reject.js b/test/built-ins/Promise/any/iter-arg-is-number-reject.js new file mode 100644 index 0000000000..0d648ed139 --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-number-reject.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument is a number +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + #sec-getiterator + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + Let iterator be ? Call(method, obj). + If Type(iterator) is not Object, throw a TypeError exception. + ... +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any(1).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-arg-is-poisoned.js b/test/built-ins/Promise/any/iter-arg-is-poisoned.js new file mode 100644 index 0000000000..ad003f0955 --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-poisoned.js @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject with abrupt completion from GetIterator +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + #sec-getiterator + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + Let iterator be ? Call(method, obj). + ... +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +var poison = []; +var error = new Test262Error(); +Object.defineProperty(poison, Symbol.iterator, { + get() { + throw error; + } +}); + +try { + Promise.any(poison).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(err) { + assert.sameValue(err, error); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js new file mode 100644 index 0000000000..b7bfc2bb37 --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js @@ -0,0 +1,35 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Resolve when argument is a string +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + #sec-getiterator + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + Let iterator be ? Call(method, obj). + If Type(iterator) is not Object, throw a TypeError exception. + ... +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any('').then(function(v) { + assert.sameValue(v.length, 0); + }, function() { + $DONE('The promise should be resolved, but was rejected'); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be resolved, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js b/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js new file mode 100644 index 0000000000..c391f51f57 --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument is a symbol +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any(Symbol()).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-arg-is-true-reject.js b/test/built-ins/Promise/any/iter-arg-is-true-reject.js new file mode 100644 index 0000000000..58dc0024f6 --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-true-reject.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument is `true` +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any(true).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js b/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js new file mode 100644 index 0000000000..f044a8885c --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument is `undefined` +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any(undefined).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} From 860e02ad28cfb9c7d51b03a1a687be80054498e7 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Thu, 28 Nov 2019 00:09:33 +0300 Subject: [PATCH 12/29] add iter-assigned tests --- .../Promise/any/iter-assigned-false-reject.js | 53 +++++++++++++++++++ .../Promise/any/iter-assigned-null-reject.js | 51 ++++++++++++++++++ .../any/iter-assigned-number-reject.js | 51 ++++++++++++++++++ .../any/iter-assigned-string-reject.js | 51 ++++++++++++++++++ .../any/iter-assigned-symbol-reject.js | 51 ++++++++++++++++++ .../Promise/any/iter-assigned-true-reject.js | 51 ++++++++++++++++++ .../any/iter-assigned-undefined-reject.js | 51 ++++++++++++++++++ 7 files changed, 359 insertions(+) create mode 100644 test/built-ins/Promise/any/iter-assigned-false-reject.js create mode 100644 test/built-ins/Promise/any/iter-assigned-null-reject.js create mode 100644 test/built-ins/Promise/any/iter-assigned-number-reject.js create mode 100644 test/built-ins/Promise/any/iter-assigned-string-reject.js create mode 100644 test/built-ins/Promise/any/iter-assigned-symbol-reject.js create mode 100644 test/built-ins/Promise/any/iter-assigned-true-reject.js create mode 100644 test/built-ins/Promise/any/iter-assigned-undefined-reject.js diff --git a/test/built-ins/Promise/any/iter-assigned-false-reject.js b/test/built-ins/Promise/any/iter-assigned-false-reject.js new file mode 100644 index 0000000000..8d10761861 --- /dev/null +++ b/test/built-ins/Promise/any/iter-assigned-false-reject.js @@ -0,0 +1,53 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument's Symbol.iterator property has the value false +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + i. Set method to ? GetMethod(obj, @@asyncIterator). + ii. If method is undefined, then + 1. Let syncMethod be ? GetMethod(obj, @@iterator). + 2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod). + ... + 4. Let iterator be ? Call(method, obj). + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any({ + [Symbol.iterator]: false + }).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-assigned-null-reject.js b/test/built-ins/Promise/any/iter-assigned-null-reject.js new file mode 100644 index 0000000000..b5edb10abc --- /dev/null +++ b/test/built-ins/Promise/any/iter-assigned-null-reject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument's Symbol.iterator property has the value null +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any({ + [Symbol.iterator]: null + }).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-assigned-number-reject.js b/test/built-ins/Promise/any/iter-assigned-number-reject.js new file mode 100644 index 0000000000..0b2884d17a --- /dev/null +++ b/test/built-ins/Promise/any/iter-assigned-number-reject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument's Symbol.iterator property has the value 1 +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any({ + [Symbol.iterator]: 1 + }).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-assigned-string-reject.js b/test/built-ins/Promise/any/iter-assigned-string-reject.js new file mode 100644 index 0000000000..b8a4c9f860 --- /dev/null +++ b/test/built-ins/Promise/any/iter-assigned-string-reject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument's Symbol.iterator property has the value "" +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any({ + [Symbol.iterator]: '' + }).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-assigned-symbol-reject.js b/test/built-ins/Promise/any/iter-assigned-symbol-reject.js new file mode 100644 index 0000000000..1d306b9d83 --- /dev/null +++ b/test/built-ins/Promise/any/iter-assigned-symbol-reject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument's Symbol.iterator property has the value Symbol() +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any({ + [Symbol.iterator]: Symbol() + }).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-assigned-true-reject.js b/test/built-ins/Promise/any/iter-assigned-true-reject.js new file mode 100644 index 0000000000..8300051c36 --- /dev/null +++ b/test/built-ins/Promise/any/iter-assigned-true-reject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument's Symbol.iterator property has the value true +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any({ + [Symbol.iterator]: true + }).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} diff --git a/test/built-ins/Promise/any/iter-assigned-undefined-reject.js b/test/built-ins/Promise/any/iter-assigned-undefined-reject.js new file mode 100644 index 0000000000..668ef26a78 --- /dev/null +++ b/test/built-ins/Promise/any/iter-assigned-undefined-reject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Reject when argument's Symbol.iterator property has the value undefined +info: | + Promise.any ( iterable ) + + ... + 4. Let iteratorRecord be GetIterator(iterable). + 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + ... + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + ... + + GetMethod + + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + + Call ( F, V [ , argumentsList ] ) + + 2. If IsCallable(F) is false, throw a TypeError exception. +features: [Promise.any, Symbol.iterator] +flags: [async] +---*/ + +try { + Promise.any({ + [Symbol.iterator]: undefined + }).then(function() { + $DONE('The promise should be rejected, but was resolved'); + }, function(error) { + assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype); + assert(error instanceof TypeError); + }).then($DONE, $DONE); +} catch (error) { + $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); +} From e0abeaa4dfdfd7b6c0c0c45b376845be0fbc1fed Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Thu, 12 Mar 2020 11:03:07 -0400 Subject: [PATCH 13/29] Promise.any: convert sync test to async test to ensure run to completion --- test/built-ins/Promise/any/invoke-then.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/built-ins/Promise/any/invoke-then.js b/test/built-ins/Promise/any/invoke-then.js index 57329e5691..95a630b11b 100644 --- a/test/built-ins/Promise/any/invoke-then.js +++ b/test/built-ins/Promise/any/invoke-then.js @@ -14,6 +14,8 @@ info: | Runtime Semantics: PerformPromiseAny r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] features: [Promise.any] ---*/ @@ -48,6 +50,8 @@ p1.then = p2.then = p3.then = function(a, b) { callCount += 1; }; -Promise.any([p1, p2, p3]); - -assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); +Promise.any([p1, p2, p3]) + .then(function() { + assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); + $DONE(); + }, $DONE); From 55b22d8d9f02ce51965d8f66dab68dd0b7e826dc Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Thu, 12 Mar 2020 12:55:58 -0400 Subject: [PATCH 14/29] Promise.any: string iterable should not be rejected (adds error message for clarity) --- test/built-ins/Promise/any/iter-arg-is-string-resolve.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js index b7bfc2bb37..60bfe98837 100644 --- a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js +++ b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js @@ -27,8 +27,8 @@ flags: [async] try { Promise.any('').then(function(v) { assert.sameValue(v.length, 0); - }, function() { - $DONE('The promise should be resolved, but was rejected'); + }, function(error) { + $DONE(`The promise should be resolved, but was rejected with error: ${error.message}`); }).then($DONE, $DONE); } catch (error) { $DONE(`The promise should be resolved, but threw an exception: ${error.message}`); From 47b3858978dc7f9a2c9e113fc24cef28fc8074d1 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 16 Mar 2020 12:08:25 -0400 Subject: [PATCH 15/29] Promise.any: expected rejection shouldn't end with error message. --- test/built-ins/Promise/any/reject-immed.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/built-ins/Promise/any/reject-immed.js b/test/built-ins/Promise/any/reject-immed.js index 18636e5e6e..81863b2bec 100644 --- a/test/built-ins/Promise/any/reject-immed.js +++ b/test/built-ins/Promise/any/reject-immed.js @@ -10,6 +10,7 @@ features: [Promise.any] ---*/ Promise.any([]) - .then(function() { - $DONE('The promise should not be fulfilled.'); - }, $DONE); + .then( + () => $DONE('The promise should be rejected, but was resolved'), + () => $DONE() + ); From 272e9abed486c32020c0e5d97c119576455d11ad Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 16 Mar 2020 12:11:22 -0400 Subject: [PATCH 16/29] Promise.any: make async operation test actually async --- test/built-ins/Promise/any/invoke-resolve.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/built-ins/Promise/any/invoke-resolve.js b/test/built-ins/Promise/any/invoke-resolve.js index 860dde810b..99daf2054f 100644 --- a/test/built-ins/Promise/any/invoke-resolve.js +++ b/test/built-ins/Promise/any/invoke-resolve.js @@ -15,6 +15,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). ... z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »). +flags: [async] features: [Promise.any] ---*/ @@ -45,8 +46,10 @@ Promise.resolve = function(nextValue) { return resolve.apply(Promise, arguments); }; -Promise.any([p1, p2, p3]); - -assert.sameValue( - callCount, 3, '`resolve` invoked once for each iterated value' -); +Promise.any([p1, p2, p3]) + .then(function() { + assert.sameValue( + callCount, 3, '`resolve` invoked once for each iterated value' + ); + $DONE(); + }, $DONE); From e0f0c7860b928fb1b82f6ead238229e79e028ae4 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 16 Mar 2020 15:21:06 -0400 Subject: [PATCH 17/29] Promise.any: empty iterable rejects with AggregateError --- .../any/{reject-immed.js => empty-iterable-rejects.js} | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) rename test/built-ins/Promise/any/{reject-immed.js => empty-iterable-rejects.js} (67%) diff --git a/test/built-ins/Promise/any/reject-immed.js b/test/built-ins/Promise/any/empty-iterable-rejects.js similarity index 67% rename from test/built-ins/Promise/any/reject-immed.js rename to test/built-ins/Promise/any/empty-iterable-rejects.js index 81863b2bec..9d0d92ac41 100644 --- a/test/built-ins/Promise/any/reject-immed.js +++ b/test/built-ins/Promise/any/empty-iterable-rejects.js @@ -6,11 +6,15 @@ description: Promise.any([]) rejects immediately esid: sec-promise.any flags: [async] includes: [promiseHelper.js] -features: [Promise.any] +features: [AggregateError, Promise.any] ---*/ Promise.any([]) .then( () => $DONE('The promise should be rejected, but was resolved'), - () => $DONE() + error => { + assert(error instanceof AggregateError); + assert.sameValue(error.errors.length, 0); + $DONE() + } ); From 6edaba378ed542e14c8d67269cc6dc85aba1cb09 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 18 Mar 2020 14:21:32 -0400 Subject: [PATCH 18/29] Promise.any: updates, corrections and new tests. --- test/built-ins/Promise/any/ctx-ctor-throws.js | 1 + test/built-ins/Promise/any/ctx-non-ctor.js | 25 ++++++++ test/built-ins/Promise/any/ctx-non-object.js | 36 ----------- .../does-not-perform-species-get-of-custom.js | 32 ++++++++++ ...does-not-perform-species-get-of-promise.js | 29 +++++++++ .../Promise/any/empty-iterable-rejects.js | 20 ------- ...olve-not-callable-rejects-with-typerror.js | 28 +++++++++ ...e-on-promises-every-iteration-of-custom.js | 50 ++++++++++++++++ ...-on-promises-every-iteration-of-promise.js | 41 +++++++++++++ ...lve-on-values-every-iteration-of-custom.js | 46 ++++++++++++++ ...ve-on-values-every-iteration-of-promise.js | 37 ++++++++++++ test/built-ins/Promise/any/invoke-resolve.js | 40 +++---------- ...invoke-then-on-promises-every-iteration.js | 45 ++++++++++++++ test/built-ins/Promise/any/invoke-then.js | 43 ++++--------- .../any/iter-arg-is-empty-iterable-reject.js | 39 ++++++++++++ .../any/iter-arg-is-empty-string-reject.js | 39 ++++++++++++ .../Promise/any/iter-arg-is-false-reject.js | 6 +- .../Promise/any/iter-arg-is-null-reject.js | 6 +- .../Promise/any/iter-arg-is-number-reject.js | 6 +- .../Promise/any/iter-arg-is-poisoned.js | 16 ++--- .../Promise/any/iter-arg-is-string-resolve.js | 13 ++-- .../Promise/any/iter-arg-is-symbol-reject.js | 6 +- .../Promise/any/iter-arg-is-true-reject.js | 6 +- .../any/iter-arg-is-undefined-reject.js | 6 +- .../Promise/any/iter-step-err-no-close.js | 60 +++++++++++++++++++ .../Promise/any/iter-step-err-reject.js | 56 +++++++++++++++++ .../Promise/any/new-reject-function.js | 51 ++++++++++++++++ .../built-ins/Promise/any/reject-all-mixed.js | 26 ++++++++ test/built-ins/Promise/any/reject-deferred.js | 31 ++++++++++ .../any/reject-element-function-extensible.js | 29 +++++++++ .../any/reject-element-function-length.js | 40 +++++++++++++ .../any/reject-element-function-name.js | 39 ++++++++++++ .../reject-element-function-nonconstructor.js | 33 ++++++++++ .../any/reject-element-function-prototype.js | 31 ++++++++++ ...resolve-ignores-late-rejection-deferred.js | 41 +++++++++++++ .../any/resolve-ignores-late-rejection.js | 37 ++++++++++++ .../Promise/any/resolve-one-mixed.js | 22 +++++++ .../Promise/any/species-get-error.js | 29 --------- 38 files changed, 959 insertions(+), 182 deletions(-) delete mode 100644 test/built-ins/Promise/any/ctx-non-object.js create mode 100644 test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js create mode 100644 test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js delete mode 100644 test/built-ins/Promise/any/empty-iterable-rejects.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js create mode 100644 test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js create mode 100644 test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js create mode 100644 test/built-ins/Promise/any/iter-step-err-no-close.js create mode 100644 test/built-ins/Promise/any/iter-step-err-reject.js create mode 100644 test/built-ins/Promise/any/new-reject-function.js create mode 100644 test/built-ins/Promise/any/reject-all-mixed.js create mode 100644 test/built-ins/Promise/any/reject-deferred.js create mode 100644 test/built-ins/Promise/any/reject-element-function-extensible.js create mode 100644 test/built-ins/Promise/any/reject-element-function-length.js create mode 100644 test/built-ins/Promise/any/reject-element-function-name.js create mode 100644 test/built-ins/Promise/any/reject-element-function-nonconstructor.js create mode 100644 test/built-ins/Promise/any/reject-element-function-prototype.js create mode 100644 test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js create mode 100644 test/built-ins/Promise/any/resolve-ignores-late-rejection.js create mode 100644 test/built-ins/Promise/any/resolve-one-mixed.js delete mode 100644 test/built-ins/Promise/any/species-get-error.js diff --git a/test/built-ins/Promise/any/ctx-ctor-throws.js b/test/built-ins/Promise/any/ctx-ctor-throws.js index b3e567acb5..a6e0d07868 100644 --- a/test/built-ins/Promise/any/ctx-ctor-throws.js +++ b/test/built-ins/Promise/any/ctx-ctor-throws.js @@ -12,6 +12,7 @@ info: | ... 7. Let promise be ? Construct(C, « executor »). + features: [Promise.any] ---*/ diff --git a/test/built-ins/Promise/any/ctx-non-ctor.js b/test/built-ins/Promise/any/ctx-non-ctor.js index f9de14efcd..6703d9eae6 100644 --- a/test/built-ins/Promise/any/ctx-non-ctor.js +++ b/test/built-ins/Promise/any/ctx-non-ctor.js @@ -12,9 +12,34 @@ info: | NewPromiseCapability ( C ) 1. If IsConstructor(C) is false, throw a TypeError exception. + features: [Promise.any] ---*/ assert.throws(TypeError, function() { 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(), []); +}); diff --git a/test/built-ins/Promise/any/ctx-non-object.js b/test/built-ins/Promise/any/ctx-non-object.js deleted file mode 100644 index 1031e25728..0000000000 --- a/test/built-ins/Promise/any/ctx-non-object.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2019 Sergey Rubanov. 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: | - 1. Let C be the this value. - 2. If Type(C) is not Object, 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(), []); -}); diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js new file mode 100644 index 0000000000..42f85f6b70 --- /dev/null +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js @@ -0,0 +1,32 @@ +// 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: > + Promise.any() does not retrieve `Symbol.species` property of the "`this` value" +info: | + 1. Let C be the this value. + 2. Let promiseCapability be ? NewPromiseCapability(C). + ... + + NewPromiseCapability ( C ) + + 1. If IsConstructor(C) is false, throw a TypeError exception. + 2. NOTE: C is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see 25.6.3.1). + ... + +flags: [async] +features: [Promise.any, Symbol.species] +---*/ + +class C extends Promise { + static get [Symbol.species]() { + throw new Test262Error('Getter for Symbol.species called'); + } + static resolve() { + throw new Test262Error('C.resolve was reached'); + } +} + +Promise.any.call(C, [1]).then(() => $DONE(), $DONE); diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js new file mode 100644 index 0000000000..7e1597cd1d --- /dev/null +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js @@ -0,0 +1,29 @@ +// 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: > + Promise.any() does not retrieve `Symbol.species` property of the "`this` value". +info: | + 1. Let C be the this value. + 2. Let promiseCapability be ? NewPromiseCapability(C). + ... + + NewPromiseCapability ( C ) + + 1. If IsConstructor(C) is false, throw a TypeError exception. + 2. NOTE: C is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see 25.6.3.1). + ... + +flags: [async] +features: [Promise.any, Symbol.species] +---*/ + +Object.defineProperty(Promise, Symbol.species, { + get() { + throw new Test262Error('Getter for Symbol.species called'); + } +}); + +Promise.any([1]).then(() => $DONE(), $DONE); diff --git a/test/built-ins/Promise/any/empty-iterable-rejects.js b/test/built-ins/Promise/any/empty-iterable-rejects.js deleted file mode 100644 index 9d0d92ac41..0000000000 --- a/test/built-ins/Promise/any/empty-iterable-rejects.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2019 Sergey Rubanov. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Promise.any([]) rejects immediately -esid: sec-promise.any -flags: [async] -includes: [promiseHelper.js] -features: [AggregateError, Promise.any] ----*/ - -Promise.any([]) - .then( - () => $DONE('The promise should be rejected, but was resolved'), - error => { - assert(error instanceof AggregateError); - assert.sameValue(error.errors.length, 0); - $DONE() - } - ); diff --git a/test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js b/test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js new file mode 100644 index 0000000000..798812ce1b --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js @@ -0,0 +1,28 @@ +// 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] +---*/ + +Promise.resolve = null; + +Promise.any([1]) + .then( + () => $DONE('The promise should not be resolved.'), + error => { + assert(error instanceof TypeError); + } + ).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js new file mode 100644 index 0000000000..226039ff42 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Invocation of the constructor's `resolve` method for iterable with promise values +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ +class Custom extends Promise {} + +let customs = [ + new Custom(resolve => resolve()), + new Custom(resolve => resolve()), + new Custom(resolve => resolve()), +]; +let cresolveCallCount = 0; +let presolveCallCount = 0; +let boundCustomResolve = Custom.resolve.bind(Custom); +let boundPromiseResolve = Promise.resolve.bind(Promise); + +Custom.resolve = function(...args) { + cresolveCallCount += 1; + return boundCustomResolve(...args); +}; + +Promise.resolve = function(...args) { + presolveCallCount += 1; + return boundPromiseResolve(...args); +}; + +Promise.any.call(Custom, customs) + .then(() => { + assert.sameValue(presolveCallCount, 0, '`Promise.resolve` is never invoked'); + assert.sameValue(cresolveCallCount, 3, '`Custom.resolve` invoked once for every iterated promise'); + }, (error) => { + $DONE(error); + } + ).then($DONE, $DONE); + diff --git a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js new file mode 100644 index 0000000000..4e90baa691 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Invocation of the constructor's `resolve` method for iterable with promise values +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ + +let promises = [ + new Promise(resolve => resolve()), + new Promise(resolve => resolve()), + new Promise(resolve => resolve()), +]; +let callCount = 0; +let boundPromiseResolve = Promise.resolve.bind(Promise); + +Promise.resolve = function(...args) { + callCount += 1; + return boundPromiseResolve(...args); +}; + +Promise.any(promises) + .then(() => { + assert.sameValue(callCount, 3, '`then` invoked once for every iterated promise'); + }, (error) => { + $DONE(error); + } + ).then($DONE, $DONE); + diff --git a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js new file mode 100644 index 0000000000..9b03b8a019 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Invocation of the constructor's `resolve` method for iterable with non-promise values +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ +class Custom extends Promise {} + +let values = [1, 2, 3]; +let cresolveCallCount = 0; +let presolveCallCount = 0; +let boundCustomResolve = Custom.resolve.bind(Custom); +let boundPromiseResolve = Promise.resolve.bind(Promise); + +Custom.resolve = function(...args) { + cresolveCallCount += 1; + return boundCustomResolve(...args); +}; + +Promise.resolve = function(...args) { + presolveCallCount += 1; + return boundPromiseResolve(...args); +}; + +Promise.any.call(Custom, values) + .then(() => { + assert.sameValue(presolveCallCount, 0, '`Promise.resolve` is never invoked'); + assert.sameValue(cresolveCallCount, 3, '`Custom.resolve` invoked once for every iterated promise'); + }, (error) => { + $DONE(error); + } + ).then($DONE, $DONE); + diff --git a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js new file mode 100644 index 0000000000..2b5629045d --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js @@ -0,0 +1,37 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Invocation of the constructor's `resolve` method for iterable with non-promise values +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ + +let values = [1, 2, 3]; +let callCount = 0; +let boundPromiseResolve = Promise.resolve.bind(Promise); + +Promise.resolve = function(...args) { + callCount += 1; + return boundPromiseResolve(...args); +}; + +Promise.any(values) + .then(() => { + assert.sameValue(callCount, 3, '`Promise.resolve` invoked once for every iterated value'); + }, (error) => { + $DONE(error); + } + ).then($DONE, $DONE); + diff --git a/test/built-ins/Promise/any/invoke-resolve.js b/test/built-ins/Promise/any/invoke-resolve.js index 99daf2054f..60119c33a4 100644 --- a/test/built-ins/Promise/any/invoke-resolve.js +++ b/test/built-ins/Promise/any/invoke-resolve.js @@ -10,46 +10,22 @@ info: | Runtime Semantics: PerformPromiseAny - 6. Repeat + 8. Repeat ... i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). ... - z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »). + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + flags: [async] features: [Promise.any] ---*/ -var p1 = new Promise(function() {}); -var p2 = new Promise(function() {}); -var p3 = new Promise(function() {}); -var resolve = Promise.resolve; -var callCount = 0; -var current = p1; -var next = p2; -var afterNext = p3; +let boundPromiseResolve = Promise.resolve.bind(Promise); -Promise.resolve = function(nextValue) { - assert.sameValue( - nextValue, current, '`resolve` invoked with next iterated value' - ); - assert.sameValue( - arguments.length, 1, '`resolve` invoked with a single argument' - ); +Promise.resolve = function(...args) { + assert.sameValue(args.length, 1, '`resolve` invoked with a single argument'); assert.sameValue(this, Promise, '`this` value is the constructor'); - - current = next; - next = afterNext; - afterNext = null; - - callCount += 1; - - return resolve.apply(Promise, arguments); + return boundPromiseResolve(...args); }; -Promise.any([p1, p2, p3]) - .then(function() { - assert.sameValue( - callCount, 3, '`resolve` invoked once for each iterated value' - ); - $DONE(); - }, $DONE); +Promise.any([1]).then(() => $DONE(), $DONE); diff --git a/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js b/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js new file mode 100644 index 0000000000..accb7c75be --- /dev/null +++ b/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Invocation of the instance's `then` method +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] +features: [Promise.any] +---*/ + +let promises = [ + new Promise(resolve => resolve()), + new Promise(resolve => resolve()), + new Promise(resolve => resolve()), +]; +let callCount = 0; + +promises.forEach(promise => { + let boundThen = promise.then.bind(promise); + promise.then = function(...args) { + assert.sameValue(this, promises[callCount]); + callCount += 1; + return boundThen(...args); + }; +}); + +Promise.any(promises) + .then(() => { + assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); + }, (error) => { + $DONE(error); + // $DONE('The promise should not be rejected'); + } + ).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-then.js b/test/built-ins/Promise/any/invoke-then.js index 95a630b11b..3de9219962 100644 --- a/test/built-ins/Promise/any/invoke-then.js +++ b/test/built-ins/Promise/any/invoke-then.js @@ -19,39 +19,16 @@ flags: [async] features: [Promise.any] ---*/ -var p1 = new Promise(function() {}); -var p2 = new Promise(function() {}); -var p3 = new Promise(function() {}); -var callCount = 0; -var currentThis = p1; -var nextThis = p2; -var afterNextThis = p3; +let promise = new Promise(() => {}); +let boundThen = promise.then.bind(promise); -p1.then = p2.then = p3.then = function(a, b) { - assert.sameValue(typeof a, 'function', 'type of first argument'); - assert.sameValue( - a.length, - 1, - 'The length property of a promise resolve function is 1.' - ); - assert.sameValue(typeof b, 'function', 'type of second argument'); - assert.sameValue( - b.length, - 1, - 'The length property of a promise reject function is 1.' - ); - assert.sameValue(arguments.length, 2, '`then` invoked with two arguments'); - assert.sameValue(this, currentThis, '`this` value'); - - currentThis = nextThis; - nextThis = afterNextThis; - afterNextThis = null; - - callCount += 1; +promise.then = function(resolver, rejectElement) { + assert.sameValue(this, promise); + assert.sameValue(typeof resolver, 'function'); + assert.sameValue(resolver.length, 1, 'resolver.length is 1'); + assert.sameValue(typeof rejectElement, 'function'); + assert.sameValue(rejectElement.length, 1, 'rejectElement.length is 0'); + return boundThen(resolver, rejectElement); }; -Promise.any([p1, p2, p3]) - .then(function() { - assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); - $DONE(); - }, $DONE); +Promise.any([promise]).then(() => $DONE(), $DONE); diff --git a/test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js b/test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js new file mode 100644 index 0000000000..42edfcec92 --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js @@ -0,0 +1,39 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Promise.any([]) rejects with AggregateError, empty errors array. +info: | + Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability ) + + ... + 3. Let errors be a new empty List. + ... + 8. Repeat, + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, then + i. Set iteratorRecord.[[Done]] to true. + ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. + iii. If remainingElementsCount.[[Value]] is 0, then + 1. Let error be a newly created AggregateError object. + 2. Set error.[[AggregateErrors]] to errors. + 3. Return ThrowCompletion(error). + ... + +flags: [async] +features: [AggregateError, Promise.any] +---*/ + +Promise.any([]) + .then( + () => $DONE('The promise should be rejected, but was resolved'), + error => { + assert.sameValue(Object.getPrototypeOf(error), AggregateError.prototype); + assert(error instanceof AggregateError); + assert.sameValue(error.errors.length, 0); + } + ).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js b/test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js new file mode 100644 index 0000000000..7f780fa95c --- /dev/null +++ b/test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js @@ -0,0 +1,39 @@ +// 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: > + Promise.any('') rejects with AggregateError, empty errors array. +info: | + Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability ) + + ... + 3. Let errors be a new empty List. + ... + 8. Repeat, + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, then + i. Set iteratorRecord.[[Done]] to true. + ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. + iii. If remainingElementsCount.[[Value]] is 0, then + 1. Let error be a newly created AggregateError object. + 2. Set error.[[AggregateErrors]] to errors. + 3. Return ThrowCompletion(error). + ... + +features: [AggregateError, Promise.any] +flags: [async] +---*/ + +Promise.any('') + .then( + () => $DONE('The promise should be rejected, but was resolved'), + error => { + assert.sameValue(Object.getPrototypeOf(error), AggregateError.prototype); + assert(error instanceof AggregateError); + assert.sameValue(error.errors.length, 0); + } + ).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/iter-arg-is-false-reject.js b/test/built-ins/Promise/any/iter-arg-is-false-reject.js index 5ba6712ddc..a78cc40a17 100644 --- a/test/built-ins/Promise/any/iter-arg-is-false-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-false-reject.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Reject when argument is `false` + Promise.any(false) rejects with TypeError. info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... #sec-getiterator diff --git a/test/built-ins/Promise/any/iter-arg-is-null-reject.js b/test/built-ins/Promise/any/iter-arg-is-null-reject.js index a2ee093b21..89ffd99e49 100644 --- a/test/built-ins/Promise/any/iter-arg-is-null-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-null-reject.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Reject when argument is `null` + Promise.any(null) rejects with TypeError. info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... #sec-getiterator diff --git a/test/built-ins/Promise/any/iter-arg-is-number-reject.js b/test/built-ins/Promise/any/iter-arg-is-number-reject.js index 0d648ed139..866b364ea8 100644 --- a/test/built-ins/Promise/any/iter-arg-is-number-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-number-reject.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Reject when argument is a number + Promise.any(number) rejects with TypeError. info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... #sec-getiterator diff --git a/test/built-ins/Promise/any/iter-arg-is-poisoned.js b/test/built-ins/Promise/any/iter-arg-is-poisoned.js index ad003f0955..230de97bf4 100644 --- a/test/built-ins/Promise/any/iter-arg-is-poisoned.js +++ b/test/built-ins/Promise/any/iter-arg-is-poisoned.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Reject with abrupt completion from GetIterator + Promise.any(poisoned iterable) rejects with whatever error is thrown. info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... #sec-getiterator @@ -24,18 +24,18 @@ flags: [async] ---*/ var poison = []; -var error = new Test262Error(); Object.defineProperty(poison, Symbol.iterator, { get() { - throw error; + throw new Test262Error(); } }); try { - Promise.any(poison).then(function() { + Promise.any(poison).then(() => { $DONE('The promise should be rejected, but was resolved'); - }, function(err) { - assert.sameValue(err, error); + }, (error) => { + assert.sameValue(Object.getPrototypeOf(error), Test262Error.prototype); + assert(error instanceof Test262Error); }).then($DONE, $DONE); } catch (error) { $DONE(`The promise should be rejected, but threw an exception: ${error.message}`); diff --git a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js index 60bfe98837..4c8ccf62c0 100644 --- a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js +++ b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Resolve when argument is a string + Promise.any('non-empty-string') resolves with the first character in the non-empty string info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... #sec-getiterator @@ -25,9 +25,10 @@ flags: [async] ---*/ try { - Promise.any('').then(function(v) { - assert.sameValue(v.length, 0); - }, function(error) { + Promise.any('xyz').then(v => { + assert.sameValue(v, 'x'); + assert.sameValue(v.length, 1); + }, error => { $DONE(`The promise should be resolved, but was rejected with error: ${error.message}`); }).then($DONE, $DONE); } catch (error) { diff --git a/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js b/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js index c391f51f57..afd082f926 100644 --- a/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Reject when argument is a symbol + Promise.any(Symbol()) rejects with TypeError. info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... GetIterator ( obj [ , hint [ , method ] ] ) diff --git a/test/built-ins/Promise/any/iter-arg-is-true-reject.js b/test/built-ins/Promise/any/iter-arg-is-true-reject.js index 58dc0024f6..6c996ed4d6 100644 --- a/test/built-ins/Promise/any/iter-arg-is-true-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-true-reject.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Reject when argument is `true` + Promise.any(true) rejects with TypeError. info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... GetIterator ( obj [ , hint [ , method ] ] ) diff --git a/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js b/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js index f044a8885c..06b526b42c 100644 --- a/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js @@ -4,13 +4,13 @@ /*--- esid: sec-promise.any description: > - Reject when argument is `undefined` + Promise.any(undefined) rejects with TypeError. info: | Promise.any ( iterable ) ... - 4. Let iteratorRecord be GetIterator(iterable). - 5. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + 3. Let iteratorRecord be GetIterator(iterable). + 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability). ... GetIterator ( obj [ , hint [ , method ] ] ) diff --git a/test/built-ins/Promise/any/iter-step-err-no-close.js b/test/built-ins/Promise/any/iter-step-err-no-close.js new file mode 100644 index 0000000000..686d07e724 --- /dev/null +++ b/test/built-ins/Promise/any/iter-step-err-no-close.js @@ -0,0 +1,60 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Error when advancing the provided iterable (not closing iterator) +info: | + Promise.any ( iterable ) + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ + +let returnCount = 0; +let poisonedDone = {}; +let error = new Test262Error(); +Object.defineProperties(poisonedDone, { + done: { + get() { + throw error; + } + }, + value: { + get() {} + } +}); +let iterStepThrows = { + [Symbol.iterator]() { + return { + next() { + return poisonedDone; + }, + return() { + returnCount += 1; + return {}; + } + }; + } +}; + +Promise.any(iterStepThrows).then( + () => { + $DONE('The promise should be rejected.'); +}, (reason) => { + assert.sameValue(reason, error); + assert.sameValue(returnCount, 0); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/iter-step-err-reject.js b/test/built-ins/Promise/any/iter-step-err-reject.js new file mode 100644 index 0000000000..3cea43a434 --- /dev/null +++ b/test/built-ins/Promise/any/iter-step-err-reject.js @@ -0,0 +1,56 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Error when advancing the provided iterable (rejecting promise) +info: | + Promise.any ( iterable ) + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ + +let poisonedDone = {}; +let error = new Test262Error(); +Object.defineProperties(poisonedDone, { + done: { + get() { + throw error; + } + }, + value: { + get() { + $DONE('The `value` property should not be accessed.'); + } + } +}); +let iterStepThrows = { + [Symbol.iterator]() { + return { + next() { + return poisonedDone; + } + }; + } +}; + +Promise.any(iterStepThrows).then( + () => { + $DONE('The promise should be rejected.'); +}, (reason) => { + assert.sameValue(reason, error); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/new-reject-function.js b/test/built-ins/Promise/any/new-reject-function.js new file mode 100644 index 0000000000..b73cc82882 --- /dev/null +++ b/test/built-ins/Promise/any/new-reject-function.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-performpromiseany +description: > + Each Promise.any element is called with a new Promise.any Reject Element function. +info: | + Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability ) + + ... + k. Let rejectElement be ! CreateBuiltinFunction(steps, « [[AlreadyCalled]], [[Index]], [[Errors]], [[Capability]], [[RemainingElements]] »). + ... + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + ... + +features: [Promise.any] +---*/ + +function rejectFunction() {} + +function Constructor(executor) { + executor(rejectFunction, $ERROR); +} +Constructor.resolve = function(v) { + return v; +}; + +var callCount1 = 0; +var callCount2 = 0; +var p1OnRejected; + +var p1 = { + then(_, onRejected) { + callCount1 += 1; + p1OnRejected = onRejected; + assert.notSameValue(onRejected, rejectFunction, 'p1.then'); + } +}; +var p2 = { + then(_, onRejected) { + callCount2 += 1; + assert.notSameValue(onRejected, rejectFunction, 'p2.then'); + assert.notSameValue(onRejected, p1OnRejected, 'p1.onRejected != p2.onRejected'); + } +}; + +Promise.any.call(Constructor, [p1, p2]); +assert.sameValue(callCount1, 1, 'p1.then call count'); +assert.sameValue(callCount2, 1, 'p2.then call count'); + diff --git a/test/built-ins/Promise/any/reject-all-mixed.js b/test/built-ins/Promise/any/reject-all-mixed.js new file mode 100644 index 0000000000..a4531e885f --- /dev/null +++ b/test/built-ins/Promise/any/reject-all-mixed.js @@ -0,0 +1,26 @@ +// 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: > + Promise.any rejection reasons from various rejections are all present +flags: [async] +features: [Promise.any] +---*/ + +let rejections = [ + Promise.reject('a'), + new Promise((_, reject) => reject('b')), + Promise.all([Promise.reject('c')]), + Promise.resolve(Promise.reject('d')), +]; + +Promise.any(rejections) + .then( + () => $DONE('The promise should be rejected, but was resolved'), + error => { + assert.sameValue(error.errors.length, rejections.length); + assert.sameValue(error.errors.join(''), 'abcd'); + } + ).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/reject-deferred.js b/test/built-ins/Promise/any/reject-deferred.js new file mode 100644 index 0000000000..3382a6d2d8 --- /dev/null +++ b/test/built-ins/Promise/any/reject-deferred.js @@ -0,0 +1,31 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-promise.any +description: Rejecting through deferred invocation of the provided resolving function +info: | + ... + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + ... + + +flags: [async] +features: [AggregateError, Promise.any] +---*/ + +var rejection = {}; +var thenable = { + then(_, reject) { + new Promise((resolve) => resolve()) + .then(() => reject(rejection)); + } +}; + +Promise.any([thenable]) + .then(() => { + $DONE('The promise should be rejected.'); + }, (aggregate) => { + assert(aggregate instanceof AggregateError); + assert.sameValue(aggregate.errors.length, 1); + assert.sameValue(aggregate.errors[0], rejection); + }).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/reject-element-function-extensible.js b/test/built-ins/Promise/any/reject-element-function-extensible.js new file mode 100644 index 0000000000..030bc36835 --- /dev/null +++ b/test/built-ins/Promise/any/reject-element-function-extensible.js @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Leo Balter, 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: The [[Extensible]] slot of Promise.any Reject Element functions +info: | + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +features: [Promise.any] +---*/ + +var rejectElementFunction; +var thenable = { + then(_, reject) { + rejectElementFunction = reject; + } +}; + +function NotPromise(executor) { + executor(function() {}, function() {}); +} +NotPromise.resolve = function(v) { + return v; +}; +Promise.any.call(NotPromise, [thenable]); + +assert(Object.isExtensible(rejectElementFunction)); diff --git a/test/built-ins/Promise/any/reject-element-function-length.js b/test/built-ins/Promise/any/reject-element-function-length.js new file mode 100644 index 0000000000..15437ff73c --- /dev/null +++ b/test/built-ins/Promise/any/reject-element-function-length.js @@ -0,0 +1,40 @@ +// Copyright (C) 2019 Leo Balter, 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: The `length` property of Promise.any Reject Element functions +info: | + The length property of a Promise.any Reject Element function is 1. + + 17 ECMAScript Standard Built-in Objects: + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Promise.any] +---*/ + +var rejectElementFunction; +var thenable = { + then(_, reject) { + rejectElementFunction = reject; + } +}; + +function NotPromise(executor) { + executor(function() {}, function() {}); +} +NotPromise.resolve = function(v) { + return v; +}; +Promise.any.call(NotPromise, [thenable]); + +assert.sameValue(rejectElementFunction.length, 1); + +verifyProperty(rejectElementFunction, 'length', { + value: 1, + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/built-ins/Promise/any/reject-element-function-name.js b/test/built-ins/Promise/any/reject-element-function-name.js new file mode 100644 index 0000000000..9487836134 --- /dev/null +++ b/test/built-ins/Promise/any/reject-element-function-name.js @@ -0,0 +1,39 @@ +// Copyright (C) 2019 Leo Balter, 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: The `name` property of Promise.any Reject Element functions +info: | + A promise resolve function is an anonymous built-in function. + + 17 ECMAScript Standard Built-in Objects: + Every built-in function object, including constructors, has a `name` + property whose value is a String. Functions that are identified as + anonymous functions use the empty string as the value of the `name` + property. + Unless otherwise specified, the `name` property of a built-in function + object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, + [[Configurable]]: *true* }. +includes: [propertyHelper.js] +features: [Promise.any] +---*/ + +var rejectElementFunction; +var thenable = { + then(_, reject) { + rejectElementFunction = reject; + } +}; + +function NotPromise(executor) { + executor(function() {}, function() {}); +} +NotPromise.resolve = function(v) { + return v; +}; +Promise.any.call(NotPromise, [thenable]); + +verifyProperty(rejectElementFunction, "name", { + value: "", writable: false, enumerable: false, configurable: true +}); diff --git a/test/built-ins/Promise/any/reject-element-function-nonconstructor.js b/test/built-ins/Promise/any/reject-element-function-nonconstructor.js new file mode 100644 index 0000000000..687e96c8bb --- /dev/null +++ b/test/built-ins/Promise/any/reject-element-function-nonconstructor.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter, 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: Promise.any Reject Element functions are not constructors +info: | + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +features: [Promise.any] +---*/ + +var rejectElementFunction; +var thenable = { + then(_, reject) { + rejectElementFunction = reject; + } +}; + +function NotPromise(executor) { + executor(function() {}, function() {}); +} +NotPromise.resolve = function(v) { + return v; +}; +Promise.any.call(NotPromise, [thenable]); + +assert.sameValue(Object.prototype.hasOwnProperty.call(rejectElementFunction, 'prototype'), false); +assert.throws(TypeError, function() { + new rejectElementFunction(); +}); diff --git a/test/built-ins/Promise/any/reject-element-function-prototype.js b/test/built-ins/Promise/any/reject-element-function-prototype.js new file mode 100644 index 0000000000..b2e1369be6 --- /dev/null +++ b/test/built-ins/Promise/any/reject-element-function-prototype.js @@ -0,0 +1,31 @@ +// Copyright (C) 2019 Leo Balter, 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: The [[Prototype]] of Promise.any Reject Element functions +info: | + 17 ECMAScript Standard Built-in Objects: + Unless otherwise specified every built-in function and every built-in + constructor has the Function prototype object, which is the initial + value of the expression Function.prototype (19.2.3), as the value of + its [[Prototype]] internal slot. +features: [Promise.any] +---*/ + +var rejectElementFunction; +var thenable = { + then(_, reject) { + rejectElementFunction = reject; + } +}; + +function NotPromise(executor) { + executor(function() {}, function() {}); +} +NotPromise.resolve = function(v) { + return v; +}; +Promise.any.call(NotPromise, [thenable]); + +assert.sameValue(Object.getPrototypeOf(rejectElementFunction), Function.prototype); diff --git a/test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js b/test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js new file mode 100644 index 0000000000..2d83ff3137 --- /dev/null +++ b/test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. 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 +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] +features: [Promise.any] +---*/ + +var resolver = { + then(resolve) { + new Promise((resolve) => resolve()) + .then(() => resolve(42)); + } +}; +var lateRejector = { + then(resolve, reject) { + new Promise((resolve) => resolve()) + .then(() => { + resolve(9); + reject(); + }); + } +}; + +Promise.any([resolver, lateRejector]) + .then(resolution => { + assert.sameValue(resolution, 42); + }).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/resolve-ignores-late-rejection.js b/test/built-ins/Promise/any/resolve-ignores-late-rejection.js new file mode 100644 index 0000000000..64955007af --- /dev/null +++ b/test/built-ins/Promise/any/resolve-ignores-late-rejection.js @@ -0,0 +1,37 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. 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 +esid: sec-promise.any +info: | + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] +features: [Promise.any] +---*/ + +var resolver = { + then(resolve) { + resolve(42); + } +}; +var lateRejector = { + then(resolve, reject) { + resolve(33); + reject(); + } +}; + +Promise.any([resolver, lateRejector]) + .then(resolution => { + assert.sameValue(resolution, 42); + }).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/resolve-one-mixed.js b/test/built-ins/Promise/any/resolve-one-mixed.js new file mode 100644 index 0000000000..b33ea0b31c --- /dev/null +++ b/test/built-ins/Promise/any/resolve-one-mixed.js @@ -0,0 +1,22 @@ +// 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: > + Promise.any resolves with the first item that does not reject. +flags: [async] +features: [Promise.any] +---*/ + +let fulfillables = [ + Promise.reject('a'), + new Promise((resolve, reject) => reject('b')), + Promise.all([Promise.reject('c')]), + Promise.resolve(Promise.reject('d').catch(v => v)), +]; + +Promise.any(fulfillables) + .then((resolution) => { + assert.sameValue(resolution, 'd'); + }).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/species-get-error.js b/test/built-ins/Promise/any/species-get-error.js deleted file mode 100644 index 1957172c48..0000000000 --- a/test/built-ins/Promise/any/species-get-error.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2019 Sergey Rubanov. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Promise.any() does not retrieve `Symbol.species` property of the `this` value -esid: sec-promise.any -info: | - 1. Let C be the this value. - 2. If Type(C) is not Object, throw a TypeError exception. - 3. Let promiseCapability be ? NewPromiseCapability(C). - ... -features: [Promise.any, Symbol.species] ----*/ - -function C(executor) { - executor(function() {}, function() {}); -} -Object.defineProperty(C, Symbol.species, { - get() { - throw new Test262Error('Getter for Symbol.species called'); - } -}); - -C.resolve = function() { - throw new Test262Error(); -}; - -Promise.any.call(C, []); From f70e3e3cf16ab65ff3328f0a81b5ac720343b718 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 20 Mar 2020 11:55:41 -0400 Subject: [PATCH 19/29] Features: remove duplicate "Promise.any" --- features.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/features.txt b/features.txt index 4e000ec8b9..764e39746b 100644 --- a/features.txt +++ b/features.txt @@ -7,10 +7,6 @@ # # https://github.com/tc39/process-document -# Promise.any -# https://github.com/tc39/proposal-promise-any -Promise.any - # Missing checks in Proxy internal methods # https://github.com/tc39/ecma262/pull/666 proxy-missing-checks From 5d3eafc5475ade29fc98f68f745f6f05dcf467f0 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 23 Mar 2020 22:39:53 -0400 Subject: [PATCH 20/29] Promise.any: review fixes --- test/built-ins/Promise/any/ctx-ctor-throws.js | 4 ++-- test/built-ins/Promise/any/ctx-non-ctor.js | 4 +++- ...resolve-on-promises-every-iteration-of-custom.js | 13 +++---------- ...esolve-on-promises-every-iteration-of-promise.js | 13 +++---------- ...e-resolve-on-values-every-iteration-of-custom.js | 5 +---- ...-resolve-on-values-every-iteration-of-promise.js | 5 +---- .../any/invoke-then-on-promises-every-iteration.js | 12 ++++-------- .../Promise/any/iter-arg-is-false-reject.js | 2 +- .../Promise/any/iter-arg-is-null-reject.js | 2 +- .../Promise/any/iter-arg-is-number-reject.js | 2 +- test/built-ins/Promise/any/iter-arg-is-poisoned.js | 2 +- .../Promise/any/iter-arg-is-string-resolve.js | 2 +- .../Promise/any/iter-arg-is-symbol-reject.js | 2 +- .../Promise/any/iter-arg-is-true-reject.js | 2 +- .../Promise/any/iter-arg-is-undefined-reject.js | 2 +- .../Promise/any/iter-assigned-symbol-reject.js | 2 +- 16 files changed, 26 insertions(+), 48 deletions(-) diff --git a/test/built-ins/Promise/any/ctx-ctor-throws.js b/test/built-ins/Promise/any/ctx-ctor-throws.js index a6e0d07868..41288914fa 100644 --- a/test/built-ins/Promise/any/ctx-ctor-throws.js +++ b/test/built-ins/Promise/any/ctx-ctor-throws.js @@ -16,9 +16,9 @@ info: | features: [Promise.any] ---*/ -var CustomPromise = function() { +function CustomPromise() { throw new Test262Error(); -}; +} assert.throws(Test262Error, function() { Promise.any.call(CustomPromise); diff --git a/test/built-ins/Promise/any/ctx-non-ctor.js b/test/built-ins/Promise/any/ctx-non-ctor.js index 6703d9eae6..46cc361240 100644 --- a/test/built-ins/Promise/any/ctx-non-ctor.js +++ b/test/built-ins/Promise/any/ctx-non-ctor.js @@ -13,9 +13,11 @@ info: | 1. If IsConstructor(C) is false, throw a TypeError exception. -features: [Promise.any] +features: [Promise.any, Symbol] ---*/ +assert.sameValue(typeof Promise.any, 'function'); + assert.throws(TypeError, function() { Promise.any.call(eval); }); diff --git a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js index 226039ff42..279e87a1fc 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js @@ -19,11 +19,7 @@ features: [Promise.any] ---*/ class Custom extends Promise {} -let customs = [ - new Custom(resolve => resolve()), - new Custom(resolve => resolve()), - new Custom(resolve => resolve()), -]; +let values = [1, 1, 1]; let cresolveCallCount = 0; let presolveCallCount = 0; let boundCustomResolve = Custom.resolve.bind(Custom); @@ -39,12 +35,9 @@ Promise.resolve = function(...args) { return boundPromiseResolve(...args); }; -Promise.any.call(Custom, customs) +Promise.any.call(Custom, values) .then(() => { assert.sameValue(presolveCallCount, 0, '`Promise.resolve` is never invoked'); assert.sameValue(cresolveCallCount, 3, '`Custom.resolve` invoked once for every iterated promise'); - }, (error) => { - $DONE(error); - } - ).then($DONE, $DONE); + }, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js index 4e90baa691..dd45faff87 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js @@ -18,11 +18,7 @@ flags: [async] features: [Promise.any] ---*/ -let promises = [ - new Promise(resolve => resolve()), - new Promise(resolve => resolve()), - new Promise(resolve => resolve()), -]; +let values = [1,1,1]; let callCount = 0; let boundPromiseResolve = Promise.resolve.bind(Promise); @@ -31,11 +27,8 @@ Promise.resolve = function(...args) { return boundPromiseResolve(...args); }; -Promise.any(promises) +Promise.any(values) .then(() => { assert.sameValue(callCount, 3, '`then` invoked once for every iterated promise'); - }, (error) => { - $DONE(error); - } - ).then($DONE, $DONE); + }, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js index 9b03b8a019..68d4c01bfa 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js @@ -39,8 +39,5 @@ Promise.any.call(Custom, values) .then(() => { assert.sameValue(presolveCallCount, 0, '`Promise.resolve` is never invoked'); assert.sameValue(cresolveCallCount, 3, '`Custom.resolve` invoked once for every iterated promise'); - }, (error) => { - $DONE(error); - } - ).then($DONE, $DONE); + }, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js index 2b5629045d..3b1fbf8a6e 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js @@ -30,8 +30,5 @@ Promise.resolve = function(...args) { Promise.any(values) .then(() => { assert.sameValue(callCount, 3, '`Promise.resolve` invoked once for every iterated value'); - }, (error) => { - $DONE(error); - } - ).then($DONE, $DONE); + }, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js b/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js index accb7c75be..abb34225f3 100644 --- a/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js +++ b/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js @@ -20,9 +20,9 @@ features: [Promise.any] ---*/ let promises = [ - new Promise(resolve => resolve()), - new Promise(resolve => resolve()), - new Promise(resolve => resolve()), + Promise.resolve(), + Promise.resolve(), + Promise.resolve(), ]; let callCount = 0; @@ -38,8 +38,4 @@ promises.forEach(promise => { Promise.any(promises) .then(() => { assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); - }, (error) => { - $DONE(error); - // $DONE('The promise should not be rejected'); - } - ).then($DONE, $DONE); + }, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/iter-arg-is-false-reject.js b/test/built-ins/Promise/any/iter-arg-is-false-reject.js index a78cc40a17..d9ca00e7d3 100644 --- a/test/built-ins/Promise/any/iter-arg-is-false-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-false-reject.js @@ -20,7 +20,7 @@ info: | Let iterator be ? Call(method, obj). If Type(iterator) is not Object, throw a TypeError exception. ... -features: [Promise.any, Symbol.iterator] +features: [Promise.any] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-null-reject.js b/test/built-ins/Promise/any/iter-arg-is-null-reject.js index 89ffd99e49..1fad1fbe66 100644 --- a/test/built-ins/Promise/any/iter-arg-is-null-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-null-reject.js @@ -20,7 +20,7 @@ info: | Let iterator be ? Call(method, obj). If Type(iterator) is not Object, throw a TypeError exception. ... -features: [Promise.any, Symbol.iterator] +features: [Promise.any] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-number-reject.js b/test/built-ins/Promise/any/iter-arg-is-number-reject.js index 866b364ea8..2e09657b8d 100644 --- a/test/built-ins/Promise/any/iter-arg-is-number-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-number-reject.js @@ -20,7 +20,7 @@ info: | Let iterator be ? Call(method, obj). If Type(iterator) is not Object, throw a TypeError exception. ... -features: [Promise.any, Symbol.iterator] +features: [Promise.any] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-poisoned.js b/test/built-ins/Promise/any/iter-arg-is-poisoned.js index 230de97bf4..723e9df9b2 100644 --- a/test/built-ins/Promise/any/iter-arg-is-poisoned.js +++ b/test/built-ins/Promise/any/iter-arg-is-poisoned.js @@ -19,7 +19,7 @@ info: | ... Let iterator be ? Call(method, obj). ... -features: [Promise.any, Symbol.iterator] +features: [Promise.any] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js index 4c8ccf62c0..3abb467361 100644 --- a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js +++ b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js @@ -20,7 +20,7 @@ info: | Let iterator be ? Call(method, obj). If Type(iterator) is not Object, throw a TypeError exception. ... -features: [Promise.any, Symbol.iterator] +features: [Promise.any] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js b/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js index afd082f926..8cc96f153c 100644 --- a/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-symbol-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-true-reject.js b/test/built-ins/Promise/any/iter-arg-is-true-reject.js index 6c996ed4d6..3678db6c49 100644 --- a/test/built-ins/Promise/any/iter-arg-is-true-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-true-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js b/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js index 06b526b42c..8224953f9b 100644 --- a/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-undefined-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-symbol-reject.js b/test/built-ins/Promise/any/iter-assigned-symbol-reject.js index 1d306b9d83..b8caa0eca1 100644 --- a/test/built-ins/Promise/any/iter-assigned-symbol-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-symbol-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol, Symbol.iterator] flags: [async] ---*/ From 1c748507f2ee48a4dc6e0f1fbd4b9b2434c21840 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Tue, 24 Mar 2020 12:10:16 -0400 Subject: [PATCH 21/29] Promise.any: feature flags --- .../Promise/any/does-not-perform-species-get-of-custom.js | 2 +- .../Promise/any/does-not-perform-species-get-of-promise.js | 2 +- .../any/invoke-resolve-not-callable-rejects-with-typerror.js | 2 +- .../any/invoke-resolve-on-promises-every-iteration-of-custom.js | 2 +- .../invoke-resolve-on-promises-every-iteration-of-promise.js | 2 +- .../any/invoke-resolve-on-values-every-iteration-of-custom.js | 2 +- .../any/invoke-resolve-on-values-every-iteration-of-promise.js | 2 +- test/built-ins/Promise/any/invoke-resolve.js | 2 +- .../Promise/any/invoke-then-on-promises-every-iteration.js | 2 +- test/built-ins/Promise/any/invoke-then.js | 2 +- test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js | 2 +- test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js | 2 +- test/built-ins/Promise/any/iter-arg-is-poisoned.js | 2 +- test/built-ins/Promise/any/iter-arg-is-string-resolve.js | 2 +- test/built-ins/Promise/any/iter-assigned-false-reject.js | 2 +- test/built-ins/Promise/any/iter-assigned-null-reject.js | 2 +- test/built-ins/Promise/any/iter-assigned-number-reject.js | 2 +- test/built-ins/Promise/any/iter-assigned-string-reject.js | 2 +- test/built-ins/Promise/any/iter-assigned-symbol-reject.js | 2 +- test/built-ins/Promise/any/iter-assigned-true-reject.js | 2 +- test/built-ins/Promise/any/iter-assigned-undefined-reject.js | 2 +- test/built-ins/Promise/any/iter-step-err-no-close.js | 2 +- test/built-ins/Promise/any/iter-step-err-reject.js | 2 +- test/built-ins/Promise/any/reject-all-mixed.js | 2 +- test/built-ins/Promise/any/reject-deferred.js | 2 +- .../Promise/any/resolve-ignores-late-rejection-deferred.js | 2 +- test/built-ins/Promise/any/resolve-ignores-late-rejection.js | 2 +- test/built-ins/Promise/any/resolve-one-mixed.js | 2 +- 28 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js index 42f85f6b70..2f43a88f28 100644 --- a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js @@ -17,7 +17,7 @@ info: | ... flags: [async] -features: [Promise.any, Symbol.species] +features: [Promise.any, Symbol.species, class, class-static-method, computed-property-names, Symbol, arrow-function] ---*/ class C extends Promise { diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js index 7e1597cd1d..09e0372618 100644 --- a/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js @@ -17,7 +17,7 @@ info: | ... flags: [async] -features: [Promise.any, Symbol.species] +features: [Promise.any, Symbol.species, Symbol, arrow-function] ---*/ Object.defineProperty(Promise, Symbol.species, { diff --git a/test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js b/test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js index 798812ce1b..c5e7e16bde 100644 --- a/test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js +++ b/test/built-ins/Promise/any/invoke-resolve-not-callable-rejects-with-typerror.js @@ -14,7 +14,7 @@ info: | 7. If ! IsCallable(promiseResolve) is false, throw a TypeError exception. flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ Promise.resolve = null; diff --git a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js index 279e87a1fc..57a99d4329 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-custom.js @@ -15,7 +15,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, class, arrow-function] ---*/ class Custom extends Promise {} diff --git a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js index dd45faff87..26d8d3332b 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-promises-every-iteration-of-promise.js @@ -15,7 +15,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let values = [1,1,1]; diff --git a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js index 68d4c01bfa..be6076f074 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js @@ -15,7 +15,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, class, arrow-function] ---*/ class Custom extends Promise {} diff --git a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js index 3b1fbf8a6e..8f36c669d9 100644 --- a/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js +++ b/test/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-promise.js @@ -15,7 +15,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let values = [1, 2, 3]; diff --git a/test/built-ins/Promise/any/invoke-resolve.js b/test/built-ins/Promise/any/invoke-resolve.js index 60119c33a4..02977fb250 100644 --- a/test/built-ins/Promise/any/invoke-resolve.js +++ b/test/built-ins/Promise/any/invoke-resolve.js @@ -17,7 +17,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let boundPromiseResolve = Promise.resolve.bind(Promise); diff --git a/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js b/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js index abb34225f3..bc6281e5d4 100644 --- a/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js +++ b/test/built-ins/Promise/any/invoke-then-on-promises-every-iteration.js @@ -16,7 +16,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let promises = [ diff --git a/test/built-ins/Promise/any/invoke-then.js b/test/built-ins/Promise/any/invoke-then.js index 3de9219962..b8b1ccdb6d 100644 --- a/test/built-ins/Promise/any/invoke-then.js +++ b/test/built-ins/Promise/any/invoke-then.js @@ -16,7 +16,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let promise = new Promise(() => {}); diff --git a/test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js b/test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js index 42edfcec92..14fb3cae1d 100644 --- a/test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-empty-iterable-reject.js @@ -25,7 +25,7 @@ info: | ... flags: [async] -features: [AggregateError, Promise.any] +features: [AggregateError, Promise.any, arrow-function] ---*/ Promise.any([]) diff --git a/test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js b/test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js index 7f780fa95c..cb3e319766 100644 --- a/test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js +++ b/test/built-ins/Promise/any/iter-arg-is-empty-string-reject.js @@ -24,7 +24,7 @@ info: | 3. Return ThrowCompletion(error). ... -features: [AggregateError, Promise.any] +features: [AggregateError, Promise.any, arrow-function] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-poisoned.js b/test/built-ins/Promise/any/iter-arg-is-poisoned.js index 723e9df9b2..679ca788f9 100644 --- a/test/built-ins/Promise/any/iter-arg-is-poisoned.js +++ b/test/built-ins/Promise/any/iter-arg-is-poisoned.js @@ -19,7 +19,7 @@ info: | ... Let iterator be ? Call(method, obj). ... -features: [Promise.any] +features: [Promise.any, Symbol, Symbol.iterator, arrow-function] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js index 3abb467361..31553ea977 100644 --- a/test/built-ins/Promise/any/iter-arg-is-string-resolve.js +++ b/test/built-ins/Promise/any/iter-arg-is-string-resolve.js @@ -20,7 +20,7 @@ info: | Let iterator be ? Call(method, obj). If Type(iterator) is not Object, throw a TypeError exception. ... -features: [Promise.any] +features: [Promise.any, arrow-function] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-false-reject.js b/test/built-ins/Promise/any/iter-assigned-false-reject.js index 8d10761861..9e6e32a213 100644 --- a/test/built-ins/Promise/any/iter-assigned-false-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-false-reject.js @@ -35,7 +35,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, Symbol, computed-property-names] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-null-reject.js b/test/built-ins/Promise/any/iter-assigned-null-reject.js index b5edb10abc..08e9b18ad5 100644 --- a/test/built-ins/Promise/any/iter-assigned-null-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-null-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, Symbol, computed-property-names] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-number-reject.js b/test/built-ins/Promise/any/iter-assigned-number-reject.js index 0b2884d17a..4e600b4278 100644 --- a/test/built-ins/Promise/any/iter-assigned-number-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-number-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, Symbol, computed-property-names] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-string-reject.js b/test/built-ins/Promise/any/iter-assigned-string-reject.js index b8a4c9f860..ab37eaca38 100644 --- a/test/built-ins/Promise/any/iter-assigned-string-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-string-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, Symbol, computed-property-names] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-symbol-reject.js b/test/built-ins/Promise/any/iter-assigned-symbol-reject.js index b8caa0eca1..341afd3d79 100644 --- a/test/built-ins/Promise/any/iter-assigned-symbol-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-symbol-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol, Symbol.iterator] +features: [Promise.any, Symbol, Symbol.iterator, computed-property-names] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-true-reject.js b/test/built-ins/Promise/any/iter-assigned-true-reject.js index 8300051c36..5eebb151bd 100644 --- a/test/built-ins/Promise/any/iter-assigned-true-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-true-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, Symbol, computed-property-names] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-assigned-undefined-reject.js b/test/built-ins/Promise/any/iter-assigned-undefined-reject.js index 668ef26a78..037669016f 100644 --- a/test/built-ins/Promise/any/iter-assigned-undefined-reject.js +++ b/test/built-ins/Promise/any/iter-assigned-undefined-reject.js @@ -33,7 +33,7 @@ info: | Call ( F, V [ , argumentsList ] ) 2. If IsCallable(F) is false, throw a TypeError exception. -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, Symbol, computed-property-names] flags: [async] ---*/ diff --git a/test/built-ins/Promise/any/iter-step-err-no-close.js b/test/built-ins/Promise/any/iter-step-err-no-close.js index 686d07e724..329240b707 100644 --- a/test/built-ins/Promise/any/iter-step-err-no-close.js +++ b/test/built-ins/Promise/any/iter-step-err-no-close.js @@ -21,7 +21,7 @@ info: | c. ReturnIfAbrupt(next). flags: [async] -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, computed-property-names, Symbol, arrow-function] ---*/ let returnCount = 0; diff --git a/test/built-ins/Promise/any/iter-step-err-reject.js b/test/built-ins/Promise/any/iter-step-err-reject.js index 3cea43a434..d06a2e0111 100644 --- a/test/built-ins/Promise/any/iter-step-err-reject.js +++ b/test/built-ins/Promise/any/iter-step-err-reject.js @@ -21,7 +21,7 @@ info: | c. ReturnIfAbrupt(next). flags: [async] -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, computed-property-names, Symbol, arrow-function] ---*/ let poisonedDone = {}; diff --git a/test/built-ins/Promise/any/reject-all-mixed.js b/test/built-ins/Promise/any/reject-all-mixed.js index a4531e885f..194f4eef18 100644 --- a/test/built-ins/Promise/any/reject-all-mixed.js +++ b/test/built-ins/Promise/any/reject-all-mixed.js @@ -6,7 +6,7 @@ esid: sec-promise.any description: > Promise.any rejection reasons from various rejections are all present flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let rejections = [ diff --git a/test/built-ins/Promise/any/reject-deferred.js b/test/built-ins/Promise/any/reject-deferred.js index 3382a6d2d8..496fbff5ff 100644 --- a/test/built-ins/Promise/any/reject-deferred.js +++ b/test/built-ins/Promise/any/reject-deferred.js @@ -10,7 +10,7 @@ info: | flags: [async] -features: [AggregateError, Promise.any] +features: [AggregateError, Promise.any, arrow-function] ---*/ var rejection = {}; diff --git a/test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js b/test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js index 2d83ff3137..e49303cfc0 100644 --- a/test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js +++ b/test/built-ins/Promise/any/resolve-ignores-late-rejection-deferred.js @@ -16,7 +16,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ var resolver = { diff --git a/test/built-ins/Promise/any/resolve-ignores-late-rejection.js b/test/built-ins/Promise/any/resolve-ignores-late-rejection.js index 64955007af..fca6653525 100644 --- a/test/built-ins/Promise/any/resolve-ignores-late-rejection.js +++ b/test/built-ins/Promise/any/resolve-ignores-late-rejection.js @@ -16,7 +16,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ var resolver = { diff --git a/test/built-ins/Promise/any/resolve-one-mixed.js b/test/built-ins/Promise/any/resolve-one-mixed.js index b33ea0b31c..e5f97d7efd 100644 --- a/test/built-ins/Promise/any/resolve-one-mixed.js +++ b/test/built-ins/Promise/any/resolve-one-mixed.js @@ -6,7 +6,7 @@ esid: sec-promise.any description: > Promise.any resolves with the first item that does not reject. flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let fulfillables = [ From d9265df3abc1518a620670a5a616bc95a8b772c1 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Tue, 24 Mar 2020 17:22:11 -0400 Subject: [PATCH 22/29] Promise.any: additional then + resolve tests --- .../Promise/any/invoke-resolve-error-close.js | 54 +++++++++++++++++ .../any/invoke-resolve-error-reject.js | 33 +++++++++++ .../any/invoke-resolve-get-error-close.js | 58 +++++++++++++++++++ .../any/invoke-resolve-get-error-reject.js | 36 ++++++++++++ .../invoke-resolve-get-once-multiple-calls.js | 55 ++++++++++++++++++ .../any/invoke-resolve-get-once-no-calls.js | 50 ++++++++++++++++ test/built-ins/Promise/any/invoke-resolve.js | 2 +- .../Promise/any/invoke-then-error-close.js | 51 ++++++++++++++++ .../Promise/any/invoke-then-error-reject.js | 33 +++++++++++ .../any/invoke-then-get-error-close.js | 52 +++++++++++++++++ .../any/invoke-then-get-error-reject.js | 34 +++++++++++ 11 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 test/built-ins/Promise/any/invoke-resolve-error-close.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-error-reject.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-get-error-close.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-get-error-reject.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js create mode 100644 test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js create mode 100644 test/built-ins/Promise/any/invoke-then-error-close.js create mode 100644 test/built-ins/Promise/any/invoke-then-error-reject.js create mode 100644 test/built-ins/Promise/any/invoke-then-get-error-close.js create mode 100644 test/built-ins/Promise/any/invoke-then-get-error-reject.js diff --git a/test/built-ins/Promise/any/invoke-resolve-error-close.js b/test/built-ins/Promise/any/invoke-resolve-error-close.js new file mode 100644 index 0000000000..e81b99a906 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-error-close.js @@ -0,0 +1,54 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Explicit iterator closing in response to error +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ + +let error = new Test262Error(); +let nextCount = 0; +let returnCount = 0; +let iter = { + [Symbol.iterator]() { + return { + next() { + nextCount += 1; + return { + value: null, + done: false + }; + }, + return() { + returnCount += 1; + } + }; + } +}; + +Promise.resolve = function() { + throw error; +}; + +Promise.any(iter).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 1); + assert.sameValue(reason, error); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-error-reject.js b/test/built-ins/Promise/any/invoke-resolve-error-reject.js new file mode 100644 index 0000000000..9d0335a144 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-error-reject.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Promise rejection in response to error +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ + +let error = new Test262Error(); +Promise.resolve = function() { + throw error; +}; + +Promise.any([1]).then(() => { + $DONE('The promise should be rejected, but was resolved'); + }, (reason) => { + assert.sameValue(reason, error); + }).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-get-error-close.js b/test/built-ins/Promise/any/invoke-resolve-get-error-close.js new file mode 100644 index 0000000000..556f01d7b6 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-get-error-close.js @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Error retrieving the constructor's `resolve` method not opening iterator +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ + +let error = new Test262Error(); +let nextCount = 0; +let returnCount = 0; +let iter = { + [Symbol.iterator]() { + return { + next() { + nextCount += 1; + return { + value: null, + done: false + }; + }, + return() { + returnCount += 1; + } + }; + } +}; + +Object.defineProperty(Promise, 'resolve', { + get() { + throw error; + } +}); + + +Promise.any(iter).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert.sameValue(nextCount, 0); + assert.sameValue(returnCount, 1); + assert.sameValue(reason, error); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js b/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js new file mode 100644 index 0000000000..8c0119567b --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Error retrieving the constructor's `resolve` method (rejecting promise) +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ + +let error = new Test262Error(); +Object.defineProperty(Promise, 'resolve', { + get() { + throw error; + } +}); + +Promise.any([1]).then(() => { + $DONE('The promise should be rejected, but was resolved'); + }, (reason) => { + assert.sameValue(reason, error); + }).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js b/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js new file mode 100644 index 0000000000..ef5753f749 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js @@ -0,0 +1,55 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Gets constructor's `resolve` method once from zero to many invocations. +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 6. Let promiseResolve be ? Get(constructor, "resolve"). + 7. If ! IsCallable(promiseResolve) is false, throw a TypeError exception. + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ + +let promises = [ + Promise.reject(1), + Promise.reject(1), + Promise.reject(1), +]; +let boundPromiseResolve = Promise.resolve.bind(Promise); +let getCount = 0; +let callCount = 0; + +Object.defineProperty(Promise, 'resolve', { + configurable: true, + get() { + getCount += 1; + return function(...args) { + callCount += 1; + return boundPromiseResolve(...args); + }; + } +}); + +Promise.any(promises).then(() => { + $DONE('The promise should be rejected, but was resolved'); + }, ({errors}) => { + assert.sameValue(getCount, 1); + assert.sameValue(callCount, 3); + assert.sameValue(errors.length, 3); + }).then($DONE, $DONE); + + diff --git a/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js b/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js new file mode 100644 index 0000000000..8806db21f8 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Gets constructor's `resolve` method once from zero to many invocations. +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + 6. Let promiseResolve be ? Get(constructor, "resolve"). + 7. If ! IsCallable(promiseResolve) is false, throw a TypeError exception. + 8. Repeat + ... + i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + +flags: [async] +features: [Promise.any] +---*/ + +let boundPromiseResolve = Promise.resolve.bind(Promise); +let getCount = 0; +let callCount = 0; + +Object.defineProperty(Promise, 'resolve', { + configurable: true, + get() { + getCount += 1; + return function(...args) { + callCount += 1; + return boundPromiseResolve(...args); + }; + } +}); + +Promise.any([]).then(() => { + $DONE('The promise should be rejected, but was resolved'); + }, ({errors}) => { + assert.sameValue(getCount, 1); + assert.sameValue(callCount, 0); + assert.sameValue(errors.length, 0); + }).then($DONE, $DONE); + + diff --git a/test/built-ins/Promise/any/invoke-resolve.js b/test/built-ins/Promise/any/invoke-resolve.js index 02977fb250..820d0ec61e 100644 --- a/test/built-ins/Promise/any/invoke-resolve.js +++ b/test/built-ins/Promise/any/invoke-resolve.js @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// Copyright (C) 2019 Sergey Rubanov, 2020 Rick Waldron. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/test/built-ins/Promise/any/invoke-then-error-close.js b/test/built-ins/Promise/any/invoke-then-error-close.js new file mode 100644 index 0000000000..fa1389950c --- /dev/null +++ b/test/built-ins/Promise/any/invoke-then-error-close.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Error thrown when invoking the instance's `then` method (closing iterator) +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ + +let error = new Test262Error(); +let promise = new Promise(() => {}); +let returnCount = 0; +let iter = { + [Symbol.iterator]() { + return { + next() { + return { + done: false, + value: promise + }; + }, + return() { + returnCount += 1; + return {}; + } + }; + } +}; + +promise.then = function() { + throw error; +}; + +Promise.any(iter).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert.sameValue(returnCount, 1); + assert.sameValue(reason, error); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-then-error-reject.js b/test/built-ins/Promise/any/invoke-then-error-reject.js new file mode 100644 index 0000000000..757fe85705 --- /dev/null +++ b/test/built-ins/Promise/any/invoke-then-error-reject.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Error thrown when invoking the instance's `then` method (rejecting Promise) +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] +features: [Promise.any] +---*/ +let error = new Test262Error(); +let promise = Promise.resolve(); + +promise.then = function() { + throw error; +}; + +Promise.any([promise]).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert.sameValue(reason, error); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-then-get-error-close.js b/test/built-ins/Promise/any/invoke-then-get-error-close.js new file mode 100644 index 0000000000..603edf4e1c --- /dev/null +++ b/test/built-ins/Promise/any/invoke-then-get-error-close.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Error thrown when accesing the instance's `then` method (closing iterator) +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ +let error = new Test262Error(); +let promise = new Promise(() => {}); +let returnCount = 0; +let iter = { + [Symbol.iterator]() { + return { + next() { + return { + done: false, + value: promise + }; + }, + return() { + returnCount += 1; + return {}; + } + }; + } +}; + +Object.defineProperty(promise, 'then', { + get() { + throw error; + } +}); + +Promise.any(iter).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert.sameValue(returnCount, 1); + assert.sameValue(reason, error); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/invoke-then-get-error-reject.js b/test/built-ins/Promise/any/invoke-then-get-error-reject.js new file mode 100644 index 0000000000..1651cb1aac --- /dev/null +++ b/test/built-ins/Promise/any/invoke-then-get-error-reject.js @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Error thrown when accessing the instance's `then` method (rejecting Promise) +esid: sec-promise.any +info: | + + 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + b. IfAbruptRejectPromise(result, promiseCapability). + + Runtime Semantics: PerformPromiseAny + + r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). + +flags: [async] +features: [Promise.any] +---*/ +let error = new Test262Error(); +let promise = new Promise(() => {}); + +Object.defineProperty(promise, 'then', { + get() { + throw error; + } +}); + +Promise.any([promise]).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert.sameValue(reason, error); +}).then($DONE, $DONE); From 5c68b60ad30cabd2ba3c0f24fb8590058124cdbb Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 25 Mar 2020 09:39:19 -0400 Subject: [PATCH 23/29] Promise.any: cleanup in @@species tests --- .../any/does-not-perform-species-get-of-custom.js | 10 +++++----- .../any/does-not-perform-species-get-of-promise.js | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js index 2f43a88f28..fe112b30ae 100644 --- a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js @@ -4,7 +4,7 @@ /*--- esid: sec-promise.any description: > - Promise.any() does not retrieve `Symbol.species` property of the "`this` value" + Promise.any.call(Custom, ...) does not derive a constructor via SpeciesConstructor() info: | 1. Let C be the this value. 2. Let promiseCapability be ? NewPromiseCapability(C). @@ -20,13 +20,13 @@ flags: [async] features: [Promise.any, Symbol.species, class, class-static-method, computed-property-names, Symbol, arrow-function] ---*/ -class C extends Promise { +class Custom extends Promise { static get [Symbol.species]() { - throw new Test262Error('Getter for Symbol.species called'); + throw new Test262Error('Erroneous Get(C, @@species) via SpeciesConstructor() occurred.'); } static resolve() { - throw new Test262Error('C.resolve was reached'); + throw new Test262Error('Custom.resolve was reached'); } } -Promise.any.call(C, [1]).then(() => $DONE(), $DONE); +Promise.any.call(Custom, [1]).then(() => $DONE(), $DONE); diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js index 09e0372618..299c03ddaf 100644 --- a/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js @@ -4,7 +4,7 @@ /*--- esid: sec-promise.any description: > - Promise.any() does not retrieve `Symbol.species` property of the "`this` value". + Promise.any() does not derive a constructor via SpeciesConstructor() info: | 1. Let C be the this value. 2. Let promiseCapability be ? NewPromiseCapability(C). @@ -22,7 +22,10 @@ features: [Promise.any, Symbol.species, Symbol, arrow-function] Object.defineProperty(Promise, Symbol.species, { get() { - throw new Test262Error('Getter for Symbol.species called'); + throw new Test262Error('Erroneous Get(C, @@species) via SpeciesConstructor() occurred.'); + } + static resolve() { + throw new Test262Error('Promise.resolve was reached'); } }); From 7fbce5a9d8ebd7c513fb98e9f4bccf62aa64daf4 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 25 Mar 2020 09:42:35 -0400 Subject: [PATCH 24/29] Promise.any: simplify promise creation --- test/built-ins/Promise/any/invoke-then-error-close.js | 2 +- test/built-ins/Promise/any/invoke-then-get-error-close.js | 2 +- test/built-ins/Promise/any/invoke-then-get-error-reject.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/built-ins/Promise/any/invoke-then-error-close.js b/test/built-ins/Promise/any/invoke-then-error-close.js index fa1389950c..0685a13758 100644 --- a/test/built-ins/Promise/any/invoke-then-error-close.js +++ b/test/built-ins/Promise/any/invoke-then-error-close.js @@ -20,7 +20,7 @@ features: [Promise.any, Symbol.iterator] ---*/ let error = new Test262Error(); -let promise = new Promise(() => {}); +let promise = Promise.resolve(); let returnCount = 0; let iter = { [Symbol.iterator]() { diff --git a/test/built-ins/Promise/any/invoke-then-get-error-close.js b/test/built-ins/Promise/any/invoke-then-get-error-close.js index 603edf4e1c..29088a8f28 100644 --- a/test/built-ins/Promise/any/invoke-then-get-error-close.js +++ b/test/built-ins/Promise/any/invoke-then-get-error-close.js @@ -19,7 +19,7 @@ flags: [async] features: [Promise.any, Symbol.iterator] ---*/ let error = new Test262Error(); -let promise = new Promise(() => {}); +let promise = Promise.resolve(); let returnCount = 0; let iter = { [Symbol.iterator]() { diff --git a/test/built-ins/Promise/any/invoke-then-get-error-reject.js b/test/built-ins/Promise/any/invoke-then-get-error-reject.js index 1651cb1aac..24a312d34b 100644 --- a/test/built-ins/Promise/any/invoke-then-get-error-reject.js +++ b/test/built-ins/Promise/any/invoke-then-get-error-reject.js @@ -19,7 +19,7 @@ flags: [async] features: [Promise.any] ---*/ let error = new Test262Error(); -let promise = new Promise(() => {}); +let promise = Promise.resolve(); Object.defineProperty(promise, 'then', { get() { From a05fb94eba4516e4c9565744070b264ff21f4ec6 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 25 Mar 2020 09:43:22 -0400 Subject: [PATCH 25/29] Promise.any: feature flags, 2 --- test/built-ins/Promise/any/invoke-resolve-error-close.js | 2 +- test/built-ins/Promise/any/invoke-resolve-error-reject.js | 2 +- test/built-ins/Promise/any/invoke-resolve-get-error-close.js | 2 +- test/built-ins/Promise/any/invoke-resolve-get-error-reject.js | 2 +- .../Promise/any/invoke-resolve-get-once-multiple-calls.js | 2 +- test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js | 2 +- test/built-ins/Promise/any/invoke-then-error-close.js | 2 +- test/built-ins/Promise/any/invoke-then-error-reject.js | 2 +- test/built-ins/Promise/any/invoke-then-get-error-close.js | 2 +- test/built-ins/Promise/any/invoke-then-get-error-reject.js | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/built-ins/Promise/any/invoke-resolve-error-close.js b/test/built-ins/Promise/any/invoke-resolve-error-close.js index e81b99a906..a013b6c676 100644 --- a/test/built-ins/Promise/any/invoke-resolve-error-close.js +++ b/test/built-ins/Promise/any/invoke-resolve-error-close.js @@ -18,7 +18,7 @@ info: | ... i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, computed-property-names, Symbol, arrow-function] ---*/ let error = new Test262Error(); diff --git a/test/built-ins/Promise/any/invoke-resolve-error-reject.js b/test/built-ins/Promise/any/invoke-resolve-error-reject.js index 9d0335a144..7eb29d4f04 100644 --- a/test/built-ins/Promise/any/invoke-resolve-error-reject.js +++ b/test/built-ins/Promise/any/invoke-resolve-error-reject.js @@ -18,7 +18,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let error = new Test262Error(); diff --git a/test/built-ins/Promise/any/invoke-resolve-get-error-close.js b/test/built-ins/Promise/any/invoke-resolve-get-error-close.js index 556f01d7b6..87c2de53ce 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-error-close.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-error-close.js @@ -19,7 +19,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, computed-property-names, Symbol, arrow-function] ---*/ let error = new Test262Error(); diff --git a/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js b/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js index 8c0119567b..16a5e2dc19 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js @@ -19,7 +19,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let error = new Test262Error(); diff --git a/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js b/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js index ef5753f749..971533f05d 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js @@ -21,7 +21,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function, destructuring-binding] ---*/ let promises = [ diff --git a/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js b/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js index 8806db21f8..5b44a2a8bd 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js @@ -21,7 +21,7 @@ info: | i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function, destructuring-binding] ---*/ let boundPromiseResolve = Promise.resolve.bind(Promise); diff --git a/test/built-ins/Promise/any/invoke-then-error-close.js b/test/built-ins/Promise/any/invoke-then-error-close.js index 0685a13758..be88b73fdb 100644 --- a/test/built-ins/Promise/any/invoke-then-error-close.js +++ b/test/built-ins/Promise/any/invoke-then-error-close.js @@ -16,7 +16,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, arrow-function, computed-property-names, Symbol] ---*/ let error = new Test262Error(); diff --git a/test/built-ins/Promise/any/invoke-then-error-reject.js b/test/built-ins/Promise/any/invoke-then-error-reject.js index 757fe85705..f89cb0cb95 100644 --- a/test/built-ins/Promise/any/invoke-then-error-reject.js +++ b/test/built-ins/Promise/any/invoke-then-error-reject.js @@ -17,7 +17,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let error = new Test262Error(); let promise = Promise.resolve(); diff --git a/test/built-ins/Promise/any/invoke-then-get-error-close.js b/test/built-ins/Promise/any/invoke-then-get-error-close.js index 29088a8f28..e04e295068 100644 --- a/test/built-ins/Promise/any/invoke-then-get-error-close.js +++ b/test/built-ins/Promise/any/invoke-then-get-error-close.js @@ -16,7 +16,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any, Symbol.iterator] +features: [Promise.any, Symbol.iterator, arrow-function, computed-property-names, Symbol] ---*/ let error = new Test262Error(); let promise = Promise.resolve(); diff --git a/test/built-ins/Promise/any/invoke-then-get-error-reject.js b/test/built-ins/Promise/any/invoke-then-get-error-reject.js index 24a312d34b..6036e6c9c9 100644 --- a/test/built-ins/Promise/any/invoke-then-get-error-reject.js +++ b/test/built-ins/Promise/any/invoke-then-get-error-reject.js @@ -16,7 +16,7 @@ info: | r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). flags: [async] -features: [Promise.any] +features: [Promise.any, arrow-function] ---*/ let error = new Test262Error(); let promise = Promise.resolve(); From b21b0c1820cee545547c18834290564899d4a714 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 25 Mar 2020 09:55:34 -0400 Subject: [PATCH 26/29] Promise.any: additional "resolve from rejection" tests --- .../Promise/any/resolve-from-reject-catch.js | 22 +++++++++++++++++++ ...s => resolve-from-resolve-reject-catch.js} | 0 .../resolve-from-resolve-reject-finally.js | 22 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/built-ins/Promise/any/resolve-from-reject-catch.js rename test/built-ins/Promise/any/{resolve-one-mixed.js => resolve-from-resolve-reject-catch.js} (100%) create mode 100644 test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js diff --git a/test/built-ins/Promise/any/resolve-from-reject-catch.js b/test/built-ins/Promise/any/resolve-from-reject-catch.js new file mode 100644 index 0000000000..bbefced968 --- /dev/null +++ b/test/built-ins/Promise/any/resolve-from-reject-catch.js @@ -0,0 +1,22 @@ +// 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: > + Promise.any resolves with the first item that does not reject. +flags: [async] +features: [Promise.any, arrow-function] +---*/ + +let fulfillables = [ + Promise.reject('a'), + new Promise((resolve, reject) => reject('b')), + Promise.all([Promise.reject('c')]), + Promise.reject('d').catch(v => v), +]; + +Promise.any(fulfillables) + .then((resolution) => { + assert.sameValue(resolution, 'd'); + }).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/resolve-one-mixed.js b/test/built-ins/Promise/any/resolve-from-resolve-reject-catch.js similarity index 100% rename from test/built-ins/Promise/any/resolve-one-mixed.js rename to test/built-ins/Promise/any/resolve-from-resolve-reject-catch.js diff --git a/test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js b/test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js new file mode 100644 index 0000000000..de1c6a8930 --- /dev/null +++ b/test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js @@ -0,0 +1,22 @@ +// 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: > + Promise.any resolves with the first item that does not reject. +flags: [async] +features: [Promise.any, arrow-function] +---*/ + +let fulfillables = [ + Promise.reject('a'), + new Promise((resolve, reject) => reject('b')), + Promise.all([Promise.reject('c')]), + Promise.resolve(Promise.reject('d').finally(v => v)), +]; + +Promise.any(fulfillables) + .then((resolution) => { + assert.sameValue(resolution, 'd'); + }).then($DONE, $DONE); From 499b748dca709da915fd74ebfe72bfee0eb7212d Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 25 Mar 2020 12:14:32 -0400 Subject: [PATCH 27/29] Promise.any: review fixes, 2 --- ...does-not-perform-species-get-of-promise.js | 3 --- .../resolve-from-resolve-reject-finally.js | 22 ------------------- 2 files changed, 25 deletions(-) delete mode 100644 test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js index 299c03ddaf..0a32658066 100644 --- a/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-promise.js @@ -24,9 +24,6 @@ Object.defineProperty(Promise, Symbol.species, { get() { throw new Test262Error('Erroneous Get(C, @@species) via SpeciesConstructor() occurred.'); } - static resolve() { - throw new Test262Error('Promise.resolve was reached'); - } }); Promise.any([1]).then(() => $DONE(), $DONE); diff --git a/test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js b/test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js deleted file mode 100644 index de1c6a8930..0000000000 --- a/test/built-ins/Promise/any/resolve-from-resolve-reject-finally.js +++ /dev/null @@ -1,22 +0,0 @@ -// 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: > - Promise.any resolves with the first item that does not reject. -flags: [async] -features: [Promise.any, arrow-function] ----*/ - -let fulfillables = [ - Promise.reject('a'), - new Promise((resolve, reject) => reject('b')), - Promise.all([Promise.reject('c')]), - Promise.resolve(Promise.reject('d').finally(v => v)), -]; - -Promise.any(fulfillables) - .then((resolution) => { - assert.sameValue(resolution, 'd'); - }).then($DONE, $DONE); From d53f45db3d3bc71b3b46319c6a03d39fa4747ee5 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 25 Mar 2020 12:25:56 -0400 Subject: [PATCH 28/29] Promise.any: remove unnecessary static resolve def --- .../Promise/any/does-not-perform-species-get-of-custom.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js index fe112b30ae..c768c790e1 100644 --- a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js @@ -24,9 +24,6 @@ class Custom extends Promise { static get [Symbol.species]() { throw new Test262Error('Erroneous Get(C, @@species) via SpeciesConstructor() occurred.'); } - static resolve() { - throw new Test262Error('Custom.resolve was reached'); - } } Promise.any.call(Custom, [1]).then(() => $DONE(), $DONE); From 22be03d83386617953b94764b1963be5b3740ce5 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 27 Mar 2020 21:00:29 -0400 Subject: [PATCH 29/29] Promise.any: lint fixes --- .../Promise/any/does-not-perform-species-get-of-custom.js | 2 +- test/built-ins/Promise/any/invoke-resolve-error-close.js | 1 - test/built-ins/Promise/any/invoke-resolve-error-reject.js | 1 - test/built-ins/Promise/any/invoke-resolve-get-error-close.js | 1 - test/built-ins/Promise/any/invoke-resolve-get-error-reject.js | 1 - .../Promise/any/invoke-resolve-get-once-multiple-calls.js | 1 - test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js | 1 - test/built-ins/Promise/any/invoke-then-error-close.js | 1 - test/built-ins/Promise/any/invoke-then-error-reject.js | 1 - test/built-ins/Promise/any/invoke-then-get-error-close.js | 1 - test/built-ins/Promise/any/invoke-then-get-error-reject.js | 1 - 11 files changed, 1 insertion(+), 11 deletions(-) diff --git a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js index c768c790e1..cc96789191 100644 --- a/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js +++ b/test/built-ins/Promise/any/does-not-perform-species-get-of-custom.js @@ -17,7 +17,7 @@ info: | ... flags: [async] -features: [Promise.any, Symbol.species, class, class-static-method, computed-property-names, Symbol, arrow-function] +features: [Promise.any, Symbol.species, class, computed-property-names, Symbol, arrow-function] ---*/ class Custom extends Promise { diff --git a/test/built-ins/Promise/any/invoke-resolve-error-close.js b/test/built-ins/Promise/any/invoke-resolve-error-close.js index a013b6c676..b9bae20cfd 100644 --- a/test/built-ins/Promise/any/invoke-resolve-error-close.js +++ b/test/built-ins/Promise/any/invoke-resolve-error-close.js @@ -6,7 +6,6 @@ description: > Explicit iterator closing in response to error esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-resolve-error-reject.js b/test/built-ins/Promise/any/invoke-resolve-error-reject.js index 7eb29d4f04..9d6c1afb98 100644 --- a/test/built-ins/Promise/any/invoke-resolve-error-reject.js +++ b/test/built-ins/Promise/any/invoke-resolve-error-reject.js @@ -5,7 +5,6 @@ description: Promise rejection in response to error esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-resolve-get-error-close.js b/test/built-ins/Promise/any/invoke-resolve-get-error-close.js index 87c2de53ce..86566d13b4 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-error-close.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-error-close.js @@ -6,7 +6,6 @@ description: > Error retrieving the constructor's `resolve` method not opening iterator esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js b/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js index 16a5e2dc19..c954c01045 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-error-reject.js @@ -6,7 +6,6 @@ description: > Error retrieving the constructor's `resolve` method (rejecting promise) esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js b/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js index 971533f05d..d8a421f7d6 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-once-multiple-calls.js @@ -6,7 +6,6 @@ description: > Gets constructor's `resolve` method once from zero to many invocations. esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js b/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js index 5b44a2a8bd..2b7aa1384f 100644 --- a/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js +++ b/test/built-ins/Promise/any/invoke-resolve-get-once-no-calls.js @@ -6,7 +6,6 @@ description: > Gets constructor's `resolve` method once from zero to many invocations. esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-then-error-close.js b/test/built-ins/Promise/any/invoke-then-error-close.js index be88b73fdb..42d7e92b15 100644 --- a/test/built-ins/Promise/any/invoke-then-error-close.js +++ b/test/built-ins/Promise/any/invoke-then-error-close.js @@ -5,7 +5,6 @@ description: > Error thrown when invoking the instance's `then` method (closing iterator) esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-then-error-reject.js b/test/built-ins/Promise/any/invoke-then-error-reject.js index f89cb0cb95..bfd8f11371 100644 --- a/test/built-ins/Promise/any/invoke-then-error-reject.js +++ b/test/built-ins/Promise/any/invoke-then-error-reject.js @@ -6,7 +6,6 @@ description: > Error thrown when invoking the instance's `then` method (rejecting Promise) esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-then-get-error-close.js b/test/built-ins/Promise/any/invoke-then-get-error-close.js index e04e295068..b2d174cbf4 100644 --- a/test/built-ins/Promise/any/invoke-then-get-error-close.js +++ b/test/built-ins/Promise/any/invoke-then-get-error-close.js @@ -5,7 +5,6 @@ description: > Error thrown when accesing the instance's `then` method (closing iterator) esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). diff --git a/test/built-ins/Promise/any/invoke-then-get-error-reject.js b/test/built-ins/Promise/any/invoke-then-get-error-reject.js index 6036e6c9c9..b202898aec 100644 --- a/test/built-ins/Promise/any/invoke-then-get-error-reject.js +++ b/test/built-ins/Promise/any/invoke-then-get-error-reject.js @@ -5,7 +5,6 @@ description: > Error thrown when accessing the instance's `then` method (rejecting Promise) esid: sec-promise.any info: | - 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 6. If result is an abrupt completion, then a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).