mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 21:45:04 +02:00
Promise.prototype.finally calls PromiseResolved: add resolved promise test
This commit is contained in:
parent
b25e36cdb6
commit
a841f07a11
45
test/built-ins/Promise/prototype/finally/resolved-observable-then-calls-PromiseResolve.js
vendored
Normal file
45
test/built-ins/Promise/prototype/finally/resolved-observable-then-calls-PromiseResolve.js
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-thenfinallyfunctions
|
||||||
|
description: >
|
||||||
|
PromiseResolve() avoids extra Promise capability creation.
|
||||||
|
info: |
|
||||||
|
Then Finally Functions
|
||||||
|
|
||||||
|
[...]
|
||||||
|
7. Let promise be ? PromiseResolve(C, result).
|
||||||
|
8. Let valueThunk be equivalent to a function that returns value.
|
||||||
|
9. Return ? Invoke(promise, "then", « valueThunk »).
|
||||||
|
|
||||||
|
PromiseResolve ( C, x )
|
||||||
|
|
||||||
|
1. Assert: Type(C) is Object.
|
||||||
|
2. If IsPromise(x) is true, then
|
||||||
|
a. Let xConstructor be ? Get(x, "constructor").
|
||||||
|
b. If SameValue(xConstructor, C) is true, return x.
|
||||||
|
features: [Promise.prototype.finally]
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class MyPromise extends Promise {}
|
||||||
|
|
||||||
|
var mp1Value = {};
|
||||||
|
var mp1 = MyPromise.resolve(mp1Value);
|
||||||
|
var mp2 = MyPromise.resolve(42);
|
||||||
|
|
||||||
|
var thenCalls = [];
|
||||||
|
var then = Promise.prototype.then;
|
||||||
|
Promise.prototype.then = function(resolve, reject) {
|
||||||
|
thenCalls.push({promise: this, resolve, reject});
|
||||||
|
return then.call(this, resolve, reject);
|
||||||
|
};
|
||||||
|
|
||||||
|
mp1.finally(() => mp2).then(() => {
|
||||||
|
assert.sameValue(thenCalls.length, 5);
|
||||||
|
|
||||||
|
var mp2Calls = thenCalls.filter(c => c.promise === mp2);
|
||||||
|
assert.sameValue(mp2Calls.length, 1);
|
||||||
|
assert.sameValue(mp2Calls[0].reject, undefined);
|
||||||
|
assert.sameValue(mp2Calls[0].resolve(), mp1Value);
|
||||||
|
}).then($DONE, $DONE);
|
Loading…
x
Reference in New Issue
Block a user