From ad4e8a27963b704bb70ec8bac0991c57296b1d16 Mon Sep 17 00:00:00 2001 From: yangguo Date: Thu, 14 Apr 2016 03:07:49 -0700 Subject: [PATCH] Correctly annotate eval origin. There were a couple of issues with it: - interpreter is not supported - the source position was just accidentally correct for full-codegen - the eval origin could have been cached Also fixes a few other places to use AbstractCode. R=mstarzinger@chromium.org Committed: https://crrev.com/2f3a171adc9e620c2235bf0562145b9d4eaba66d Cr-Commit-Position: refs/heads/master@{#35257} Review URL: https://codereview.chromium.org/1854713002 Cr-Commit-Position: refs/heads/master@{#35481} --- src/accessors.cc | 7 +--- src/api.cc | 12 +++--- src/builtins.cc | 17 +++++++-- src/compiler.cc | 15 +++++--- src/compiler.h | 4 +- src/compiler/ast-graph-builder.cc | 2 +- src/debug/debug-evaluate.cc | 10 ++--- src/debug/debug-frames.cc | 3 +- src/debug/debug.cc | 33 +++-------------- src/debug/debug.h | 3 -- src/debug/liveedit.cc | 3 +- src/factory.cc | 2 +- src/frames.cc | 12 ++++-- src/frames.h | 9 +++-- src/full-codegen/arm/full-codegen-arm.cc | 12 +++--- src/full-codegen/arm64/full-codegen-arm64.cc | 12 +++--- src/full-codegen/full-codegen.h | 2 +- src/full-codegen/ia32/full-codegen-ia32.cc | 12 +++--- src/full-codegen/mips/full-codegen-mips.cc | 12 +++--- .../mips64/full-codegen-mips64.cc | 12 +++--- src/full-codegen/ppc/full-codegen-ppc.cc | 12 +++--- src/full-codegen/s390/full-codegen-s390.cc | 11 +++--- src/full-codegen/x64/full-codegen-x64.cc | 12 +++--- src/full-codegen/x87/full-codegen-x87.cc | 12 +++--- src/heap/heap.cc | 6 +-- src/interpreter/bytecode-generator.cc | 3 +- src/objects-inl.h | 3 +- src/objects-printer.cc | 3 +- src/objects.h | 10 ++--- src/runtime/runtime-compiler.cc | 5 +-- .../CallLookupSlot.golden | 2 +- .../bytecode_expectations/Eval.golden | 2 +- .../bytecode_expectations/LookupSlot.golden | 6 +-- test/mjsunit/eval-origin.js | 37 +++++++++++++++++++ 34 files changed, 173 insertions(+), 145 deletions(-) create mode 100644 test/mjsunit/eval-origin.js diff --git a/src/accessors.cc b/src/accessors.cc index 73b225dba4..dcf0ce86f9 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -661,11 +661,8 @@ void Accessors::ScriptEvalFromScriptPositionGetter( Script::cast(Handle::cast(object)->value()), isolate); Handle result = isolate->factory()->undefined_value(); if (script->compilation_type() == Script::COMPILATION_TYPE_EVAL) { - Handle code(SharedFunctionInfo::cast( - script->eval_from_shared())->code()); - result = Handle(Smi::FromInt(code->SourcePosition( - script->eval_from_instructions_offset())), - isolate); + result = + Handle(Smi::FromInt(script->eval_from_position()), isolate); } info.GetReturnValue().Set(Utils::ToLocal(result)); } diff --git a/src/api.cc b/src/api.cc index 5aea799847..17502bce90 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2034,6 +2034,7 @@ MaybeLocal ScriptCompiler::CompileFunctionInContext( } i::Handle name_obj; + int eval_position = 0; int line_offset = 0; int column_offset = 0; if (!source->resource_name.IsEmpty()) { @@ -2046,11 +2047,12 @@ MaybeLocal ScriptCompiler::CompileFunctionInContext( column_offset = static_cast(source->resource_column_offset->Value()); } i::Handle fun; - has_pending_exception = !i::Compiler::GetFunctionFromEval( - source_string, outer_info, context, i::SLOPPY, - i::ONLY_SINGLE_FUNCTION_LITERAL, line_offset, - column_offset - scope_position, name_obj, - source->resource_options).ToHandle(&fun); + has_pending_exception = + !i::Compiler::GetFunctionFromEval( + source_string, outer_info, context, i::SLOPPY, + i::ONLY_SINGLE_FUNCTION_LITERAL, eval_position, line_offset, + column_offset - scope_position, name_obj, source->resource_options) + .ToHandle(&fun); if (has_pending_exception) { isolate->ReportPendingMessages(); } diff --git a/src/builtins.cc b/src/builtins.cc index d054916db0..577ab0a116 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -2068,11 +2068,20 @@ MaybeHandle CompileString(Handle context, } // Compile source string in the native context. - Handle outer_info(native_context->closure()->shared(), - isolate); + StackTraceFrameIterator it(isolate); + int pos = RelocInfo::kNoPosition; + Handle outer_info; + if (!it.done() && it.is_javascript()) { + FrameSummary summary = FrameSummary::GetFirst(it.javascript_frame()); + pos = summary.abstract_code()->SourcePosition(summary.code_offset()); + outer_info = Handle(summary.function()->shared()); + } else { + outer_info = + Handle(native_context->closure()->shared()); + } + return Compiler::GetFunctionFromEval(source, outer_info, native_context, - SLOPPY, restriction, - RelocInfo::kNoPosition); + SLOPPY, restriction, pos); } } // namespace diff --git a/src/compiler.cc b/src/compiler.cc index 35cb918085..6fb58e3bb4 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -1250,8 +1250,9 @@ void Compiler::CompileForLiveEdit(Handle