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 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 &RuntimeCallStats::ParseFunction); | 852 &RuntimeCallStats::ParseFunction); |
853 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); | 853 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); |
854 Handle<String> source(String::cast(info->script()->source())); | 854 Handle<String> source(String::cast(info->script()->source())); |
855 isolate->counters()->total_parse_size()->Increment(source->length()); | 855 isolate->counters()->total_parse_size()->Increment(source->length()); |
856 base::ElapsedTimer timer; | 856 base::ElapsedTimer timer; |
857 if (FLAG_trace_parse) { | 857 if (FLAG_trace_parse) { |
858 timer.Start(); | 858 timer.Start(); |
859 } | 859 } |
860 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 860 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
861 DeserializeScopeChain(info, info->maybe_outer_scope_info()); | 861 DeserializeScopeChain(info, info->maybe_outer_scope_info()); |
| 862 if (info->asm_function_scope()) { |
| 863 original_scope_ = info->asm_function_scope(); |
| 864 factory()->set_zone(info->zone()); |
| 865 } else { |
| 866 DCHECK(factory()->zone() == info->zone()); |
| 867 } |
862 | 868 |
863 // Initialize parser state. | 869 // Initialize parser state. |
864 source = String::Flatten(source); | 870 source = String::Flatten(source); |
865 FunctionLiteral* result; | 871 FunctionLiteral* result; |
866 { | 872 { |
867 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( | 873 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( |
868 source, shared_info->start_position(), shared_info->end_position())); | 874 source, shared_info->start_position(), shared_info->end_position())); |
869 Handle<String> name(String::cast(shared_info->name())); | 875 Handle<String> name(String::cast(shared_info->name())); |
870 result = DoParseFunction(info, ast_value_factory()->GetString(name), | 876 result = DoParseFunction(info, ast_value_factory()->GetString(name), |
871 stream.get()); | 877 stream.get()); |
(...skipping 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2624 // - Neither V8 natives nor native function declarations can be allowed, | 2630 // - Neither V8 natives nor native function declarations can be allowed, |
2625 // since parsing one would retroactively force the function to be | 2631 // since parsing one would retroactively force the function to be |
2626 // eagerly compiled. | 2632 // eagerly compiled. |
2627 // - The invoker of this parser can't depend on the AST being eagerly | 2633 // - The invoker of this parser can't depend on the AST being eagerly |
2628 // built (either because the function is about to be compiled, or | 2634 // built (either because the function is about to be compiled, or |
2629 // because the AST is going to be inspected for some reason). | 2635 // because the AST is going to be inspected for some reason). |
2630 // - Because of the above, we can't be attempting to parse a | 2636 // - Because of the above, we can't be attempting to parse a |
2631 // FunctionExpression; even without enclosing parentheses it might be | 2637 // FunctionExpression; even without enclosing parentheses it might be |
2632 // immediately invoked. | 2638 // immediately invoked. |
2633 // - The function literal shouldn't be hinted to eagerly compile. | 2639 // - The function literal shouldn't be hinted to eagerly compile. |
2634 // - For asm.js functions the body needs to be available when module | |
2635 // validation is active, because we examine the entire module at once. | |
2636 | 2640 |
2637 // Inner functions will be parsed using a temporary Zone. After parsing, we | 2641 // Inner functions will be parsed using a temporary Zone. After parsing, we |
2638 // will migrate unresolved variable into a Scope in the main Zone. | 2642 // will migrate unresolved variable into a Scope in the main Zone. |
2639 // TODO(marja): Refactor parsing modes: simplify this. | 2643 // TODO(marja): Refactor parsing modes: simplify this. |
2640 bool use_temp_zone = | 2644 bool use_temp_zone = |
2641 (FLAG_lazy_inner_functions | 2645 (FLAG_lazy_inner_functions |
2642 ? can_preparse | 2646 ? can_preparse |
2643 : (is_lazy_top_level_function || | 2647 : (is_lazy_top_level_function || |
2644 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration && | 2648 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration && |
2645 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))) && | 2649 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))); |
2646 !(FLAG_validate_asm && scope()->IsAsmModule()); | |
2647 bool is_lazy_inner_function = | 2650 bool is_lazy_inner_function = |
2648 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; | 2651 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; |
2649 | 2652 |
2650 ZoneList<Statement*>* body = nullptr; | 2653 ZoneList<Statement*>* body = nullptr; |
2651 int materialized_literal_count = -1; | 2654 int materialized_literal_count = -1; |
2652 int expected_property_count = -1; | 2655 int expected_property_count = -1; |
2653 bool should_be_used_once_hint = false; | 2656 bool should_be_used_once_hint = false; |
2654 int num_parameters = -1; | 2657 int num_parameters = -1; |
2655 int function_length = -1; | 2658 int function_length = -1; |
2656 bool has_duplicate_parameters = false; | 2659 bool has_duplicate_parameters = false; |
(...skipping 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5497 | 5500 |
5498 return final_loop; | 5501 return final_loop; |
5499 } | 5502 } |
5500 | 5503 |
5501 #undef CHECK_OK | 5504 #undef CHECK_OK |
5502 #undef CHECK_OK_VOID | 5505 #undef CHECK_OK_VOID |
5503 #undef CHECK_FAILED | 5506 #undef CHECK_FAILED |
5504 | 5507 |
5505 } // namespace internal | 5508 } // namespace internal |
5506 } // namespace v8 | 5509 } // namespace v8 |
OLD | NEW |