}
+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);
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);
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()))
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;
--- /dev/null
+// 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);