| 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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 RuntimeCallTimerScope runtime_timer(runtime_call_stats_, | 847 RuntimeCallTimerScope runtime_timer(runtime_call_stats_, |
| 848 &RuntimeCallStats::ParseFunction); | 848 &RuntimeCallStats::ParseFunction); |
| 849 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); | 849 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); |
| 850 Handle<String> source(String::cast(info->script()->source())); | 850 Handle<String> source(String::cast(info->script()->source())); |
| 851 isolate->counters()->total_parse_size()->Increment(source->length()); | 851 isolate->counters()->total_parse_size()->Increment(source->length()); |
| 852 base::ElapsedTimer timer; | 852 base::ElapsedTimer timer; |
| 853 if (FLAG_trace_parse) { | 853 if (FLAG_trace_parse) { |
| 854 timer.Start(); | 854 timer.Start(); |
| 855 } | 855 } |
| 856 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 856 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
| 857 DeserializeScopeChain(info, info->maybe_outer_scope_info()); | 857 if (!info->script_scope()) { |
| 858 DeserializeScopeChain(info, info->maybe_outer_scope_info()); |
| 859 } else { |
| 860 original_scope_ = new (info->zone()) DeclarationScope( |
| 861 info->zone(), info->script_scope()->outer_scope(), FUNCTION_SCOPE); |
| 862 } |
| 858 | 863 |
| 859 // Initialize parser state. | 864 // Initialize parser state. |
| 860 source = String::Flatten(source); | 865 source = String::Flatten(source); |
| 861 FunctionLiteral* result; | 866 FunctionLiteral* result; |
| 862 { | 867 { |
| 863 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( | 868 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( |
| 864 source, shared_info->start_position(), shared_info->end_position())); | 869 source, shared_info->start_position(), shared_info->end_position())); |
| 865 Handle<String> name(String::cast(shared_info->name())); | 870 Handle<String> name(String::cast(shared_info->name())); |
| 866 result = DoParseFunction(info, ast_value_factory()->GetString(name), | 871 result = DoParseFunction(info, ast_value_factory()->GetString(name), |
| 867 stream.get()); | 872 stream.get()); |
| (...skipping 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2603 // - Neither V8 natives nor native function declarations can be allowed, | 2608 // - Neither V8 natives nor native function declarations can be allowed, |
| 2604 // since parsing one would retroactively force the function to be | 2609 // since parsing one would retroactively force the function to be |
| 2605 // eagerly compiled. | 2610 // eagerly compiled. |
| 2606 // - The invoker of this parser can't depend on the AST being eagerly | 2611 // - The invoker of this parser can't depend on the AST being eagerly |
| 2607 // built (either because the function is about to be compiled, or | 2612 // built (either because the function is about to be compiled, or |
| 2608 // because the AST is going to be inspected for some reason). | 2613 // because the AST is going to be inspected for some reason). |
| 2609 // - Because of the above, we can't be attempting to parse a | 2614 // - Because of the above, we can't be attempting to parse a |
| 2610 // FunctionExpression; even without enclosing parentheses it might be | 2615 // FunctionExpression; even without enclosing parentheses it might be |
| 2611 // immediately invoked. | 2616 // immediately invoked. |
| 2612 // - The function literal shouldn't be hinted to eagerly compile. | 2617 // - The function literal shouldn't be hinted to eagerly compile. |
| 2613 // - For asm.js functions the body needs to be available when module | |
| 2614 // validation is active, because we examine the entire module at once. | |
| 2615 | 2618 |
| 2616 // Inner functions will be parsed using a temporary Zone. After parsing, we | 2619 // Inner functions will be parsed using a temporary Zone. After parsing, we |
| 2617 // will migrate unresolved variable into a Scope in the main Zone. | 2620 // will migrate unresolved variable into a Scope in the main Zone. |
| 2618 // TODO(marja): Refactor parsing modes: simplify this. | 2621 // TODO(marja): Refactor parsing modes: simplify this. |
| 2619 bool use_temp_zone = | 2622 bool use_temp_zone = |
| 2620 (FLAG_lazy_inner_functions | 2623 (FLAG_lazy_inner_functions |
| 2621 ? can_preparse | 2624 ? can_preparse |
| 2622 : (is_lazy_top_level_function || | 2625 : (is_lazy_top_level_function || |
| 2623 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration && | 2626 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration && |
| 2624 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))) && | 2627 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))); |
| 2625 !(FLAG_validate_asm && scope()->IsAsmModule()); | |
| 2626 bool is_lazy_inner_function = | 2628 bool is_lazy_inner_function = |
| 2627 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; | 2629 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; |
| 2628 | 2630 |
| 2629 ZoneList<Statement*>* body = nullptr; | 2631 ZoneList<Statement*>* body = nullptr; |
| 2630 int materialized_literal_count = -1; | 2632 int materialized_literal_count = -1; |
| 2631 int expected_property_count = -1; | 2633 int expected_property_count = -1; |
| 2632 bool should_be_used_once_hint = false; | 2634 bool should_be_used_once_hint = false; |
| 2633 int num_parameters = -1; | 2635 int num_parameters = -1; |
| 2634 int function_length = -1; | 2636 int function_length = -1; |
| 2635 bool has_duplicate_parameters = false; | 2637 bool has_duplicate_parameters = false; |
| (...skipping 2836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5472 | 5474 |
| 5473 return final_loop; | 5475 return final_loop; |
| 5474 } | 5476 } |
| 5475 | 5477 |
| 5476 #undef CHECK_OK | 5478 #undef CHECK_OK |
| 5477 #undef CHECK_OK_VOID | 5479 #undef CHECK_OK_VOID |
| 5478 #undef CHECK_FAILED | 5480 #undef CHECK_FAILED |
| 5479 | 5481 |
| 5480 } // namespace internal | 5482 } // namespace internal |
| 5481 } // namespace v8 | 5483 } // namespace v8 |
| OLD | NEW |