`Promise.prototype.finally` thunks have a length of 0

This commit is contained in:
Jordan Harband 2020-02-05 13:00:01 -10:00 committed by Rick Waldron
parent 5c9b5ed610
commit 0ebbdf0395
2 changed files with 32 additions and 14 deletions

View File

@ -21,12 +21,22 @@ Promise.reject(new Test262Error())
.finally(function() {})
.then($DONE, $DONE);
var then = Promise.prototype.then;
Promise.prototype.then = function(thrower) {
assert(!isConstructor(thrower));
assert.sameValue(thrower.length, 1);
assert.sameValue(thrower.name, '');
assert.throws(Test262Error, thrower);
var calls = 0;
var expected = [
{ length: 0, name: '' },
{ length: 1, name: '' }
];
return then.call(this, thrower);
var then = Promise.prototype.then;
Promise.prototype.then = function(resolve) {
assert(!isConstructor(resolve));
assert.sameValue(resolve.length, expected[calls].length);
assert.sameValue(resolve.name, expected[calls].name);
if (calls === 0) {
assert.throws(Test262Error, resolve);
}
calls += 1;
return then.call(this, resolve);
};

View File

@ -23,12 +23,20 @@ Promise.resolve(value)
.finally(function() {})
.then($DONE, $DONE);
var then = Promise.prototype.then;
Promise.prototype.then = function(valueThunk) {
assert(!isConstructor(valueThunk));
assert.sameValue(valueThunk.length, 1);
assert.sameValue(valueThunk.name, '');
assert.sameValue(valueThunk(), value);
var calls = 0;
var expected = [
{ length: 0, name: '' },
{ length: 1, name: '' }
];
return then.call(this, valueThunk);
var then = Promise.prototype.then;
Promise.prototype.then = function(resolve) {
assert(!isConstructor(resolve));
assert.sameValue(resolve.length, expected[calls].length);
assert.sameValue(resolve.name, expected[calls].name);
if (calls === 0) {
assert.sameValue(resolve(), value);
}
return then.call(this, resolve);
};