diff --git a/test/built-ins/Promise/prototype/finally/species-constructor.js b/test/built-ins/Promise/prototype/finally/species-constructor.js index 24a772682095651cbd5a80d142bd6f652e3faaf0..1ed3cb3560ad0cd0b5647f09c196ddf97d9a562d 100644 --- a/test/built-ins/Promise/prototype/finally/species-constructor.js +++ b/test/built-ins/Promise/prototype/finally/species-constructor.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- author: Sathya Gunasekaran -description: finally calls the SpeciesConstructor +description: finally calls the SpeciesConstructor and creates the right amount of promises esid: sec-promise.prototype.finally features: [Promise.prototype.finally] flags: [async] @@ -22,4 +22,4 @@ new FooPromise(r => r()) .then(() => { assert.sameValue(count, 6, "6 new promises were created"); $DONE(); -}); + }, $ERROR); diff --git a/test/built-ins/Promise/prototype/finally/subclass-reject-count.js b/test/built-ins/Promise/prototype/finally/subclass-reject-count.js new file mode 100644 index 0000000000000000000000000000000000000000..6f9db88fe3201ecf09102c9d4e354278fc3fe345 --- /dev/null +++ b/test/built-ins/Promise/prototype/finally/subclass-reject-count.js @@ -0,0 +1,22 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Jordan Harband +description: Promise subclass finally on rejected creates the proper number of subclassed promises +esid: sec-promise.prototype.finally +features: [Promise.prototype.finally] +flags: [async] +---*/ + +var count = 0; +class FooPromise extends Promise { + constructor(resolve, reject) { + count++; + return super(resolve, reject); + } +} + +FooPromise.reject().finally(() => {}).then($ERROR).catch(() => { + assert.sameValue(7, count); + $DONE(); +}); diff --git a/test/built-ins/Promise/prototype/finally/subclass-resolve-count.js b/test/built-ins/Promise/prototype/finally/subclass-resolve-count.js new file mode 100644 index 0000000000000000000000000000000000000000..87642c301a265b8f3b272b2d1c841a7b376cbba1 --- /dev/null +++ b/test/built-ins/Promise/prototype/finally/subclass-resolve-count.js @@ -0,0 +1,22 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Jordan Harband +description: Promise subclass finally on resolved creates the proper number of subclassed promises +esid: sec-promise.prototype.finally +features: [Promise.prototype.finally] +flags: [async] +---*/ + +var count = 0; +class FooPromise extends Promise { + constructor(resolve, reject) { + count++; + return super(resolve, reject); + } +} + +FooPromise.resolve().finally(() => {}).then(() => { + assert.sameValue(6, count); + $DONE(); +}, $ERROR); diff --git a/test/built-ins/Promise/prototype/finally/subclass-species-constructor-reject-count.js b/test/built-ins/Promise/prototype/finally/subclass-species-constructor-reject-count.js new file mode 100644 index 0000000000000000000000000000000000000000..5db1a5f49467bdb615e382ca47ff10cddc35c1a4 --- /dev/null +++ b/test/built-ins/Promise/prototype/finally/subclass-species-constructor-reject-count.js @@ -0,0 +1,17 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Jordan Harband +description: finally on rejected Promise calls the SpeciesConstructor +esid: sec-promise.prototype.finally +features: [Promise.prototype.finally] +---*/ + +class FooPromise extends Promise { + static get [Symbol.species]() { return Promise; } +} + +var p = Promise.reject().finally(() => FooPromise.reject()); + +assert.sameValue(p instanceof Promise, true); +assert.sameValue(p instanceof FooPromise, false); diff --git a/test/built-ins/Promise/prototype/finally/subclass-species-constructor-resolve-count.js b/test/built-ins/Promise/prototype/finally/subclass-species-constructor-resolve-count.js new file mode 100644 index 0000000000000000000000000000000000000000..f34a795a2380e48e5ff2b8852ba704798aed1142 --- /dev/null +++ b/test/built-ins/Promise/prototype/finally/subclass-species-constructor-resolve-count.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Jordan Harband +description: finally on resolved Promise calls the SpeciesConstructor +esid: sec-promise.prototype.finally +features: [Promise.prototype.finally] +flags: [async] +---*/ + +class FooPromise extends Promise { + static get [Symbol.species]() { return Promise; } +} + +var p = Promise.resolve().finally(() => FooPromise.resolve()); + +assert.sameValue(p instanceof Promise, true); +assert.sameValue(p instanceof FooPromise, false); diff --git a/test/built-ins/Promise/prototype/finally/this-value-non-promise.js b/test/built-ins/Promise/prototype/finally/this-value-non-promise.js new file mode 100644 index 0000000000000000000000000000000000000000..16d9f8d76640f3ae02c1ddb9d8c1dc4e55a10286 --- /dev/null +++ b/test/built-ins/Promise/prototype/finally/this-value-non-promise.js @@ -0,0 +1,17 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Jordan Harband +description: > + Promise.prototype.finally called with a non-branded Promise does not throw +esid: sec-promise.prototype.finally +features: [Promise.prototype.finally] +---*/ + +var called = false; +var p = new Proxy(Promise.resolve(), {}); +var oldThen = Promise.prototype.then; +Promise.prototype.then = () => { called = true; }; +Promise.prototype.finally.call(p); +assert.sameValue(called, true); +Promise.prototype.then = oldThen;