Commit 37735851 authored by littledan's avatar littledan Committed by Commit bot

Make Promise.all/Promise.race catch prediction conditional on DevTools

To improve performance, this patch makes Promise.all and Promise.race not
perform correct catch prediction when the debugger is not open. The case
may come up if Promise.race or Promise.all is called, then DevTools is
open, then a component Promise is rejected. In this case, the user would
falsely get an exception event even if the "pause on caught exceptions"
box is unchecked. There are tests which triggered this case; however, it
seems both unlikely and and acceptable to have an event in this case.
Many analogous events are already produced when DevTools is enabled
during the operation of a program.

BUG=v8:3093

Review-Url: https://codereview.chromium.org/2350363002
Cr-Commit-Position: refs/heads/master@{#39565}
parent 1b414e28
......@@ -480,7 +480,10 @@ function PromiseAll(iterable) {
// For catch prediction, don't treat the .then calls as handling it;
// instead, recurse outwards.
SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true);
var instrumenting = DEBUG_IS_ACTIVE;
if (instrumenting) {
SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true);
}
function CreateResolveElementFunction(index, values, promiseCapability) {
var alreadyCalled = false;
......@@ -507,7 +510,7 @@ function PromiseAll(iterable) {
deferred.reject);
// For catch prediction, mark that rejections here are semantically
// handled by the combined Promise.
if (IsPromise(throwawayPromise)) {
if (instrumenting && IsPromise(throwawayPromise)) {
SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise);
}
++i;
......@@ -539,7 +542,10 @@ function PromiseRace(iterable) {
// For catch prediction, don't treat the .then calls as handling it;
// instead, recurse outwards.
SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true);
var instrumenting = DEBUG_IS_ACTIVE;
if (instrumenting) {
SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true);
}
try {
for (var value of iterable) {
......@@ -547,7 +553,7 @@ function PromiseRace(iterable) {
deferred.reject);
// For catch prediction, mark that rejections here are semantically
// handled by the combined Promise.
if (IsPromise(throwawayPromise)) {
if (instrumenting && IsPromise(throwawayPromise)) {
SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise);
}
}
......
......@@ -16,19 +16,6 @@ var Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
log.push("throw");
throw new Error("uncaught"); // event
});
p2.name = "p2";
var p3 = Promise.all([p2]);
p3.name = "p3";
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
......@@ -48,6 +35,19 @@ function listener(event, exec_state, event_data, data) {
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
log.push("throw");
throw new Error("uncaught"); // event
});
p2.name = "p2";
var p3 = Promise.all([p2]);
p3.name = "p3";
log.push("end main");
function testDone(iteration) {
......
......@@ -16,19 +16,6 @@ var Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
log.push("throw");
throw new Error("uncaught"); // event
});
p2.name = "p2";
var p3 = Promise.race([p2]);
p3.name = "p3";
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
......@@ -48,6 +35,19 @@ function listener(event, exec_state, event_data, data) {
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
log.push("throw");
throw new Error("uncaught"); // event
});
p2.name = "p2";
var p3 = Promise.race([p2]);
p3.name = "p3";
log.push("end main");
function testDone(iteration) {
......
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