From 58dba42939c7c3042c7b589dfa2ddb76e29b19fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marja=20H=C3=B6ltt=C3=A4?= Date: Tue, 28 Apr 2020 10:27:53 +0200 Subject: [PATCH] Add Promise/*/resolve-not-callable-close.js --- .../Promise/all/resolve-not-callable-close.js | 47 +++++++++++++++++++ .../allSettled/resolve-not-callable-close.js | 44 +++++++++++++++++ .../Promise/any/resolve-not-callable-close.js | 44 +++++++++++++++++ .../race/resolve-not-callable-close.js | 47 +++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 test/built-ins/Promise/all/resolve-not-callable-close.js create mode 100644 test/built-ins/Promise/allSettled/resolve-not-callable-close.js create mode 100644 test/built-ins/Promise/any/resolve-not-callable-close.js create mode 100644 test/built-ins/Promise/race/resolve-not-callable-close.js diff --git a/test/built-ins/Promise/all/resolve-not-callable-close.js b/test/built-ins/Promise/all/resolve-not-callable-close.js new file mode 100644 index 0000000000..467e42f520 --- /dev/null +++ b/test/built-ins/Promise/all/resolve-not-callable-close.js @@ -0,0 +1,47 @@ +// 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] +---*/ + +let returnCount = 0; +const iter = {  + [Symbol.iterator]: function() { + return { + return: function() { + returnCount += 1; + } + }; + } +} + +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); diff --git a/test/built-ins/Promise/allSettled/resolve-not-callable-close.js b/test/built-ins/Promise/allSettled/resolve-not-callable-close.js new file mode 100644 index 0000000000..0f49f9d32f --- /dev/null +++ b/test/built-ins/Promise/allSettled/resolve-not-callable-close.js @@ -0,0 +1,44 @@ +// 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.allsettled +info: | + 5. Let result be PerformPromiseAllSettled(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: PerformPromiseAllSettled + + [...] + 5. Let promiseResolve be ? Get(constructor, "resolve"). + 6. If IsCallable(promiseResolve) is false, throw a TypeError exception. + [...] + +flags: [async] +features: [Promise.allSettled, Symbol.iterator, computed-property-names] +---*/ + +let returnCount = 0; +const iter = {  + [Symbol.iterator]: function() { + return { + return: function() { + returnCount += 1; + } + }; + } +} + +Promise.resolve = "certainly not callable"; + +Promise.allSettled(iter).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert(reason instanceof TypeError); +}).then($DONE, $DONE); + +assert.sameValue(returnCount, 1); diff --git a/test/built-ins/Promise/any/resolve-not-callable-close.js b/test/built-ins/Promise/any/resolve-not-callable-close.js new file mode 100644 index 0000000000..9a567cecc8 --- /dev/null +++ b/test/built-ins/Promise/any/resolve-not-callable-close.js @@ -0,0 +1,44 @@ +// 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 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] +---*/ + +let returnCount = 0; +const iter = {  + [Symbol.iterator]: function() { + return { + return: function() { + returnCount += 1; + } + }; + } +} + +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); diff --git a/test/built-ins/Promise/race/resolve-not-callable-close.js b/test/built-ins/Promise/race/resolve-not-callable-close.js new file mode 100644 index 0000000000..4362babc2f --- /dev/null +++ b/test/built-ins/Promise/race/resolve-not-callable-close.js @@ -0,0 +1,47 @@ +// 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.race +info: | + [...] + 5. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). + 6. If result is an abrupt completion, then + a. If iteratorRecord.[[Done]] is false, let result be + IteratorClose(iterator,result). + b. IfAbruptRejectPromise(result, promiseCapability). + + + Runtime Semantics: PerformPromiseRace + + [...] + 3. Let promiseResolve be ? Get(constructor, "resolve"). + 4. If ! IsCallable(promiseResolve) is false, throw a TypeError exception. + [...] + +flags: [async] +features: [Symbol.iterator, computed-property-names] +---*/ + +let returnCount = 0; +const iter = {  + [Symbol.iterator]: function() { + return { + return: function() { + returnCount += 1; + } + }; + } +} + +Promise.resolve = "certainly not callable"; + +Promise.race(iter).then(() => { + $DONE('The promise should be rejected, but was resolved'); +}, (reason) => { + assert(reason instanceof TypeError); +}).then($DONE, $DONE); + +assert.sameValue(returnCount, 1);