[promise] Test IsPromise() early in Promise.prototype.then()

Addresses TODO by Dan --- simply by moving the check and exception
earlier in the function, before calling NewPromiseCapability() or
loading the constructor.

BUG=v8:4633
LOG=N
R=adamk@chromium.org, littledan@chromium.org, cbruni@chromium.org

Fixes 'test262/built-ins/Promise/prototype/then/context-check-on-entry'

Review URL: https://codereview.chromium.org/1561193002

Cr-Commit-Position: refs/heads/master@{#33137}
This commit is contained in:
caitpotter88 2016-01-06 10:50:42 -08:00 committed by Commit bot
parent 2c63060f11
commit 6cd8535c3b
2 changed files with 6 additions and 7 deletions

View File

@ -274,16 +274,16 @@ function PromiseRejected(r) {
// Multi-unwrapped chaining with thenable coercion.
function PromiseThen(onResolve, onReject) {
var status = GET_PRIVATE(this, promiseStatusSymbol);
if (IS_UNDEFINED(status)) {
throw MakeTypeError(kNotAPromise, this);
}
var constructor = this.constructor;
onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler;
onReject = IS_CALLABLE(onReject) ? onReject : PromiseIdRejectHandler;
var deferred = NewPromiseCapability(constructor);
switch (GET_PRIVATE(this, promiseStatusSymbol)) {
case UNDEFINED:
// TODO(littledan): The type check should be called before
// constructing NewPromiseCapability; this is observable when
// erroneously copying this method to other classes.
throw MakeTypeError(kNotAPromise, this);
switch (status) {
case 0: // Pending
GET_PRIVATE(this, promiseOnResolveSymbol).push(onResolve, deferred);
GET_PRIVATE(this, promiseOnRejectSymbol).push(onReject, deferred);

View File

@ -415,7 +415,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=4633
'built-ins/Promise/prototype/then/deferred-is-resolved-value': [SKIP],
'built-ins/Promise/prototype/then/context-check-on-entry': [FAIL],
'built-ins/Promise/exception-after-resolve-in-executor': [FAIL],
'built-ins/Promise/reject-function-name': [FAIL],
'built-ins/Promise/reject-function-nonconstructor': [FAIL],