Index: src/compiler.cc |
diff --git a/src/compiler.cc b/src/compiler.cc |
index c5f84ebde5f1a89280905f8ba1ae2574e8a399b7..d05f62d7c16b65f8e0ee02bb30f4009df954ba04 100644 |
--- a/src/compiler.cc |
+++ b/src/compiler.cc |
@@ -1265,14 +1265,31 @@ Compiler::CompilationTier Compiler::NextCompilationTier(JSFunction* function) { |
MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
Handle<Context> context, LanguageMode language_mode, |
- ParseRestriction restriction, int eval_scope_position, int eval_position, |
- int line_offset, int column_offset, Handle<Object> script_name, |
+ ParseRestriction restriction, int parameters_end_pos, |
+ int eval_scope_position, int eval_position, int line_offset, |
+ int column_offset, Handle<Object> script_name, |
ScriptOriginOptions options) { |
Isolate* isolate = source->GetIsolate(); |
int source_length = source->length(); |
isolate->counters()->total_eval_size()->Increment(source_length); |
isolate->counters()->total_compile_size()->Increment(source_length); |
+ // The cache lookup key needs to be aware of the separation between the |
+ // parameters and the body to prevent this valid invocation: |
+ // Function("", "function anonymous(\n/**/) {\n}"); |
+ // from adding an entry that falsely approves this invalid invocation: |
+ // Function("\n/**/) {\nfunction anonymous(", "}"); |
+ // The actual eval_scope_position for indirect eval and CreateDynamicFunction |
+ // is unused (just 0), which means it's an available field to use to indicate |
+ // this separation. But to make sure we're not causing other false hits, we |
+ // negate the scope position. |
+ if (FLAG_harmony_function_tostring && |
+ restriction == ONLY_SINGLE_FUNCTION_LITERAL && |
+ parameters_end_pos != kNoSourcePosition) { |
+ // use the parameters_end_pos as the eval_scope_position in the eval cache. |
+ DCHECK_EQ(eval_scope_position, 0); |
+ eval_scope_position = -parameters_end_pos; |
Dan Ehrenberg
2016/12/06 00:32:13
This seems like a valid implementation strategy, t
jwolfe
2017/01/13 00:28:47
I added documentation to the StringSharedKey const
|
+ } |
CompilationCache* compilation_cache = isolate->compilation_cache(); |
MaybeHandle<SharedFunctionInfo> maybe_shared_info = |
compilation_cache->LookupEval(source, outer_info, context, language_mode, |
@@ -1298,6 +1315,7 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
parse_info.set_eval(); |
parse_info.set_language_mode(language_mode); |
parse_info.set_parse_restriction(restriction); |
+ parse_info.set_parameters_end_pos(parameters_end_pos); |
if (!context->IsNativeContext()) { |
parse_info.set_outer_scope_info(handle(context->scope_info())); |
} |
@@ -1349,7 +1367,7 @@ bool CodeGenerationFromStringsAllowed(Isolate* isolate, |
MaybeHandle<JSFunction> Compiler::GetFunctionFromString( |
Handle<Context> context, Handle<String> source, |
- ParseRestriction restriction) { |
+ ParseRestriction restriction, int parameters_end_pos) { |
Isolate* const isolate = context->GetIsolate(); |
Handle<Context> native_context(context->native_context(), isolate); |
@@ -1369,8 +1387,8 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromString( |
int eval_position = kNoSourcePosition; |
Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); |
return Compiler::GetFunctionFromEval(source, outer_info, native_context, |
- SLOPPY, restriction, eval_scope_position, |
- eval_position); |
+ SLOPPY, restriction, parameters_end_pos, |
+ eval_scope_position, eval_position); |
} |
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript( |