Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 | 282 |
| 283 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 283 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 284 name, function_scope, body, materialized_literal_count, | 284 name, function_scope, body, materialized_literal_count, |
| 285 expected_property_count, parameter_count, | 285 expected_property_count, parameter_count, |
| 286 FunctionLiteral::kNoDuplicateParameters, | 286 FunctionLiteral::kNoDuplicateParameters, |
| 287 FunctionLiteral::kAnonymousExpression, | 287 FunctionLiteral::kAnonymousExpression, |
| 288 FunctionLiteral::kShouldLazyCompile, pos); | 288 FunctionLiteral::kShouldLazyCompile, pos); |
| 289 | 289 |
| 290 function_literal->set_requires_class_field_init(requires_class_field_init); | 290 function_literal->set_requires_class_field_init(requires_class_field_init); |
| 291 | 291 |
| 292 if (ShouldCompileLazily(function_literal)) { | |
| 293 function_literal->scope()->SetShouldCompileLazily(true); | |
| 294 } | |
| 295 | |
| 292 return function_literal; | 296 return function_literal; |
| 293 } | 297 } |
| 294 | 298 |
| 295 | 299 |
| 296 // ---------------------------------------------------------------------------- | 300 // ---------------------------------------------------------------------------- |
| 297 // Target is a support class to facilitate manipulation of the | 301 // Target is a support class to facilitate manipulation of the |
| 298 // Parser's target_stack_ (the stack of potential 'break' and | 302 // Parser's target_stack_ (the stack of potential 'break' and |
| 299 // 'continue' statement targets). Upon construction, a new target is | 303 // 'continue' statement targets). Upon construction, a new target is |
| 300 // added; it is removed upon destruction. | 304 // added; it is removed upon destruction. |
| 301 | 305 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 compile_options_(info->compile_options()), | 643 compile_options_(info->compile_options()), |
| 640 cached_parse_data_(NULL), | 644 cached_parse_data_(NULL), |
| 641 total_preparse_skipped_(0), | 645 total_preparse_skipped_(0), |
| 642 pre_parse_timer_(NULL), | 646 pre_parse_timer_(NULL), |
| 643 parsing_on_main_thread_(true) { | 647 parsing_on_main_thread_(true) { |
| 644 // Even though we were passed ParseInfo, we should not store it in | 648 // Even though we were passed ParseInfo, we should not store it in |
| 645 // Parser - this makes sure that Isolate is not accidentally accessed via | 649 // Parser - this makes sure that Isolate is not accidentally accessed via |
| 646 // ParseInfo during background parsing. | 650 // ParseInfo during background parsing. |
| 647 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 651 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
| 648 info->character_stream() != nullptr); | 652 info->character_stream() != nullptr); |
| 653 set_will_serialize(info->will_serialize()); | |
| 654 set_serializer_enabled(info->isolate()->serializer_enabled()); | |
| 655 set_is_debug(info->is_debug()); | |
| 649 set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && | 656 set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && |
| 650 !info->is_native() && info->extension() == nullptr); | 657 !info->is_native() && info->extension() == nullptr); |
| 651 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 658 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
| 652 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && | 659 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && |
| 653 info->isolate()->is_tail_call_elimination_enabled()); | 660 info->isolate()->is_tail_call_elimination_enabled()); |
| 654 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 661 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
| 655 set_allow_harmony_for_in(FLAG_harmony_for_in); | 662 set_allow_harmony_for_in(FLAG_harmony_for_in); |
| 656 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 663 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
| 657 set_allow_harmony_restrictive_declarations( | 664 set_allow_harmony_restrictive_declarations( |
| 658 FLAG_harmony_restrictive_declarations); | 665 FLAG_harmony_restrictive_declarations); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 684 Handle<ScopeInfo> outer_scope_info; | 691 Handle<ScopeInfo> outer_scope_info; |
| 685 if (maybe_outer_scope_info.ToHandle(&outer_scope_info)) { | 692 if (maybe_outer_scope_info.ToHandle(&outer_scope_info)) { |
| 686 scope = Scope::DeserializeScopeChain( | 693 scope = Scope::DeserializeScopeChain( |
| 687 info->isolate(), zone(), *outer_scope_info, script_scope, | 694 info->isolate(), zone(), *outer_scope_info, script_scope, |
| 688 ast_value_factory(), Scope::DeserializationMode::kScopesOnly); | 695 ast_value_factory(), Scope::DeserializationMode::kScopesOnly); |
| 689 DCHECK(!info->is_module() || scope->is_module_scope()); | 696 DCHECK(!info->is_module() || scope->is_module_scope()); |
| 690 } | 697 } |
| 691 original_scope_ = scope; | 698 original_scope_ = scope; |
| 692 } | 699 } |
| 693 | 700 |
| 701 bool Parser::ShouldCompileLazily(FunctionLiteral* fun) { | |
| 702 // Determine if the function should be lazily compiled. This is necessary to | |
| 703 // allow some of our builtin JS files to be lazily compiled. These | |
| 704 // builtins cannot be handled lazily by the parser, since we have to know | |
| 705 // if a function uses the special natives syntax, which is something the | |
| 706 // parser records. | |
| 707 // If the debugger requests compilation for break points, we cannot be | |
| 708 // aggressive about lazy compilation, because it might trigger compilation | |
| 709 // of functions without an outer context when setting a breakpoint through | |
| 710 // Debug::FindSharedFunctionInfoInScript. | |
| 711 bool allow_lazy = fun->AllowsLazyCompilation() && !is_debug(); | |
| 712 bool lazy = FLAG_lazy && allow_lazy && !fun->should_eager_compile(); | |
| 713 | |
| 714 // Consider compiling eagerly when targeting the code cache. | |
| 715 lazy &= !(FLAG_serialize_eager && will_serialize()); | |
| 716 | |
| 717 // Consider compiling eagerly when compiling bytecode for Ignition. | |
| 718 lazy &= !(FLAG_ignition && FLAG_ignition_eager && !serializer_enabled()); | |
| 719 | |
| 720 return lazy; | |
| 721 } | |
| 722 | |
| 694 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { | 723 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { |
| 695 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 724 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
| 696 // see comment for HistogramTimerScope class. | 725 // see comment for HistogramTimerScope class. |
| 697 | 726 |
| 698 // It's OK to use the Isolate & counters here, since this function is only | 727 // It's OK to use the Isolate & counters here, since this function is only |
| 699 // called in the main thread. | 728 // called in the main thread. |
| 700 DCHECK(parsing_on_main_thread_); | 729 DCHECK(parsing_on_main_thread_); |
| 701 | 730 |
| 702 HistogramTimerScope timer_scope(isolate->counters()->parse(), true); | 731 HistogramTimerScope timer_scope(isolate->counters()->parse(), true); |
| 703 RuntimeCallTimerScope runtime_timer(isolate, &RuntimeCallStats::Parse); | 732 RuntimeCallTimerScope runtime_timer(isolate, &RuntimeCallStats::Parse); |
| (...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2775 expected_property_count, arity, duplicate_parameters, function_type, | 2804 expected_property_count, arity, duplicate_parameters, function_type, |
| 2776 eager_compile_hint, pos); | 2805 eager_compile_hint, pos); |
| 2777 function_literal->set_function_token_position(function_token_pos); | 2806 function_literal->set_function_token_position(function_token_pos); |
| 2778 if (should_be_used_once_hint) | 2807 if (should_be_used_once_hint) |
| 2779 function_literal->set_should_be_used_once_hint(); | 2808 function_literal->set_should_be_used_once_hint(); |
| 2780 | 2809 |
| 2781 if (should_infer_name) { | 2810 if (should_infer_name) { |
| 2782 DCHECK_NOT_NULL(fni_); | 2811 DCHECK_NOT_NULL(fni_); |
| 2783 fni_->AddFunction(function_literal); | 2812 fni_->AddFunction(function_literal); |
| 2784 } | 2813 } |
| 2814 | |
| 2815 if (ShouldCompileLazily(function_literal)) { | |
| 2816 scope->SetShouldCompileLazily(true); | |
|
marja
2016/10/06 11:53:06
Would it be feasible to pass this information in F
| |
| 2817 } | |
| 2818 | |
| 2785 return function_literal; | 2819 return function_literal; |
| 2786 } | 2820 } |
| 2787 | 2821 |
| 2788 Parser::LazyParsingResult Parser::SkipLazyFunctionBody( | 2822 Parser::LazyParsingResult Parser::SkipLazyFunctionBody( |
| 2789 int* materialized_literal_count, int* expected_property_count, | 2823 int* materialized_literal_count, int* expected_property_count, |
| 2790 bool is_inner_function, bool may_abort, bool* ok) { | 2824 bool is_inner_function, bool may_abort, bool* ok) { |
| 2791 if (produce_cached_parse_data()) CHECK(log_); | 2825 if (produce_cached_parse_data()) CHECK(log_); |
| 2792 | 2826 |
| 2793 int function_block_pos = position(); | 2827 int function_block_pos = position(); |
| 2794 DeclarationScope* scope = function_state_->scope(); | 2828 DeclarationScope* scope = function_state_->scope(); |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3425 zone()); | 3459 zone()); |
| 3426 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 3460 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 3427 ast_value_factory()->empty_string(), initializer_scope, body, | 3461 ast_value_factory()->empty_string(), initializer_scope, body, |
| 3428 initializer_state.materialized_literal_count(), | 3462 initializer_state.materialized_literal_count(), |
| 3429 initializer_state.expected_property_count(), 0, | 3463 initializer_state.expected_property_count(), 0, |
| 3430 FunctionLiteral::kNoDuplicateParameters, | 3464 FunctionLiteral::kNoDuplicateParameters, |
| 3431 FunctionLiteral::kAnonymousExpression, | 3465 FunctionLiteral::kAnonymousExpression, |
| 3432 FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position()); | 3466 FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position()); |
| 3433 function_literal->set_is_class_field_initializer(true); | 3467 function_literal->set_is_class_field_initializer(true); |
| 3434 function_literal->scope()->set_arity(count); | 3468 function_literal->scope()->set_arity(count); |
| 3469 if (ShouldCompileLazily(function_literal)) { | |
| 3470 function_literal->scope()->SetShouldCompileLazily(true); | |
| 3471 } | |
| 3435 return function_literal; | 3472 return function_literal; |
| 3436 } | 3473 } |
| 3437 | 3474 |
| 3438 FunctionLiteral* Parser::InsertClassFieldInitializer( | 3475 FunctionLiteral* Parser::InsertClassFieldInitializer( |
| 3439 FunctionLiteral* constructor) { | 3476 FunctionLiteral* constructor) { |
| 3440 Statement* call_initializer = factory()->NewExpressionStatement( | 3477 Statement* call_initializer = factory()->NewExpressionStatement( |
| 3441 CallClassFieldInitializer( | 3478 CallClassFieldInitializer( |
| 3442 constructor->scope(), | 3479 constructor->scope(), |
| 3443 constructor->scope()->NewUnresolved( | 3480 constructor->scope()->NewUnresolved( |
| 3444 factory(), ast_value_factory()->this_string(), kNoSourcePosition, | 3481 factory(), ast_value_factory()->this_string(), kNoSourcePosition, |
| (...skipping 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5442 | 5479 |
| 5443 return final_loop; | 5480 return final_loop; |
| 5444 } | 5481 } |
| 5445 | 5482 |
| 5446 #undef CHECK_OK | 5483 #undef CHECK_OK |
| 5447 #undef CHECK_OK_VOID | 5484 #undef CHECK_OK_VOID |
| 5448 #undef CHECK_FAILED | 5485 #undef CHECK_FAILED |
| 5449 | 5486 |
| 5450 } // namespace internal | 5487 } // namespace internal |
| 5451 } // namespace v8 | 5488 } // namespace v8 |
| OLD | NEW |