Commit 6cd8535c authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[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}
parent 2c63060f
......@@ -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);
......
......@@ -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],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment