| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); | 160 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); |
| 161 if (cached_parse_data_ != nullptr) return; | 161 if (cached_parse_data_ != nullptr) return; |
| 162 } | 162 } |
| 163 compile_options_ = ScriptCompiler::kNoCompileOptions; | 163 compile_options_ = ScriptCompiler::kNoCompileOptions; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, | 167 FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, |
| 168 bool call_super, int pos, | 168 bool call_super, int pos, |
| 169 int end_pos) { | 169 int end_pos) { |
| 170 int materialized_literal_count = -1; | |
| 171 int expected_property_count = -1; | 170 int expected_property_count = -1; |
| 172 const int parameter_count = 0; | 171 const int parameter_count = 0; |
| 173 if (name == nullptr) name = ast_value_factory()->empty_string(); | 172 if (name == nullptr) name = ast_value_factory()->empty_string(); |
| 174 | 173 |
| 175 FunctionKind kind = call_super ? FunctionKind::kDefaultDerivedConstructor | 174 FunctionKind kind = call_super ? FunctionKind::kDefaultDerivedConstructor |
| 176 : FunctionKind::kDefaultBaseConstructor; | 175 : FunctionKind::kDefaultBaseConstructor; |
| 177 DeclarationScope* function_scope = NewFunctionScope(kind); | 176 DeclarationScope* function_scope = NewFunctionScope(kind); |
| 178 SetLanguageMode(function_scope, STRICT); | 177 SetLanguageMode(function_scope, STRICT); |
| 179 // Set start and end position to the same value | 178 // Set start and end position to the same value |
| 180 function_scope->set_start_position(pos); | 179 function_scope->set_start_position(pos); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 200 new (zone()) ZoneList<Expression*>(1, zone()); | 199 new (zone()) ZoneList<Expression*>(1, zone()); |
| 201 Spread* spread_args = factory()->NewSpread( | 200 Spread* spread_args = factory()->NewSpread( |
| 202 factory()->NewVariableProxy(constructor_args), pos, pos); | 201 factory()->NewVariableProxy(constructor_args), pos, pos); |
| 203 | 202 |
| 204 args->Add(spread_args, zone()); | 203 args->Add(spread_args, zone()); |
| 205 Expression* super_call_ref = NewSuperCallReference(pos); | 204 Expression* super_call_ref = NewSuperCallReference(pos); |
| 206 Expression* call = factory()->NewCall(super_call_ref, args, pos); | 205 Expression* call = factory()->NewCall(super_call_ref, args, pos); |
| 207 body->Add(factory()->NewReturnStatement(call, pos), zone()); | 206 body->Add(factory()->NewReturnStatement(call, pos), zone()); |
| 208 } | 207 } |
| 209 | 208 |
| 210 materialized_literal_count = function_state.materialized_literal_count(); | |
| 211 expected_property_count = function_state.expected_property_count(); | 209 expected_property_count = function_state.expected_property_count(); |
| 212 } | 210 } |
| 213 | 211 |
| 214 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 212 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 215 name, function_scope, body, materialized_literal_count, | 213 name, function_scope, body, expected_property_count, parameter_count, |
| 216 expected_property_count, parameter_count, parameter_count, | 214 parameter_count, FunctionLiteral::kNoDuplicateParameters, |
| 217 FunctionLiteral::kNoDuplicateParameters, | |
| 218 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint(), pos, | 215 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint(), pos, |
| 219 true, GetNextFunctionLiteralId()); | 216 true, GetNextFunctionLiteralId()); |
| 220 | 217 |
| 221 return function_literal; | 218 return function_literal; |
| 222 } | 219 } |
| 223 | 220 |
| 224 // ---------------------------------------------------------------------------- | 221 // ---------------------------------------------------------------------------- |
| 225 // The CHECK_OK macro is a convenient macro to enforce error | 222 // The CHECK_OK macro is a convenient macro to enforce error |
| 226 // handling for functions that may fail (by returning !*ok). | 223 // handling for functions that may fail (by returning !*ok). |
| 227 // | 224 // |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 expression()->IsFunctionLiteral()) { | 738 expression()->IsFunctionLiteral()) { |
| 742 ReportMessage(MessageTemplate::kSingleFunctionLiteral); | 739 ReportMessage(MessageTemplate::kSingleFunctionLiteral); |
| 743 ok = false; | 740 ok = false; |
| 744 } | 741 } |
| 745 } | 742 } |
| 746 | 743 |
| 747 if (ok) { | 744 if (ok) { |
| 748 RewriteDestructuringAssignments(); | 745 RewriteDestructuringAssignments(); |
| 749 int parameter_count = parsing_module_ ? 1 : 0; | 746 int parameter_count = parsing_module_ ? 1 : 0; |
| 750 result = factory()->NewScriptOrEvalFunctionLiteral( | 747 result = factory()->NewScriptOrEvalFunctionLiteral( |
| 751 scope, body, function_state.materialized_literal_count(), | 748 scope, body, function_state.expected_property_count(), |
| 752 function_state.expected_property_count(), parameter_count); | 749 parameter_count); |
| 753 } | 750 } |
| 754 } | 751 } |
| 755 | 752 |
| 756 info->set_max_function_literal_id(GetLastFunctionLiteralId()); | 753 info->set_max_function_literal_id(GetLastFunctionLiteralId()); |
| 757 | 754 |
| 758 // Make sure the target stack is empty. | 755 // Make sure the target stack is empty. |
| 759 DCHECK(target_stack_ == NULL); | 756 DCHECK(target_stack_ == NULL); |
| 760 | 757 |
| 761 return result; | 758 return result; |
| 762 } | 759 } |
| (...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2586 | 2583 |
| 2587 DCHECK_IMPLIES( | 2584 DCHECK_IMPLIES( |
| 2588 (is_lazy_top_level_function || | 2585 (is_lazy_top_level_function || |
| 2589 (parse_lazily() && function_type == FunctionLiteral::kDeclaration && | 2586 (parse_lazily() && function_type == FunctionLiteral::kDeclaration && |
| 2590 eager_compile_hint == FunctionLiteral::kShouldLazyCompile)), | 2587 eager_compile_hint == FunctionLiteral::kShouldLazyCompile)), |
| 2591 can_preparse); | 2588 can_preparse); |
| 2592 bool is_lazy_inner_function = | 2589 bool is_lazy_inner_function = |
| 2593 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; | 2590 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; |
| 2594 | 2591 |
| 2595 ZoneList<Statement*>* body = nullptr; | 2592 ZoneList<Statement*>* body = nullptr; |
| 2596 int materialized_literal_count = -1; | |
| 2597 int expected_property_count = -1; | 2593 int expected_property_count = -1; |
| 2598 bool should_be_used_once_hint = false; | 2594 bool should_be_used_once_hint = false; |
| 2599 int num_parameters = -1; | 2595 int num_parameters = -1; |
| 2600 int function_length = -1; | 2596 int function_length = -1; |
| 2601 bool has_duplicate_parameters = false; | 2597 bool has_duplicate_parameters = false; |
| 2602 int function_literal_id = GetNextFunctionLiteralId(); | 2598 int function_literal_id = GetNextFunctionLiteralId(); |
| 2603 | 2599 |
| 2604 Zone* outer_zone = zone(); | 2600 Zone* outer_zone = zone(); |
| 2605 DeclarationScope* scope; | 2601 DeclarationScope* scope; |
| 2606 | 2602 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2631 scope->set_start_position(scanner()->location().beg_pos); | 2627 scope->set_start_position(scanner()->location().beg_pos); |
| 2632 | 2628 |
| 2633 // Eager or lazy parse? If is_lazy_top_level_function, we'll parse | 2629 // Eager or lazy parse? If is_lazy_top_level_function, we'll parse |
| 2634 // lazily. We'll call SkipFunction, which may decide to | 2630 // lazily. We'll call SkipFunction, which may decide to |
| 2635 // abort lazy parsing if it suspects that wasn't a good idea. If so (in | 2631 // abort lazy parsing if it suspects that wasn't a good idea. If so (in |
| 2636 // which case the parser is expected to have backtracked), or if we didn't | 2632 // which case the parser is expected to have backtracked), or if we didn't |
| 2637 // try to lazy parse in the first place, we'll have to parse eagerly. | 2633 // try to lazy parse in the first place, we'll have to parse eagerly. |
| 2638 if (is_lazy_top_level_function || is_lazy_inner_function) { | 2634 if (is_lazy_top_level_function || is_lazy_inner_function) { |
| 2639 Scanner::BookmarkScope bookmark(scanner()); | 2635 Scanner::BookmarkScope bookmark(scanner()); |
| 2640 bookmark.Set(); | 2636 bookmark.Set(); |
| 2641 LazyParsingResult result = | 2637 LazyParsingResult result = SkipFunction( |
| 2642 SkipFunction(kind, scope, &num_parameters, &function_length, | 2638 kind, scope, &num_parameters, &function_length, |
| 2643 &has_duplicate_parameters, &materialized_literal_count, | 2639 &has_duplicate_parameters, &expected_property_count, |
| 2644 &expected_property_count, is_lazy_inner_function, | 2640 is_lazy_inner_function, is_lazy_top_level_function, CHECK_OK); |
| 2645 is_lazy_top_level_function, CHECK_OK); | |
| 2646 | 2641 |
| 2647 if (result == kLazyParsingAborted) { | 2642 if (result == kLazyParsingAborted) { |
| 2648 DCHECK(is_lazy_top_level_function); | 2643 DCHECK(is_lazy_top_level_function); |
| 2649 bookmark.Apply(); | 2644 bookmark.Apply(); |
| 2650 // Trigger eager (re-)parsing, just below this block. | 2645 // Trigger eager (re-)parsing, just below this block. |
| 2651 is_lazy_top_level_function = false; | 2646 is_lazy_top_level_function = false; |
| 2652 | 2647 |
| 2653 // This is probably an initialization function. Inform the compiler it | 2648 // This is probably an initialization function. Inform the compiler it |
| 2654 // should also eager-compile this function, and that we expect it to be | 2649 // should also eager-compile this function, and that we expect it to be |
| 2655 // used once. | 2650 // used once. |
| 2656 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; | 2651 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; |
| 2657 should_be_used_once_hint = true; | 2652 should_be_used_once_hint = true; |
| 2658 scope->ResetAfterPreparsing(ast_value_factory(), true); | 2653 scope->ResetAfterPreparsing(ast_value_factory(), true); |
| 2659 zone_scope.Reset(); | 2654 zone_scope.Reset(); |
| 2660 use_temp_zone = false; | 2655 use_temp_zone = false; |
| 2661 } | 2656 } |
| 2662 } | 2657 } |
| 2663 | 2658 |
| 2664 if (!is_lazy_top_level_function && !is_lazy_inner_function) { | 2659 if (!is_lazy_top_level_function && !is_lazy_inner_function) { |
| 2665 body = ParseFunction( | 2660 body = ParseFunction(function_name, pos, kind, function_type, scope, |
| 2666 function_name, pos, kind, function_type, scope, &num_parameters, | 2661 &num_parameters, &function_length, |
| 2667 &function_length, &has_duplicate_parameters, | 2662 &has_duplicate_parameters, &expected_property_count, |
| 2668 &materialized_literal_count, &expected_property_count, CHECK_OK); | 2663 CHECK_OK); |
| 2669 } | 2664 } |
| 2670 | 2665 |
| 2671 DCHECK(use_temp_zone || !is_lazy_top_level_function); | 2666 DCHECK(use_temp_zone || !is_lazy_top_level_function); |
| 2672 if (use_temp_zone) { | 2667 if (use_temp_zone) { |
| 2673 // If the preconditions are correct the function body should never be | 2668 // If the preconditions are correct the function body should never be |
| 2674 // accessed, but do this anyway for better behaviour if they're wrong. | 2669 // accessed, but do this anyway for better behaviour if they're wrong. |
| 2675 body = nullptr; | 2670 body = nullptr; |
| 2676 scope->AnalyzePartially(&previous_zone_ast_node_factory, | 2671 scope->AnalyzePartially(&previous_zone_ast_node_factory, |
| 2677 preparsed_scope_data_); | 2672 preparsed_scope_data_); |
| 2678 } | 2673 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2714 } | 2709 } |
| 2715 CheckConflictingVarDeclarations(scope, CHECK_OK); | 2710 CheckConflictingVarDeclarations(scope, CHECK_OK); |
| 2716 } // DiscardableZoneScope goes out of scope. | 2711 } // DiscardableZoneScope goes out of scope. |
| 2717 | 2712 |
| 2718 FunctionLiteral::ParameterFlag duplicate_parameters = | 2713 FunctionLiteral::ParameterFlag duplicate_parameters = |
| 2719 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters | 2714 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters |
| 2720 : FunctionLiteral::kNoDuplicateParameters; | 2715 : FunctionLiteral::kNoDuplicateParameters; |
| 2721 | 2716 |
| 2722 // Note that the FunctionLiteral needs to be created in the main Zone again. | 2717 // Note that the FunctionLiteral needs to be created in the main Zone again. |
| 2723 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 2718 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 2724 function_name, scope, body, materialized_literal_count, | 2719 function_name, scope, body, expected_property_count, num_parameters, |
| 2725 expected_property_count, num_parameters, function_length, | 2720 function_length, duplicate_parameters, function_type, eager_compile_hint, |
| 2726 duplicate_parameters, function_type, eager_compile_hint, pos, true, | 2721 pos, true, function_literal_id); |
| 2727 function_literal_id); | |
| 2728 function_literal->set_function_token_position(function_token_pos); | 2722 function_literal->set_function_token_position(function_token_pos); |
| 2729 if (should_be_used_once_hint) | 2723 if (should_be_used_once_hint) |
| 2730 function_literal->set_should_be_used_once_hint(); | 2724 function_literal->set_should_be_used_once_hint(); |
| 2731 | 2725 |
| 2732 if (should_infer_name) { | 2726 if (should_infer_name) { |
| 2733 DCHECK_NOT_NULL(fni_); | 2727 DCHECK_NOT_NULL(fni_); |
| 2734 fni_->AddFunction(function_literal); | 2728 fni_->AddFunction(function_literal); |
| 2735 } | 2729 } |
| 2736 return function_literal; | 2730 return function_literal; |
| 2737 } | 2731 } |
| 2738 | 2732 |
| 2739 Parser::LazyParsingResult Parser::SkipFunction( | 2733 Parser::LazyParsingResult Parser::SkipFunction( |
| 2740 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, | 2734 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, |
| 2741 int* function_length, bool* has_duplicate_parameters, | 2735 int* function_length, bool* has_duplicate_parameters, |
| 2742 int* materialized_literal_count, int* expected_property_count, | 2736 int* expected_property_count, bool is_inner_function, bool may_abort, |
| 2743 bool is_inner_function, bool may_abort, bool* ok) { | 2737 bool* ok) { |
| 2744 DCHECK_NE(kNoSourcePosition, function_scope->start_position()); | 2738 DCHECK_NE(kNoSourcePosition, function_scope->start_position()); |
| 2745 if (produce_cached_parse_data()) CHECK(log_); | 2739 if (produce_cached_parse_data()) CHECK(log_); |
| 2746 | 2740 |
| 2747 DCHECK_IMPLIES(IsArrowFunction(kind), | 2741 DCHECK_IMPLIES(IsArrowFunction(kind), |
| 2748 scanner()->current_token() == Token::ARROW); | 2742 scanner()->current_token() == Token::ARROW); |
| 2749 | 2743 |
| 2750 // Inner functions are not part of the cached data. | 2744 // Inner functions are not part of the cached data. |
| 2751 if (!is_inner_function && consume_cached_parse_data() && | 2745 if (!is_inner_function && consume_cached_parse_data() && |
| 2752 !cached_parse_data_->rejected()) { | 2746 !cached_parse_data_->rejected()) { |
| 2753 // If we have cached data, we use it to skip parsing the function. The data | 2747 // If we have cached data, we use it to skip parsing the function. The data |
| 2754 // contains the information we need to construct the lazy function. | 2748 // contains the information we need to construct the lazy function. |
| 2755 FunctionEntry entry = | 2749 FunctionEntry entry = |
| 2756 cached_parse_data_->GetFunctionEntry(function_scope->start_position()); | 2750 cached_parse_data_->GetFunctionEntry(function_scope->start_position()); |
| 2757 // Check that cached data is valid. If not, mark it as invalid (the embedder | 2751 // Check that cached data is valid. If not, mark it as invalid (the embedder |
| 2758 // handles it). Note that end position greater than end of stream is safe, | 2752 // handles it). Note that end position greater than end of stream is safe, |
| 2759 // and hard to check. | 2753 // and hard to check. |
| 2760 if (entry.is_valid() && | 2754 if (entry.is_valid() && |
| 2761 entry.end_pos() > function_scope->start_position()) { | 2755 entry.end_pos() > function_scope->start_position()) { |
| 2762 total_preparse_skipped_ += entry.end_pos() - position(); | 2756 total_preparse_skipped_ += entry.end_pos() - position(); |
| 2763 function_scope->set_end_position(entry.end_pos()); | 2757 function_scope->set_end_position(entry.end_pos()); |
| 2764 scanner()->SeekForward(entry.end_pos() - 1); | 2758 scanner()->SeekForward(entry.end_pos() - 1); |
| 2765 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); | 2759 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); |
| 2766 *num_parameters = entry.num_parameters(); | 2760 *num_parameters = entry.num_parameters(); |
| 2767 *function_length = entry.function_length(); | 2761 *function_length = entry.function_length(); |
| 2768 *has_duplicate_parameters = entry.has_duplicate_parameters(); | 2762 *has_duplicate_parameters = entry.has_duplicate_parameters(); |
| 2769 *materialized_literal_count = entry.literal_count(); | |
| 2770 *expected_property_count = entry.property_count(); | 2763 *expected_property_count = entry.property_count(); |
| 2771 SetLanguageMode(function_scope, entry.language_mode()); | 2764 SetLanguageMode(function_scope, entry.language_mode()); |
| 2772 if (entry.uses_super_property()) | 2765 if (entry.uses_super_property()) |
| 2773 function_scope->RecordSuperPropertyUsage(); | 2766 function_scope->RecordSuperPropertyUsage(); |
| 2774 if (entry.calls_eval()) function_scope->RecordEvalCall(); | 2767 if (entry.calls_eval()) function_scope->RecordEvalCall(); |
| 2775 SkipFunctionLiterals(entry.num_inner_functions()); | 2768 SkipFunctionLiterals(entry.num_inner_functions()); |
| 2776 return kLazyParsingComplete; | 2769 return kLazyParsingComplete; |
| 2777 } | 2770 } |
| 2778 cached_parse_data_->Reject(); | 2771 cached_parse_data_->Reject(); |
| 2779 } | 2772 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2817 return kLazyParsingComplete; | 2810 return kLazyParsingComplete; |
| 2818 } | 2811 } |
| 2819 PreParserLogger* logger = reusable_preparser_->logger(); | 2812 PreParserLogger* logger = reusable_preparser_->logger(); |
| 2820 function_scope->set_end_position(logger->end()); | 2813 function_scope->set_end_position(logger->end()); |
| 2821 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); | 2814 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); |
| 2822 total_preparse_skipped_ += | 2815 total_preparse_skipped_ += |
| 2823 function_scope->end_position() - function_scope->start_position(); | 2816 function_scope->end_position() - function_scope->start_position(); |
| 2824 *num_parameters = logger->num_parameters(); | 2817 *num_parameters = logger->num_parameters(); |
| 2825 *function_length = logger->function_length(); | 2818 *function_length = logger->function_length(); |
| 2826 *has_duplicate_parameters = logger->has_duplicate_parameters(); | 2819 *has_duplicate_parameters = logger->has_duplicate_parameters(); |
| 2827 *materialized_literal_count = logger->literals(); | |
| 2828 *expected_property_count = logger->properties(); | 2820 *expected_property_count = logger->properties(); |
| 2829 SkipFunctionLiterals(logger->num_inner_functions()); | 2821 SkipFunctionLiterals(logger->num_inner_functions()); |
| 2830 if (!is_inner_function && produce_cached_parse_data()) { | 2822 if (!is_inner_function && produce_cached_parse_data()) { |
| 2831 DCHECK(log_); | 2823 DCHECK(log_); |
| 2832 log_->LogFunction( | 2824 log_->LogFunction( |
| 2833 function_scope->start_position(), function_scope->end_position(), | 2825 function_scope->start_position(), function_scope->end_position(), |
| 2834 *num_parameters, *function_length, *has_duplicate_parameters, | 2826 *num_parameters, *function_length, *has_duplicate_parameters, |
| 2835 *materialized_literal_count, *expected_property_count, language_mode(), | 2827 *expected_property_count, language_mode(), |
| 2836 function_scope->uses_super_property(), function_scope->calls_eval(), | 2828 function_scope->uses_super_property(), function_scope->calls_eval(), |
| 2837 logger->num_inner_functions()); | 2829 logger->num_inner_functions()); |
| 2838 } | 2830 } |
| 2839 return kLazyParsingComplete; | 2831 return kLazyParsingComplete; |
| 2840 } | 2832 } |
| 2841 | 2833 |
| 2842 | 2834 |
| 2843 Statement* Parser::BuildAssertIsCoercible(Variable* var) { | 2835 Statement* Parser::BuildAssertIsCoercible(Variable* var) { |
| 2844 // if (var === null || var === undefined) | 2836 // if (var === null || var === undefined) |
| 2845 // throw /* type error kNonCoercible) */; | 2837 // throw /* type error kNonCoercible) */; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3104 // caused by calling the .throw method on a generator suspended at the | 3096 // caused by calling the .throw method on a generator suspended at the |
| 3105 // initial yield (i.e. right after generator instantiation). | 3097 // initial yield (i.e. right after generator instantiation). |
| 3106 return factory()->NewYield(generator, assignment, scope()->start_position(), | 3098 return factory()->NewYield(generator, assignment, scope()->start_position(), |
| 3107 Yield::kOnExceptionThrow); | 3099 Yield::kOnExceptionThrow); |
| 3108 } | 3100 } |
| 3109 | 3101 |
| 3110 ZoneList<Statement*>* Parser::ParseFunction( | 3102 ZoneList<Statement*>* Parser::ParseFunction( |
| 3111 const AstRawString* function_name, int pos, FunctionKind kind, | 3103 const AstRawString* function_name, int pos, FunctionKind kind, |
| 3112 FunctionLiteral::FunctionType function_type, | 3104 FunctionLiteral::FunctionType function_type, |
| 3113 DeclarationScope* function_scope, int* num_parameters, int* function_length, | 3105 DeclarationScope* function_scope, int* num_parameters, int* function_length, |
| 3114 bool* has_duplicate_parameters, int* materialized_literal_count, | 3106 bool* has_duplicate_parameters, int* expected_property_count, bool* ok) { |
| 3115 int* expected_property_count, bool* ok) { | |
| 3116 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY); | 3107 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY); |
| 3117 | 3108 |
| 3118 FunctionState function_state(&function_state_, &scope_state_, function_scope); | 3109 FunctionState function_state(&function_state_, &scope_state_, function_scope); |
| 3119 | 3110 |
| 3120 DuplicateFinder duplicate_finder; | 3111 DuplicateFinder duplicate_finder; |
| 3121 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 3112 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
| 3122 | 3113 |
| 3123 if (IsResumableFunction(kind)) PrepareGeneratorVariables(); | 3114 if (IsResumableFunction(kind)) PrepareGeneratorVariables(); |
| 3124 | 3115 |
| 3125 ParserFormalParameters formals(function_scope); | 3116 ParserFormalParameters formals(function_scope); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3143 is_sloppy(function_scope->language_mode()) && formals.is_simple && | 3134 is_sloppy(function_scope->language_mode()) && formals.is_simple && |
| 3144 !IsConciseMethod(kind); | 3135 !IsConciseMethod(kind); |
| 3145 ValidateFormalParameters(function_scope->language_mode(), | 3136 ValidateFormalParameters(function_scope->language_mode(), |
| 3146 allow_duplicate_parameters, CHECK_OK); | 3137 allow_duplicate_parameters, CHECK_OK); |
| 3147 | 3138 |
| 3148 RewriteDestructuringAssignments(); | 3139 RewriteDestructuringAssignments(); |
| 3149 | 3140 |
| 3150 *has_duplicate_parameters = | 3141 *has_duplicate_parameters = |
| 3151 !classifier()->is_valid_formal_parameter_list_without_duplicates(); | 3142 !classifier()->is_valid_formal_parameter_list_without_duplicates(); |
| 3152 | 3143 |
| 3153 *materialized_literal_count = function_state.materialized_literal_count(); | |
| 3154 *expected_property_count = function_state.expected_property_count(); | 3144 *expected_property_count = function_state.expected_property_count(); |
| 3155 return body; | 3145 return body; |
| 3156 } | 3146 } |
| 3157 | 3147 |
| 3158 void Parser::DeclareClassVariable(const AstRawString* name, | 3148 void Parser::DeclareClassVariable(const AstRawString* name, |
| 3159 ClassInfo* class_info, int class_token_pos, | 3149 ClassInfo* class_info, int class_token_pos, |
| 3160 bool* ok) { | 3150 bool* ok) { |
| 3161 #ifdef DEBUG | 3151 #ifdef DEBUG |
| 3162 scope()->SetScopeName(name); | 3152 scope()->SetScopeName(name); |
| 3163 #endif | 3153 #endif |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3509 | 3499 |
| 3510 expr = factory()->NewBinaryOperation( | 3500 expr = factory()->NewBinaryOperation( |
| 3511 Token::ADD, factory()->NewBinaryOperation( | 3501 Token::ADD, factory()->NewBinaryOperation( |
| 3512 Token::ADD, expr, middle, expr->position()), | 3502 Token::ADD, expr, middle, expr->position()), |
| 3513 cooked_str, sub->position()); | 3503 cooked_str, sub->position()); |
| 3514 } | 3504 } |
| 3515 return expr; | 3505 return expr; |
| 3516 } else { | 3506 } else { |
| 3517 uint32_t hash = ComputeTemplateLiteralHash(lit); | 3507 uint32_t hash = ComputeTemplateLiteralHash(lit); |
| 3518 | 3508 |
| 3519 // cooked and raw indexes. | |
| 3520 function_state_->NextMaterializedLiteralIndex(); | |
| 3521 function_state_->NextMaterializedLiteralIndex(); | |
| 3522 | |
| 3523 // $getTemplateCallSite | 3509 // $getTemplateCallSite |
| 3524 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); | 3510 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); |
| 3525 args->Add(factory()->NewArrayLiteral( | 3511 args->Add(factory()->NewArrayLiteral( |
| 3526 const_cast<ZoneList<Expression*>*>(cooked_strings), pos), | 3512 const_cast<ZoneList<Expression*>*>(cooked_strings), pos), |
| 3527 zone()); | 3513 zone()); |
| 3528 args->Add(factory()->NewArrayLiteral( | 3514 args->Add(factory()->NewArrayLiteral( |
| 3529 const_cast<ZoneList<Expression*>*>(raw_strings), pos), | 3515 const_cast<ZoneList<Expression*>*>(raw_strings), pos), |
| 3530 zone()); | 3516 zone()); |
| 3531 | 3517 |
| 3532 // Truncate hash to Smi-range. | 3518 // Truncate hash to Smi-range. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3617 int n = list->length(); | 3603 int n = list->length(); |
| 3618 while (i < n) { | 3604 while (i < n) { |
| 3619 if (!list->at(i)->IsSpread()) { | 3605 if (!list->at(i)->IsSpread()) { |
| 3620 ZoneList<Expression*>* unspread = | 3606 ZoneList<Expression*>* unspread = |
| 3621 new (zone()) ZoneList<Expression*>(1, zone()); | 3607 new (zone()) ZoneList<Expression*>(1, zone()); |
| 3622 | 3608 |
| 3623 // Push array of unspread parameters | 3609 // Push array of unspread parameters |
| 3624 while (i < n && !list->at(i)->IsSpread()) { | 3610 while (i < n && !list->at(i)->IsSpread()) { |
| 3625 unspread->Add(list->at(i++), zone()); | 3611 unspread->Add(list->at(i++), zone()); |
| 3626 } | 3612 } |
| 3627 function_state_->NextMaterializedLiteralIndex(); | |
| 3628 args->Add(factory()->NewArrayLiteral(unspread, kNoSourcePosition), | 3613 args->Add(factory()->NewArrayLiteral(unspread, kNoSourcePosition), |
| 3629 zone()); | 3614 zone()); |
| 3630 | 3615 |
| 3631 if (i == n) break; | 3616 if (i == n) break; |
| 3632 } | 3617 } |
| 3633 | 3618 |
| 3634 // Push eagerly spread argument | 3619 // Push eagerly spread argument |
| 3635 ZoneList<Expression*>* spread_list = | 3620 ZoneList<Expression*>* spread_list = |
| 3636 new (zone()) ZoneList<Expression*>(1, zone()); | 3621 new (zone()) ZoneList<Expression*>(1, zone()); |
| 3637 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); | 3622 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); |
| (...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5018 | 5003 |
| 5019 return final_loop; | 5004 return final_loop; |
| 5020 } | 5005 } |
| 5021 | 5006 |
| 5022 #undef CHECK_OK | 5007 #undef CHECK_OK |
| 5023 #undef CHECK_OK_VOID | 5008 #undef CHECK_OK_VOID |
| 5024 #undef CHECK_FAILED | 5009 #undef CHECK_FAILED |
| 5025 | 5010 |
| 5026 } // namespace internal | 5011 } // namespace internal |
| 5027 } // namespace v8 | 5012 } // namespace v8 |
| OLD | NEW |