Commit a68ad56c authored by yangguo's avatar yangguo Committed by Commit bot

Debugger: correctly find closure to recompile eval for debugging.

R=mstarzinger@chromium.org
BUG=chromium:517592
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#30104}
parent 75e43a66
......@@ -1017,11 +1017,16 @@ bool CompileForDebugging(CompilationInfo* info) {
}
static inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) {
return shared->is_toplevel() && shared->script()->IsScript() &&
Script::cast(shared->script())->compilation_type() ==
Script::COMPILATION_TYPE_EVAL;
}
bool Compiler::CompileDebugCode(Handle<JSFunction> function) {
Handle<SharedFunctionInfo> shared(function->shared());
if (shared->is_toplevel() && shared->script()->IsScript() &&
Script::cast(shared->script())->compilation_type() ==
Script::COMPILATION_TYPE_EVAL) {
if (IsEvalToplevel(shared)) {
return CompileEvalForDebugging(function, shared);
} else {
CompilationInfoWithZone info(function);
......@@ -1032,6 +1037,7 @@ bool Compiler::CompileDebugCode(Handle<JSFunction> function) {
bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) {
DCHECK(shared->allows_lazy_compilation_without_context());
DCHECK(!IsEvalToplevel(shared));
Zone zone;
ParseInfo parse_info(&zone, shared);
CompilationInfo info(&parse_info);
......@@ -1142,6 +1148,10 @@ static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
SharedFunctionInfo::InitFromFunctionLiteral(result, lit);
SharedFunctionInfo::SetScript(result, script);
result->set_is_toplevel(true);
if (info->is_eval()) {
// Eval scripts cannot be (re-)compiled without context.
result->set_allows_lazy_compilation_without_context(false);
}
Handle<String> script_name = script->name()->IsString()
? Handle<String>(String::cast(script->name()))
......
......@@ -1528,10 +1528,12 @@ class SharedFunctionInfoFinder {
if (current_candidate_ != NULL) {
if (current_start_position_ == start_position &&
shared->end_position() == current_candidate_->end_position()) {
// If we already have a matching closure, do not throw it away.
if (current_candidate_closure_ != NULL && closure == NULL) return;
// If a top-level function contains only one function
// declaration the source for the top-level and the function
// is the same. In that case prefer the non top-level function.
if (shared->is_toplevel()) return;
if (!current_candidate_->is_toplevel() && shared->is_toplevel()) return;
} else if (start_position < current_start_position_ ||
current_candidate_->end_position() < shared->end_position()) {
return;
......
// Copyright 2015 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 --min-preparse-length=10
var source =
"var foo = function foo() {\n" +
" return 1;\n" +
"}\n" +
"//@ sourceURL=test";
Debug = debug.Debug;
Debug.setListener(listener);
var exception = null;
var break_count = 0;
function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.Break) break_count++;
if (event != Debug.DebugEvent.AfterCompile) return;
try {
var name = event_data.script().name();
var id = event_data.script().id();
assertEquals("test", name);
Debug.setScriptBreakPointById(id, 2);
} catch (e) {
exception = e;
}
}
eval(source);
assertEquals(0, break_count);
foo();
assertEquals(1, break_count);
assertNull(exception);
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