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() {}) .finally(function() {})
.then($DONE, $DONE); .then($DONE, $DONE);
var then = Promise.prototype.then; var calls = 0;
Promise.prototype.then = function(thrower) { var expected = [
assert(!isConstructor(thrower)); { length: 0, name: '' },
assert.sameValue(thrower.length, 1); { length: 1, name: '' }
assert.sameValue(thrower.name, ''); ];
assert.throws(Test262Error, thrower);
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() {}) .finally(function() {})
.then($DONE, $DONE); .then($DONE, $DONE);
var then = Promise.prototype.then; var calls = 0;
Promise.prototype.then = function(valueThunk) { var expected = [
assert(!isConstructor(valueThunk)); { length: 0, name: '' },
assert.sameValue(valueThunk.length, 1); { length: 1, name: '' }
assert.sameValue(valueThunk.name, ''); ];
assert.sameValue(valueThunk(), value);
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);
}; };