From 7c5b5bf75031df8ffde722dfe76540c71d064814 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 24 Jan 2018 22:20:44 -0800 Subject: [PATCH] Promise.prototype.finally: add missing tests Per: - https://github.com/tc39/test262/issues/866#issuecomment-328565337 - https://github.com/tc39/test262/issues/866#issuecomment-359978873 Closes #866. --- .../prototype/finally/species-constructor.js | 4 ++-- .../finally/subclass-reject-count.js | 22 +++++++++++++++++++ .../finally/subclass-resolve-count.js | 22 +++++++++++++++++++ ...bclass-species-constructor-reject-count.js | 17 ++++++++++++++ ...class-species-constructor-resolve-count.js | 18 +++++++++++++++ .../finally/this-value-non-promise.js | 17 ++++++++++++++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test/built-ins/Promise/prototype/finally/subclass-reject-count.js create mode 100644 test/built-ins/Promise/prototype/finally/subclass-resolve-count.js create mode 100644 test/built-ins/Promise/prototype/finally/subclass-species-constructor-reject-count.js create mode 100644 test/built-ins/Promise/prototype/finally/subclass-species-constructor-resolve-count.js create mode 100644 test/built-ins/Promise/prototype/finally/this-value-non-promise.js diff --git a/test/built-ins/Promise/prototype/finally/species-constructor.js b/test/built-ins/Promise/prototype/finally/species-constructor.js index 24a7726820..1ed3cb3560 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 0000000000..6f9db88fe3 --- /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 0000000000..87642c301a --- /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 0000000000..5db1a5f494 --- /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 0000000000..f34a795a23 --- /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 0000000000..16d9f8d766 --- /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;