Commit 9dedcc3d authored by yangguo's avatar yangguo Committed by Commit bot

Simplify promise event on throw handling.

R=mstarzinger@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27074}
parent ded6ffbb
......@@ -1555,14 +1555,9 @@ Handle<Object> Isolate::GetPromiseOnStackOnThrow() {
StackHandler* promise_try = tltop->promise_on_stack_->handler();
// Find the top-most try-catch handler.
StackHandler* handler = StackHandler::FromAddress(Isolate::handler(tltop));
do {
if (handler == promise_try) {
return tltop->promise_on_stack_->promise();
}
handler = handler->next();
// Throwing inside a Promise can be intercepted by an inner try-catch, so
// we stop at the first try-catch handler.
} while (handler != NULL && !handler->is_catch());
// Throwing inside a Promise only leads to a reject if not caught by an inner
// try-catch or try-finally.
if (handler == promise_try) return tltop->promise_on_stack_->promise();
return undefined;
}
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --allow-natives-syntax
// Test debug events when we listen to all exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect a normal Exception debug event to be triggered.
Debug = debug.Debug;
var events = [];
function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status());
}
Debug.setListener(listener);
var p = new Promise(function(resolve, reject) {
do {
try {
throw new Error("reject");
} finally {
break; // No rethrow.
}
} while (false);
resolve();
});
assertEquals([0 /* create */, 1 /* resolve */], events);
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --allow-natives-syntax
// Test debug events when we listen to all exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect a normal Exception debug event to be triggered.
Debug = debug.Debug;
var events = [];
function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status());
}
Debug.setListener(listener);
var p = new Promise(function (resolve, reject) {
try {
throw new Error("reject");
} catch (e) {
}
resolve();
});
assertEquals([0 /* create */, 1 /* resolve */], events);
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --allow-natives-syntax
// Test debug events when we listen to all exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect a normal Exception debug event to be triggered.
Debug = debug.Debug;
var events = [];
function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status());
}
Debug.setListener(listener);
var p = new Promise(function(resolve, reject) {
try {
throw new Error("reject");
} finally {
// Implicit rethrow.
}
resolve();
});
assertEquals([0 /* create */, -1 /* rethrown */], events);
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