| Index: src/compiler.cc
|
| diff --git a/src/compiler.cc b/src/compiler.cc
|
| index 08a1339de033faa85dc487aa206b429da76d50d8..5f56c77708e4e90056f97390e398b65fdc690864 100644
|
| --- a/src/compiler.cc
|
| +++ b/src/compiler.cc
|
| @@ -1390,14 +1390,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;
|
| + }
|
| CompilationCache* compilation_cache = isolate->compilation_cache();
|
| MaybeHandle<SharedFunctionInfo> maybe_shared_info =
|
| compilation_cache->LookupEval(source, outer_info, context, language_mode,
|
| @@ -1422,6 +1439,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()));
|
| }
|
| @@ -1473,7 +1491,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);
|
|
|
| @@ -1493,8 +1511,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(
|
|
|