Chromium Code Reviews| Index: src/parsing/parser.cc |
| diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
| index 0ae1fb619a70ff1aa8bf224fa5a613ec99ebcea4..e536304165ef1b35e3eddf77b3ae27e66769d6e1 100644 |
| --- a/src/parsing/parser.cc |
| +++ b/src/parsing/parser.cc |
| @@ -289,6 +289,10 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, |
| function_literal->set_requires_class_field_init(requires_class_field_init); |
| + if (ShouldCompileLazily(function_literal)) { |
| + function_literal->scope()->SetShouldCompileLazily(true); |
| + } |
| + |
| return function_literal; |
| } |
| @@ -646,6 +650,9 @@ Parser::Parser(ParseInfo* info) |
| // ParseInfo during background parsing. |
| DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
| info->character_stream() != nullptr); |
| + set_will_serialize(info->will_serialize()); |
| + set_serializer_enabled(info->isolate()->serializer_enabled()); |
| + set_is_debug(info->is_debug()); |
| set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && |
| !info->is_native() && info->extension() == nullptr); |
| set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
| @@ -691,6 +698,28 @@ void Parser::DeserializeScopeChain( |
| original_scope_ = scope; |
| } |
| +bool Parser::ShouldCompileLazily(FunctionLiteral* fun) { |
| + // Determine if the function should be lazily compiled. This is necessary to |
| + // allow some of our builtin JS files to be lazily compiled. These |
| + // builtins cannot be handled lazily by the parser, since we have to know |
| + // if a function uses the special natives syntax, which is something the |
| + // parser records. |
| + // If the debugger requests compilation for break points, we cannot be |
| + // aggressive about lazy compilation, because it might trigger compilation |
| + // of functions without an outer context when setting a breakpoint through |
| + // Debug::FindSharedFunctionInfoInScript. |
| + bool allow_lazy = fun->AllowsLazyCompilation() && !is_debug(); |
| + bool lazy = FLAG_lazy && allow_lazy && !fun->should_eager_compile(); |
| + |
| + // Consider compiling eagerly when targeting the code cache. |
| + lazy &= !(FLAG_serialize_eager && will_serialize()); |
| + |
| + // Consider compiling eagerly when compiling bytecode for Ignition. |
| + lazy &= !(FLAG_ignition && FLAG_ignition_eager && !serializer_enabled()); |
| + |
| + return lazy; |
| +} |
| + |
| FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { |
| // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
| // see comment for HistogramTimerScope class. |
| @@ -2782,6 +2811,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
| DCHECK_NOT_NULL(fni_); |
| fni_->AddFunction(function_literal); |
| } |
| + |
| + if (ShouldCompileLazily(function_literal)) { |
| + scope->SetShouldCompileLazily(true); |
|
marja
2016/10/06 11:53:06
Would it be feasible to pass this information in F
|
| + } |
| + |
| return function_literal; |
| } |
| @@ -3432,6 +3466,9 @@ FunctionLiteral* Parser::SynthesizeClassFieldInitializer(int count) { |
| FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position()); |
| function_literal->set_is_class_field_initializer(true); |
| function_literal->scope()->set_arity(count); |
| + if (ShouldCompileLazily(function_literal)) { |
| + function_literal->scope()->SetShouldCompileLazily(true); |
| + } |
| return function_literal; |
| } |