From cf37b039a81bf18a777df873bbd4c0ad317e6610 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Wed, 3 Jun 2020 17:21:22 +0300 Subject: [PATCH] Update Promise.all tests --- .../all/invoke-resolve-get-error-close.js | 57 ------------------- .../Promise/all/invoke-resolve-get-error.js | 40 +++++++++++++ .../Promise/all/resolve-non-callable.js | 36 ++++++++++++ .../Promise/all/resolve-not-callable-close.js | 47 --------------- 4 files changed, 76 insertions(+), 104 deletions(-) delete mode 100644 test/built-ins/Promise/all/invoke-resolve-get-error-close.js create mode 100644 test/built-ins/Promise/all/invoke-resolve-get-error.js create mode 100644 test/built-ins/Promise/all/resolve-non-callable.js delete mode 100644 test/built-ins/Promise/all/resolve-not-callable-close.js diff --git a/test/built-ins/Promise/all/invoke-resolve-get-error-close.js b/test/built-ins/Promise/all/invoke-resolve-get-error-close.js deleted file mode 100644 index a2be82922c..0000000000 --- a/test/built-ins/Promise/all/invoke-resolve-get-error-close.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Error retrieving the constructor's `resolve` method before iterator being used. -esid: sec-performpromiseall -info: | - 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability). - 12. If result is an abrupt completion, - a. If iteratorRecord.[[done]] is false, let result be - IteratorClose(iterator, result). - b. IfAbruptRejectPromise(result, promiseCapability). - - ... - - Runtime Semantics: PerformPromiseAll - - ... - 1. Let promiseResolve be ? Get(constructor, `"resolve"`). - ... - 1. Repeat, - 1. Let next be IteratorStep(iteratorRecord). - ... - 1. Let nextPromise be ? Call(promiseResolve, constructor, < nextValue >). -features: [Symbol.iterator] ----*/ - -var iter = {}; - -var returnCount = 0; -var nextCount = 0; - -iter[Symbol.iterator] = function() { - return { - next: function() { - nextCount += 1; - return { - done: false - }; - }, - return: function() { - returnCount += 1; - return {}; - } - }; -}; -Object.defineProperty(Promise, 'resolve', { - get() { - throw new Test262Error(); - } -}); - -Promise.all(iter); - -assert.sameValue(nextCount, 0); -assert.sameValue(returnCount, 1); diff --git a/test/built-ins/Promise/all/invoke-resolve-get-error.js b/test/built-ins/Promise/all/invoke-resolve-get-error.js new file mode 100644 index 0000000000..072804f158 --- /dev/null +++ b/test/built-ins/Promise/all/invoke-resolve-get-error.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-promise.all +description: > + Promise.resolve is retrieved before GetIterator call (abrupt lookup). +info: | + Promise.all ( iterable ) + + [...] + 3. Let promiseResolve be GetPromiseResolve(C). + 4. IfAbruptRejectPromise(promiseResolve, promiseCapability). + + GetPromiseResolve ( promiseConstructor ) + + [...] + 2. Let promiseResolve be ? Get(promiseConstructor, "resolve"). +flags: [async] +features: [Symbol.iterator] +---*/ + +const iter = { + get [Symbol.iterator]() { + throw new Test262Error('unreachable'); + }, +}; + +const resolveError = { name: 'MyError' }; +Object.defineProperty(Promise, 'resolve', { + get() { + throw resolveError; + }, +}); + +Promise.all(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/all/resolve-non-callable.js b/test/built-ins/Promise/all/resolve-non-callable.js new file mode 100644 index 0000000000..57b8e31a49 --- /dev/null +++ b/test/built-ins/Promise/all/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.all +description: > + Promise.resolve is retrieved before GetIterator call (non-callable). +info: | + Promise.all ( 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: [Symbol.iterator] +---*/ + +const iter = {  + get [Symbol.iterator]() { + throw new Test262Error("unreachable"); + }, +}; + +Promise.resolve = "certainly not callable"; + +Promise.all(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/all/resolve-not-callable-close.js b/test/built-ins/Promise/all/resolve-not-callable-close.js deleted file mode 100644 index 6d73880749..0000000000 --- a/test/built-ins/Promise/all/resolve-not-callable-close.js +++ /dev/null @@ -1,47 +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.all -info: | - 5. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability). - 6. If result is an abrupt completion, - a. If iteratorRecord.[[Done]] is false, let result be - IteratorClose(iterator, result). - b. IfAbruptRejectPromise(result, promiseCapability). - - [...] - - Runtime Semantics: PerformPromiseAll - - [...] - 5. Let promiseResolve be ? Get(constructor, "resolve"). - 6. If ! IsCallable(promiseResolve) is false, throw a TypeError exception. - [...] - -flags: [async] -features: [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.all(iter).then(() => { - $DONE('The promise should be rejected, but was resolved'); -}, (reason) => { - assert(reason instanceof TypeError); -}).then($DONE, $DONE); - -assert.sameValue(returnCount, 1);