From a392f6ced8d7fe0f4048b95c6cb5eda518574c93 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Sat, 28 Oct 2017 14:01:13 -0700 Subject: [PATCH] Promise.p.finally: test SpeciesConstructor and Symbol.species lookup --- .../prototype/finally/species-constructor.js | 25 +++++++++++++++++++ .../prototype/finally/species-symbol.js | 20 +++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/built-ins/Promise/prototype/finally/species-constructor.js create mode 100644 test/built-ins/Promise/prototype/finally/species-symbol.js diff --git a/test/built-ins/Promise/prototype/finally/species-constructor.js b/test/built-ins/Promise/prototype/finally/species-constructor.js new file mode 100644 index 0000000000..24a7726820 --- /dev/null +++ b/test/built-ins/Promise/prototype/finally/species-constructor.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 V8. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Sathya Gunasekaran +description: finally calls the SpeciesConstructor +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); + } +} + +new FooPromise(r => r()) + .finally(() => {}) + .then(() => { + assert.sameValue(count, 6, "6 new promises were created"); + $DONE(); +}); diff --git a/test/built-ins/Promise/prototype/finally/species-symbol.js b/test/built-ins/Promise/prototype/finally/species-symbol.js new file mode 100644 index 0000000000..b29e47bfd9 --- /dev/null +++ b/test/built-ins/Promise/prototype/finally/species-symbol.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 V8. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Sathya Gunasekaran +description: finally calls the SpeciesConstructor +esid: sec-promise.prototype.finally +features: [Promise.prototype.finally] +---*/ + + +class MyPromise extends Promise { + static get [Symbol.species]() { return Promise; } +} + +var p = Promise + .resolve() + .finally(() => MyPromise.resolve()); + +assert.sameValue(true, p instanceof Promise); +assert.sameValue(false, p instanceof MyPromise);