Simplify promise event on throw handling.
R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/991833002 Cr-Commit-Position: refs/heads/master@{#27074}
This commit is contained in:
parent
ded6ffbb2a
commit
9dedcc3dfc
@ -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;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
// 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);
|
29
test/mjsunit/es6/debug-promises/resolve-after-try-catch.js
Normal file
29
test/mjsunit/es6/debug-promises/resolve-after-try-catch.js
Normal file
@ -0,0 +1,29 @@
|
||||
// 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);
|
30
test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js
Normal file
30
test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js
Normal file
@ -0,0 +1,30 @@
|
||||
// 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);
|
Loading…
Reference in New Issue
Block a user