Reviewers: Yang,
Description:
Take the ScriptOrigin into account for CompileFunctionInContext
BUG=none
[email protected]
LOG=n
Please review this at https://codereview.chromium.org/952893006/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+66, -5 lines):
M src/api.cc
M src/compiler.h
M src/compiler.cc
M test/cctest/test-compiler.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
fbbb5223f2939d6f37065ebdb832a387b363a348..ab82ea58af98ea1292c1efaf8691b13cdad10cef
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1705,9 +1705,32 @@ Local<Function>
ScriptCompiler::CompileFunctionInContext(
}
EXCEPTION_PREAMBLE(isolate);
+ i::Handle<i::Object> name_obj;
+ int line_offset = 0;
+ int column_offset = 0;
+ bool is_embedder_debug_script = false;
+ bool is_shared_cross_origin = false;
+ if (!source->resource_name.IsEmpty()) {
+ name_obj = Utils::OpenHandle(*(source->resource_name));
+ }
+ if (!source->resource_line_offset.IsEmpty()) {
+ line_offset = static_cast<int>(source->resource_line_offset->Value());
+ }
+ if (!source->resource_column_offset.IsEmpty()) {
+ column_offset =
static_cast<int>(source->resource_column_offset->Value());
+ }
+ if (!source->resource_is_shared_cross_origin.IsEmpty()) {
+ is_shared_cross_origin =
source->resource_is_shared_cross_origin->IsTrue();
+ }
+ if (!source->resource_is_embedder_debug_script.IsEmpty()) {
+ is_embedder_debug_script =
+ source->resource_is_embedder_debug_script->IsTrue();
+ }
i::MaybeHandle<i::JSFunction> maybe_fun =
i::Compiler::GetFunctionFromEval(
source_string, outer_info, context, i::SLOPPY,
- i::ONLY_SINGLE_FUNCTION_LITERAL, scope_position);
+ i::ONLY_SINGLE_FUNCTION_LITERAL, line_offset,
+ column_offset - scope_position, name_obj, is_embedder_debug_script,
+ is_shared_cross_origin);
i::Handle<i::JSFunction> fun;
has_pending_exception = !maybe_fun.ToHandle(&fun);
EXCEPTION_BAILOUT_CHECK(isolate, Local<Function>());
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index
f3f8dbd086d3288d5e51214f8cdc8a3880367203..b881b18669d19aa88bf5e9b686f31f711873440c
100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -1206,7 +1206,9 @@ static Handle<SharedFunctionInfo>
CompileToplevel(CompilationInfo* info) {
MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
Handle<Context> context, LanguageMode language_mode,
- ParseRestriction restriction, int scope_position) {
+ ParseRestriction restriction, int line_offset, int column_offset,
+ Handle<Object> script_name, bool is_embedder_debug_script,
+ bool is_shared_cross_origin) {
Isolate* isolate = source->GetIsolate();
int source_length = source->length();
isolate->counters()->total_eval_size()->Increment(source_length);
@@ -1215,11 +1217,18 @@ MaybeHandle<JSFunction>
Compiler::GetFunctionFromEval(
CompilationCache* compilation_cache = isolate->compilation_cache();
MaybeHandle<SharedFunctionInfo> maybe_shared_info =
compilation_cache->LookupEval(source, outer_info, context,
language_mode,
- scope_position);
+ line_offset);
Handle<SharedFunctionInfo> shared_info;
if (!maybe_shared_info.ToHandle(&shared_info)) {
Handle<Script> script = isolate->factory()->NewScript(source);
+ if (!script_name.is_null()) {
+ script->set_name(*script_name);
+ script->set_line_offset(Smi::FromInt(line_offset));
+ script->set_column_offset(Smi::FromInt(column_offset));
+ }
+ script->set_is_shared_cross_origin(is_shared_cross_origin);
+ script->set_is_embedder_debug_script(is_embedder_debug_script);
CompilationInfoWithZone info(script);
info.MarkAsEval();
if (context->IsNativeContext()) info.MarkAsGlobal();
@@ -1245,7 +1254,7 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
is_strict(shared_info->language_mode()));
if (!shared_info->dont_cache()) {
compilation_cache->PutEval(source, outer_info, context,
shared_info,
- scope_position);
+ line_offset);
}
}
} else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
Index: src/compiler.h
diff --git a/src/compiler.h b/src/compiler.h
index
8ef2e0a95b3ca19813347b7de738f1a1ae6a1cfe..7f063ea22217d74cf948a9a741ef84f9d0353b3b
100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -801,7 +801,10 @@ class Compiler : public AllStatic {
MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval(
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
Handle<Context> context, LanguageMode language_mode,
- ParseRestriction restriction, int scope_position);
+ ParseRestriction restriction, int line_offset, int column_offset = 0,
+ Handle<Object> script_name = Handle<Object>(),
+ bool is_embedder_debug_script = false,
+ bool is_shared_cross_origin = false);
// Compile a String source within a context.
static Handle<SharedFunctionInfo> CompileScript(
Index: test/cctest/test-compiler.cc
diff --git a/test/cctest/test-compiler.cc b/test/cctest/test-compiler.cc
index
faf533239e504b0b411c49b6f97175b50653faf6..338c5bcba8698176dc045e8f67413c489b2f7970
100644
--- a/test/cctest/test-compiler.cc
+++ b/test/cctest/test-compiler.cc
@@ -514,6 +514,32 @@ TEST(CompileFunctionInContextNonIdentifierArgs) {
}
+TEST(CompileFunctionInContextScriptOrigin) {
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::ScriptOrigin origin(v8_str("test"),
+ v8::Integer::New(CcTest::isolate(), 22),
+ v8::Integer::New(CcTest::isolate(), 41));
+ v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"),
origin);
+ v8::Local<v8::Function> fun =
v8::ScriptCompiler::CompileFunctionInContext(
+ CcTest::isolate(), &script_source, env.local(), 0, NULL, 0, NULL);
+ CHECK(!fun.IsEmpty());
+ v8::TryCatch try_catch;
+ CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true);
+ fun->Call(env->Global(), 0, NULL);
+ CHECK(try_catch.HasCaught());
+ CHECK(!try_catch.Exception().IsEmpty());
+ v8::Local<v8::StackTrace> stack =
+ v8::Exception::GetStackTrace(try_catch.Exception());
+ CHECK(!stack.IsEmpty());
+ CHECK(stack->GetFrameCount() > 0);
+ v8::Local<v8::StackFrame> frame = stack->GetFrame(0);
+ CHECK_EQ(23, frame->GetLineNumber());
+ CHECK_EQ(42 + strlen("throw "),
static_cast<unsigned>(frame->GetColumn()));
+}
+
+
#ifdef ENABLE_DISASSEMBLER
static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
const char* property_name) {
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.