Commit 1dcd1c9f authored by Ingvar Stepanyan's avatar Ingvar Stepanyan Committed by Commit Bot

Report late-bound scripts to the debugger

Previously, if an unbound script was created in a non-inspected context,
but later bound to an inspected one, it never appeared in the
debugger sources.

After this change `OnAfterCompile` will be invoked not on the original
script compilation, but when it's actually bound to a context for
execution, which means `Debugger.scriptParsed` will be now sent to the
inspector even for such precompiled scripts.

R=jgruber@chromium.org, kozyatinskiy@chromium.org, yangguo@chromium.org

Bug: v8:7654
Change-Id: Ice13312e425903fb2baf14edab5c566d649a6438
Reviewed-on: https://chromium-review.googlesource.com/1013581Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52652}
parent 3539c22d
...@@ -32,6 +32,7 @@ Facebook, Inc. <*@fb.com> ...@@ -32,6 +32,7 @@ Facebook, Inc. <*@fb.com>
Facebook, Inc. <*@oculus.com> Facebook, Inc. <*@oculus.com>
Vewd Software AS <*@vewd.com> Vewd Software AS <*@vewd.com>
Groupon <*@groupon.com> Groupon <*@groupon.com>
Cloudflare, Inc. <*@cloudflare.com>
Aaron Bieber <deftly@gmail.com> Aaron Bieber <deftly@gmail.com>
Abdulla Kamar <abdulla.kamar@gmail.com> Abdulla Kamar <abdulla.kamar@gmail.com>
......
...@@ -1356,11 +1356,6 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( ...@@ -1356,11 +1356,6 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
} }
} }
// OnAfterCompile has to be called after we create the JSFunction, which we
// may require to recompile the eval for debugging, if we find a function
// that contains break points in the eval script.
isolate->debug()->OnAfterCompile(script);
return result; return result;
} }
...@@ -1731,12 +1726,6 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript( ...@@ -1731,12 +1726,6 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
} }
} }
// On success, report script compilation to debugger.
Handle<SharedFunctionInfo> result;
if (maybe_result.ToHandle(&result)) {
isolate->debug()->OnAfterCompile(handle(Script::cast(result->script())));
}
return maybe_result; return maybe_result;
} }
...@@ -1815,14 +1804,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction( ...@@ -1815,14 +1804,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
script = Handle<Script>(Script::cast(wrapped->script()), isolate); script = Handle<Script>(Script::cast(wrapped->script()), isolate);
} }
Handle<JSFunction> function = return isolate->factory()->NewFunctionFromSharedFunctionInfo(wrapped, context,
isolate->factory()->NewFunctionFromSharedFunctionInfo(wrapped, context,
NOT_TENURED); NOT_TENURED);
// OnAfterCompile has to be called after we create the JSFunction, which we
// may require to recompile the eval for debugging, if we find a function
// that contains break points in the eval script.
isolate->debug()->OnAfterCompile(script);
return function;
} }
ScriptCompiler::ScriptStreamingTask* Compiler::NewBackgroundCompileTask( ScriptCompiler::ScriptStreamingTask* Compiler::NewBackgroundCompileTask(
...@@ -1892,12 +1875,6 @@ Compiler::GetSharedFunctionInfoForStreamedScript( ...@@ -1892,12 +1875,6 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
} }
} }
// On success, report script compilation to debugger.
Handle<SharedFunctionInfo> result;
if (maybe_result.ToHandle(&result)) {
isolate->debug()->OnAfterCompile(handle(Script::cast(result->script())));
}
streaming_data->Release(); streaming_data->Release();
return maybe_result; return maybe_result;
} }
......
...@@ -2254,6 +2254,11 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( ...@@ -2254,6 +2254,11 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
Compiler::PostInstantiation(result, pretenure); Compiler::PostInstantiation(result, pretenure);
} }
if (info->is_toplevel() || info->is_wrapped()) {
// Report script compilation to debugger.
isolate()->debug()->OnAfterCompile(handle(Script::cast(info->script())));
}
return result; return result;
} }
...@@ -2288,6 +2293,11 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( ...@@ -2288,6 +2293,11 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
Compiler::PostInstantiation(result, pretenure); Compiler::PostInstantiation(result, pretenure);
} }
if (info->is_toplevel() || info->is_wrapped()) {
// Report script compilation to debugger.
isolate()->debug()->OnAfterCompile(handle(Script::cast(info->script())));
}
return result; return result;
} }
......
...@@ -5471,6 +5471,27 @@ TEST(ExceptionEventWhenEventListenerIsReset) { ...@@ -5471,6 +5471,27 @@ TEST(ExceptionEventWhenEventListenerIsReset) {
} }
// Tests that script is reported as compiled when bound to context.
TEST(AfterCompileEventOnBindToContext) {
DebugLocalContext env;
v8::Isolate* isolate = env->GetIsolate();
SetDebugEventListener(isolate, AfterCompileEventListener);
const char* source = "var a=1";
v8::ScriptCompiler::Source script_source(
v8::String::NewFromUtf8(isolate, source, v8::NewStringType::kNormal)
.ToLocalChecked());
v8::Local<v8::UnboundScript> unbound =
v8::ScriptCompiler::CompileUnboundScript(isolate, &script_source)
.ToLocalChecked();
CHECK_EQ(after_compile_event_count, 0);
unbound->BindToCurrentContext();
CHECK_EQ(after_compile_event_count, 1);
}
static void BreakEventListener(const v8::Debug::EventDetails& details) { static void BreakEventListener(const v8::Debug::EventDetails& details) {
if (details.GetEvent() == v8::Break) break_point_hit_count++; if (details.GetEvent() == v8::Break) break_point_hit_count++;
} }
......
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