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 deleted file mode 100644 index 86566d13b4..0000000000 --- a/test/built-ins/Promise/any/invoke-resolve-get-error-close.js +++ /dev/null @@ -1,57 +0,0 @@ -// 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, computed-property-names, Symbol, arrow-function] ----*/ - -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.js b/test/built-ins/Promise/any/invoke-resolve-get-error.js new file mode 100644 index 0000000000..05f35e452d --- /dev/null +++ b/test/built-ins/Promise/any/invoke-resolve-get-error.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 +description: > + Promise.resolve is retrieved before GetIterator call (abrupt lookup). +info: | + Promise.any ( iterable ) + + [...] + 3. Let promiseResolve be GetPromiseResolve(C). + 4. IfAbruptRejectPromise(promiseResolve, promiseCapability). + + GetPromiseResolve ( promiseConstructor ) + + [...] + 2. Let promiseResolve be ? Get(promiseConstructor, "resolve"). +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ + +const iter = { + get [Symbol.iterator]() { + throw new Test262Error('unreachable'); + }, +}; + +const resolveError = { name: 'MyError' }; +Object.defineProperty(Promise, 'resolve', { + get() { + throw resolveError; + }, +}); + +Promise.any(iter).then(() => { + throw new Test262Error('The promise should be rejected, but it was resolved'); +}, (reason) => { + assert.sameValue(reason, resolveError); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/resolve-non-callable.js b/test/built-ins/Promise/any/resolve-non-callable.js new file mode 100644 index 0000000000..6fc56d45ab --- /dev/null +++ b/test/built-ins/Promise/any/resolve-non-callable.js @@ -0,0 +1,36 @@ +// Copyright (C) 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.any +description: > + Promise.resolve is retrieved before GetIterator call (non-callable). +info: | + Promise.any ( iterable ) + + [...] + 3. Let promiseResolve be GetPromiseResolve(C). + 4. IfAbruptRejectPromise(promiseResolve, promiseCapability). + + GetPromiseResolve ( promiseConstructor ) + + [...] + 2. Let promiseResolve be ? Get(promiseConstructor, "resolve"). + 3. If IsCallable(promiseResolve) is false, throw a TypeError exception. +flags: [async] +features: [Promise.any, Symbol.iterator] +---*/ + +const iter = {  + get [Symbol.iterator]() { + throw new Test262Error("unreachable"); + }, +}; + +Promise.resolve = "certainly not callable"; + +Promise.any(iter).then(() => { + throw new Test262Error("The promise should be rejected, but it was resolved"); +}, (reason) => { + assert(reason instanceof TypeError); +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/any/resolve-not-callable-close.js b/test/built-ins/Promise/any/resolve-not-callable-close.js deleted file mode 100644 index 24b4567f5e..0000000000 --- a/test/built-ins/Promise/any/resolve-not-callable-close.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2020 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Explicit iterator closing if Promise.resolve is not callable -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 - - [...] - 5. Let promiseResolve be ? Get(constructor, "resolve"). - 6. If ! IsCallable(promiseResolve) is false, throw a TypeError exception. - [...] - -flags: [async] -features: [Promise.any, Symbol.iterator, computed-property-names, arrow-function] ----*/ - -let returnCount = 0; -const iter = {  - [Symbol.iterator]: function() { - return { - return: function() { - ++returnCount; - } - }; - } -} - -Promise.resolve = "certainly not callable"; - -Promise.any(iter).then(() => { - $DONE('The promise should be rejected, but was resolved'); -}, (reason) => { - assert(reason instanceof TypeError); -}).then($DONE, $DONE); - -assert.sameValue(returnCount, 1);