Commit affe4c03 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[V8] Report v8::AfterCompile and v8::CompileError to listener on pause

V8 didn't report compile events on pause before this patch. These events can be important for listener. For example, DevTools allows user to execute some JS code on pause and needs to show correct stack trace in message from it.

BUG=396013
R=yurys@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25767}
parent 1b316ed0
...@@ -2630,8 +2630,12 @@ void Debug::OnException(Handle<Object> exception, bool uncaught, ...@@ -2630,8 +2630,12 @@ void Debug::OnException(Handle<Object> exception, bool uncaught,
void Debug::OnCompileError(Handle<Script> script) { void Debug::OnCompileError(Handle<Script> script) {
// No more to do if not debugging. if (ignore_events()) return;
if (in_debug_scope() || ignore_events()) return;
if (in_debug_scope()) {
ProcessCompileEventInDebugScope(v8::CompileError, script);
return;
}
HandleScope scope(isolate_); HandleScope scope(isolate_);
DebugScope debug_scope(this); DebugScope debug_scope(this);
...@@ -2692,8 +2696,12 @@ void Debug::OnAfterCompile(Handle<Script> script) { ...@@ -2692,8 +2696,12 @@ void Debug::OnAfterCompile(Handle<Script> script) {
// Add the newly compiled script to the script cache. // Add the newly compiled script to the script cache.
if (script_cache_ != NULL) script_cache_->Add(script); if (script_cache_ != NULL) script_cache_->Add(script);
// No more to do if not debugging. if (ignore_events()) return;
if (in_debug_scope() || ignore_events()) return;
if (in_debug_scope()) {
ProcessCompileEventInDebugScope(v8::AfterCompile, script);
return;
}
HandleScope scope(isolate_); HandleScope scope(isolate_);
DebugScope debug_scope(this); DebugScope debug_scope(this);
...@@ -2848,6 +2856,27 @@ void Debug::CallEventCallback(v8::DebugEvent event, ...@@ -2848,6 +2856,27 @@ void Debug::CallEventCallback(v8::DebugEvent event,
} }
void Debug::ProcessCompileEventInDebugScope(v8::DebugEvent event,
Handle<Script> script) {
if (event_listener_.is_null()) return;
SuppressDebug while_processing(this);
DebugScope debug_scope(this);
if (debug_scope.failed()) return;
Handle<Object> event_data;
// Bail out and don't call debugger if exception.
if (!MakeCompileEvent(script, event).ToHandle(&event_data)) return;
// Create the execution state.
Handle<Object> exec_state;
// Bail out and don't call debugger if exception.
if (!MakeExecutionState().ToHandle(&exec_state)) return;
CallEventCallback(event, exec_state, event_data, NULL);
}
Handle<Context> Debug::GetDebugContext() { Handle<Context> Debug::GetDebugContext() {
DebugScope debug_scope(this); DebugScope debug_scope(this);
// The global handle may be destroyed soon after. Return it reboxed. // The global handle may be destroyed soon after. Return it reboxed.
......
...@@ -553,6 +553,8 @@ class Debug { ...@@ -553,6 +553,8 @@ class Debug {
Handle<Object> exec_state, Handle<Object> exec_state,
Handle<Object> event_data, Handle<Object> event_data,
v8::Debug::ClientData* client_data); v8::Debug::ClientData* client_data);
void ProcessCompileEventInDebugScope(v8::DebugEvent event,
Handle<Script> script);
void ProcessDebugEvent(v8::DebugEvent event, void ProcessDebugEvent(v8::DebugEvent event,
Handle<JSObject> event_data, Handle<JSObject> event_data,
bool auto_continue); bool auto_continue);
......
...@@ -36,13 +36,17 @@ var exception = false; ...@@ -36,13 +36,17 @@ var exception = false;
var base_request = '"seq":0,"type":"request","command":"clearbreakpointgroup"'; var base_request = '"seq":0,"type":"request","command":"clearbreakpointgroup"';
var scriptId = null; var scriptId = null;
var muteListener = false;
function safeEval(code) { function safeEval(code) {
try { try {
muteListener = true;
return eval('(' + code + ')'); return eval('(' + code + ')');
} catch (e) { } catch (e) {
assertEquals(void 0, e); assertEquals(void 0, e);
return undefined; return undefined;
} finally {
muteListener = false;
} }
} }
...@@ -58,6 +62,7 @@ function testArguments(dcp, arguments, success) { ...@@ -58,6 +62,7 @@ function testArguments(dcp, arguments, success) {
} }
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
if (muteListener) return;
try { try {
if (event == Debug.DebugEvent.Break) { if (event == Debug.DebugEvent.Break) {
// Get the debug command processor. // Get the debug command processor.
......
...@@ -37,7 +37,7 @@ var current_source = ''; // Current source being compiled. ...@@ -37,7 +37,7 @@ var current_source = ''; // Current source being compiled.
var source_count = 0; // Total number of scources compiled. var source_count = 0; // Total number of scources compiled.
var host_compilations = 0; // Number of scources compiled through the API. var host_compilations = 0; // Number of scources compiled through the API.
var eval_compilations = 0; // Number of scources compiled through eval. var eval_compilations = 0; // Number of scources compiled through eval.
var mute_listener = false;
function compileSource(source) { function compileSource(source) {
current_source = source; current_source = source;
...@@ -45,8 +45,20 @@ function compileSource(source) { ...@@ -45,8 +45,20 @@ function compileSource(source) {
source_count++; source_count++;
} }
function safeEval(code) {
try {
mute_listener = true;
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
} finally {
mute_listener = false;
}
}
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
if (mute_listener) return;
try { try {
if (event == Debug.DebugEvent.BeforeCompile || if (event == Debug.DebugEvent.BeforeCompile ||
event == Debug.DebugEvent.AfterCompile || event == Debug.DebugEvent.AfterCompile ||
...@@ -81,7 +93,7 @@ function listener(event, exec_state, event_data, data) { ...@@ -81,7 +93,7 @@ function listener(event, exec_state, event_data, data) {
} }
// Check that script context is included into the event message. // Check that script context is included into the event message.
var json = event_data.toJSONProtocol(); var json = event_data.toJSONProtocol();
var msg = eval('(' + json + ')'); var msg = safeEval(json);
assertTrue('context' in msg.body.script); assertTrue('context' in msg.body.script);
// Check that we pick script name from //# sourceURL, iff present // Check that we pick script name from //# sourceURL, iff present
......
...@@ -32,6 +32,7 @@ Debug = debug.Debug ...@@ -32,6 +32,7 @@ Debug = debug.Debug
var evaluate_callback; var evaluate_callback;
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
if (event !== Debug.DebugEvent.Break) return;
try { try {
var context = { what_is_capybara: "a fish" }; var context = { what_is_capybara: "a fish" };
var context2 = { what_is_capybara: "a fish", what_is_parrot: "a beard" }; var context2 = { what_is_capybara: "a fish", what_is_parrot: "a beard" };
......
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