Skip to content

Commit e44b4b6

Browse files
ogoffartnierob
authored andcommitted
v8: Fix the script name and line number in CompileEval
Add a way to register the script name and the line/column offset in CompileEval
1 parent 3f0da95 commit e44b4b6

File tree

5 files changed

+91
-14
lines changed

5 files changed

+91
-14
lines changed

src/3rdparty/v8/src/api.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,11 +1513,28 @@ Local<Script> Script::CompileEval(v8::Handle<String> source,
15131513
ENTER_V8(isolate);
15141514
i::Handle<i::String> str = Utils::OpenHandle(*source);
15151515
i::Handle<i::Context> context(isolate->context());
1516+
1517+
i::Handle<i::Object> name_obj;
1518+
int line_offset = 0;
1519+
int column_offset = 0;
1520+
if (origin != NULL) {
1521+
if (!origin->ResourceName().IsEmpty()) {
1522+
name_obj = Utils::OpenHandle(*origin->ResourceName());
1523+
}
1524+
if (!origin->ResourceLineOffset().IsEmpty()) {
1525+
line_offset = static_cast<int>(origin->ResourceLineOffset()->Value());
1526+
}
1527+
if (!origin->ResourceColumnOffset().IsEmpty()) {
1528+
column_offset = static_cast<int>(origin->ResourceColumnOffset()->Value());
1529+
}
1530+
}
1531+
15161532
i::Handle<i::SharedFunctionInfo> shared = i::Compiler::CompileEval(
15171533
str,
15181534
context,
15191535
context->IsGlobalContext(),
1520-
i::kNonStrictMode);
1536+
i::kNonStrictMode,
1537+
name_obj, line_offset, column_offset);
15211538
if (shared.is_null())
15221539
return Local<Script>();
15231540
i::Handle<i::JSFunction> result = isolate->factory()->NewFunctionFromSharedFunctionInfo(

src/3rdparty/v8/src/compilation-cache.cc

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ bool CompilationCacheScript::HasOrigin(
148148
int line_offset,
149149
int column_offset) {
150150
Handle<Script> script =
151-
Handle<Script>(Script::cast(function_info->script()), isolate());
151+
Handle<Script>(Script::cast(function_info->script()), internal::Isolate::Current());
152152
// If the script name isn't set, the boilerplate script should have
153153
// an undefined name to have the same origin.
154154
if (name.is_null()) {
@@ -254,7 +254,11 @@ void CompilationCacheScript::Put(Handle<String> source,
254254
Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
255255
Handle<String> source,
256256
Handle<Context> context,
257-
StrictModeFlag strict_mode) {
257+
StrictModeFlag strict_mode
258+
#ifdef QT_BUILD_SCRIPT_LIB
259+
, Handle<Object> name, int line_offset, int column_offset
260+
#endif
261+
) {
258262
// Make sure not to leak the table into the surrounding handle
259263
// scope. Otherwise, we risk keeping old tables around even after
260264
// having cleared the cache.
@@ -263,9 +267,18 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
263267
{ HandleScope scope(isolate());
264268
for (generation = 0; generation < generations(); generation++) {
265269
Handle<CompilationCacheTable> table = GetTable(generation);
266-
result = table->LookupEval(*source, *context, strict_mode);
267-
if (result->IsSharedFunctionInfo()) {
268-
break;
270+
Handle<Object> probe(table->LookupEval(*source, *context, strict_mode));
271+
if (probe->IsSharedFunctionInfo()) {
272+
#ifdef QT_BUILD_SCRIPT_LIB
273+
Handle<SharedFunctionInfo> function_info =
274+
Handle<SharedFunctionInfo>::cast(probe);
275+
// Break when we've found a suitable shared function info that
276+
// matches the origin.
277+
if (CompilationCacheScript::HasOrigin(function_info, name, line_offset, column_offset)) {
278+
result = *function_info;
279+
break;
280+
}
281+
#endif
269282
}
270283
}
271284
}
@@ -393,16 +406,29 @@ Handle<SharedFunctionInfo> CompilationCache::LookupEval(
393406
Handle<String> source,
394407
Handle<Context> context,
395408
bool is_global,
396-
StrictModeFlag strict_mode) {
409+
StrictModeFlag strict_mode
410+
#ifdef QT_BUILD_SCRIPT_LIB
411+
, Handle<Object> script_name,
412+
int line_offset, int column_offset
413+
#endif
414+
) {
397415
if (!IsEnabled()) {
398416
return Handle<SharedFunctionInfo>::null();
399417
}
400418

401419
Handle<SharedFunctionInfo> result;
402420
if (is_global) {
403-
result = eval_global_.Lookup(source, context, strict_mode);
421+
result = eval_global_.Lookup(source, context, strict_mode
422+
#ifdef QT_BUILD_SCRIPT_LIB
423+
,script_name, line_offset, column_offset
424+
#endif
425+
);
404426
} else {
405-
result = eval_contextual_.Lookup(source, context, strict_mode);
427+
result = eval_contextual_.Lookup(source, context, strict_mode
428+
#ifdef QT_BUILD_SCRIPT_LIB
429+
,script_name, line_offset, column_offset
430+
#endif
431+
);
406432
}
407433
return result;
408434
}

src/3rdparty/v8/src/compilation-cache.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class CompilationCacheScript : public CompilationSubCache {
111111
Handle<CompilationCacheTable> TablePut(
112112
Handle<String> source, Handle<SharedFunctionInfo> function_info);
113113

114+
#ifdef QT_BUILD_SCRIPT_LIB
115+
public:
116+
static
117+
#endif
114118
bool HasOrigin(Handle<SharedFunctionInfo> function_info,
115119
Handle<Object> name,
116120
int line_offset,
@@ -131,7 +135,11 @@ class CompilationCacheEval: public CompilationSubCache {
131135

132136
Handle<SharedFunctionInfo> Lookup(Handle<String> source,
133137
Handle<Context> context,
134-
StrictModeFlag strict_mode);
138+
StrictModeFlag strict_mode
139+
#ifdef QT_BUILD_SCRIPT_LIB
140+
, Handle<Object> script_name, int line_offset, int column_offset
141+
#endif
142+
);
135143

136144
void Put(Handle<String> source,
137145
Handle<Context> context,
@@ -198,7 +206,12 @@ class CompilationCache {
198206
Handle<SharedFunctionInfo> LookupEval(Handle<String> source,
199207
Handle<Context> context,
200208
bool is_global,
201-
StrictModeFlag strict_mode);
209+
StrictModeFlag strict_mode
210+
#ifdef QT_BUILD_SCRIPT_LIB
211+
, Handle<Object> script_name = Handle<Object>(),
212+
int line_offset = 0, int column_offset = 0
213+
#endif
214+
);
202215

203216
// Returns the regexp data associated with the given regexp if it
204217
// is in cache, otherwise an empty handle.

src/3rdparty/v8/src/compiler.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,12 @@ Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
543543
Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
544544
Handle<Context> context,
545545
bool is_global,
546-
StrictModeFlag strict_mode) {
546+
StrictModeFlag strict_mode
547+
#ifdef QT_BUILD_SCRIPT_LIB
548+
, Handle<Object> script_name,
549+
int line_offset, int column_offset
550+
#endif
551+
) {
547552
Isolate* isolate = source->GetIsolate();
548553
int source_length = source->length();
549554
isolate->counters()->total_eval_size()->Increment(source_length);
@@ -559,11 +564,22 @@ Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
559564
result = compilation_cache->LookupEval(source,
560565
context,
561566
is_global,
562-
strict_mode);
567+
strict_mode
568+
#ifdef QT_BUILD_SCRIPT_LIB
569+
,script_name, line_offset, column_offset
570+
#endif
571+
);
563572

564573
if (result.is_null()) {
565574
// Create a script object describing the script to be compiled.
566575
Handle<Script> script = isolate->factory()->NewScript(source);
576+
#ifdef QT_BUILD_SCRIPT_LIB
577+
if (!script_name.is_null()) {
578+
script->set_name(*script_name);
579+
script->set_line_offset(Smi::FromInt(line_offset));
580+
script->set_column_offset(Smi::FromInt(column_offset));
581+
}
582+
#endif
567583
CompilationInfo info(script);
568584
info.MarkAsEval();
569585
if (is_global) info.MarkAsGlobal();

src/3rdparty/v8/src/compiler.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ class Compiler : public AllStatic {
259259
static Handle<SharedFunctionInfo> CompileEval(Handle<String> source,
260260
Handle<Context> context,
261261
bool is_global,
262-
StrictModeFlag strict_mode);
262+
StrictModeFlag strict_mode
263+
#ifdef QT_BUILD_SCRIPT_LIB
264+
, Handle<Object> script_name = Handle<Object>(),
265+
int line_offset = 0, int column_offset = 0
266+
#endif
267+
);
263268

264269
// Compile from function info (used for lazy compilation). Returns true on
265270
// success and false if the compilation resulted in a stack overflow.

0 commit comments

Comments
 (0)