diff --git a/test/built-ins/Promise/all/ctx-ctor-throws.js b/test/built-ins/Promise/all/ctx-ctor-throws.js new file mode 100644 index 0000000000..79f40da16b --- /dev/null +++ b/test/built-ins/Promise/all/ctx-ctor-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.all` invoked on a constructor value that throws an error +es6id: 25.4.4.1 +info: > + 1. Let C be the this value. + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + 7. ReturnIfAbrupt(promiseCapability). + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). +---*/ + +var CustomPromise = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + Promise.all.call(CustomPromise); +}); diff --git a/test/built-ins/Promise/prototype/then/ctor-throws.js b/test/built-ins/Promise/prototype/then/ctor-throws.js new file mode 100644 index 0000000000..340d59760a --- /dev/null +++ b/test/built-ins/Promise/prototype/then/ctor-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.prototype.then` invoked on a constructor value that throws an + error +es6id: 25.4.5.3 +info: > + 1. Let promise be the this value. + [...] + 3. Let C be SpeciesConstructor(promise, %Promise%). + [...] + 5. Let resultCapability be NewPromiseCapability(C). + 6. ReturnIfAbrupt(resultCapability). + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). + features: [Symbol.species] +---*/ + +var BadCtor = function() { + throw new Test262Error(); +}; +var originalSpecies = Object.getOwnPropertyDescriptor(Promise, Symbol.species); + +Object.defineProperty(Promise, Symbol.species, { value: BadCtor }); + +try { + var p = new Promise(function(resolve) { resolve(); }); + + assert.throws(Test262Error, function() { + p.then(); + }); +} finally { + Object.defineProperty(Promise, Symbol.species, originalSpecies); +} diff --git a/test/built-ins/Promise/race/ctx-ctor-throws.js b/test/built-ins/Promise/race/ctx-ctor-throws.js new file mode 100644 index 0000000000..6f7a92770e --- /dev/null +++ b/test/built-ins/Promise/race/ctx-ctor-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.race` invoked on a constructor value that throws an error +es6id: 25.4.4.3 +info: > + 1. Let C be the this value. + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + 7. ReturnIfAbrupt(promiseCapability). + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). +---*/ + +var CustomPromise = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + Promise.race.call(CustomPromise); +}); diff --git a/test/built-ins/Promise/reject/ctx-ctor-throws.js b/test/built-ins/Promise/reject/ctx-ctor-throws.js new file mode 100644 index 0000000000..c1cb7e2110 --- /dev/null +++ b/test/built-ins/Promise/reject/ctx-ctor-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.reject` invoked on a constructor value that throws an error +es6id: 25.4.4.4 +info: > + 1. Let C be the this value. + [...] + 3. Let promiseCapability be NewPromiseCapability(C). + 4. ReturnIfAbrupt(promiseCapability). + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). +---*/ + +var CustomPromise = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + Promise.reject.call(CustomPromise); +}); diff --git a/test/built-ins/Promise/resolve/ctx-ctor-throws.js b/test/built-ins/Promise/resolve/ctx-ctor-throws.js new file mode 100644 index 0000000000..4edcd4152f --- /dev/null +++ b/test/built-ins/Promise/resolve/ctx-ctor-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.resolve` invoked on a constructor value that throws an error +es6id: 25.4.4.5 +info: > + 1. Let C be the this value. + [...] + 4. Let promiseCapability be NewPromiseCapability(C). + 5. ReturnIfAbrupt(promiseCapability). + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). +---*/ + +var CustomPromise = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + Promise.resolve.call(CustomPromise); +});