Jordan Harband 2018-01-24 22:20:44 -08:00 committed by Rick Waldron
parent 8b71c5fea5
commit 7c5b5bf750
6 changed files with 98 additions and 2 deletions

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
author: Sathya Gunasekaran 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 esid: sec-promise.prototype.finally
features: [Promise.prototype.finally] features: [Promise.prototype.finally]
flags: [async] flags: [async]
@ -22,4 +22,4 @@ new FooPromise(r => r())
.then(() => { .then(() => {
assert.sameValue(count, 6, "6 new promises were created"); assert.sameValue(count, 6, "6 new promises were created");
$DONE(); $DONE();
}); }, $ERROR);

View File

@ -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();
});

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;