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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 scanner_(info->unicode_cache()), | 509 scanner_(info->unicode_cache()), |
510 reusable_preparser_(nullptr), | 510 reusable_preparser_(nullptr), |
511 original_scope_(nullptr), | 511 original_scope_(nullptr), |
512 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 512 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
513 target_stack_(nullptr), | 513 target_stack_(nullptr), |
514 compile_options_(info->compile_options()), | 514 compile_options_(info->compile_options()), |
515 cached_parse_data_(nullptr), | 515 cached_parse_data_(nullptr), |
516 total_preparse_skipped_(0), | 516 total_preparse_skipped_(0), |
517 temp_zoned_(false), | 517 temp_zoned_(false), |
518 log_(nullptr), | 518 log_(nullptr), |
519 preparsed_scope_data_(info->preparsed_scope_data()) { | 519 preparsed_scope_data_(info->preparsed_scope_data()), |
| 520 parameters_end_pos_(info->parameters_end_pos()) { |
520 // Even though we were passed ParseInfo, we should not store it in | 521 // Even though we were passed ParseInfo, we should not store it in |
521 // Parser - this makes sure that Isolate is not accidentally accessed via | 522 // Parser - this makes sure that Isolate is not accidentally accessed via |
522 // ParseInfo during background parsing. | 523 // ParseInfo during background parsing. |
523 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 524 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
524 info->character_stream() != nullptr); | 525 info->character_stream() != nullptr); |
525 // Determine if functions can be lazily compiled. This is necessary to | 526 // Determine if functions can be lazily compiled. This is necessary to |
526 // allow some of our builtin JS files to be lazily compiled. These | 527 // allow some of our builtin JS files to be lazily compiled. These |
527 // builtins cannot be handled lazily by the parser, since we have to know | 528 // builtins cannot be handled lazily by the parser, since we have to know |
528 // if a function uses the special natives syntax, which is something the | 529 // if a function uses the special natives syntax, which is something the |
529 // parser records. | 530 // parser records. |
(...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2742 } | 2743 } |
2743 return function_literal; | 2744 return function_literal; |
2744 } | 2745 } |
2745 | 2746 |
2746 Parser::LazyParsingResult Parser::SkipFunction( | 2747 Parser::LazyParsingResult Parser::SkipFunction( |
2747 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, | 2748 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, |
2748 int* function_length, bool* has_duplicate_parameters, | 2749 int* function_length, bool* has_duplicate_parameters, |
2749 int* expected_property_count, bool is_inner_function, bool may_abort, | 2750 int* expected_property_count, bool is_inner_function, bool may_abort, |
2750 bool* ok) { | 2751 bool* ok) { |
2751 DCHECK_NE(kNoSourcePosition, function_scope->start_position()); | 2752 DCHECK_NE(kNoSourcePosition, function_scope->start_position()); |
| 2753 DCHECK_EQ(kNoSourcePosition, parameters_end_pos_); |
2752 if (produce_cached_parse_data()) CHECK(log_); | 2754 if (produce_cached_parse_data()) CHECK(log_); |
2753 | 2755 |
2754 DCHECK_IMPLIES(IsArrowFunction(kind), | 2756 DCHECK_IMPLIES(IsArrowFunction(kind), |
2755 scanner()->current_token() == Token::ARROW); | 2757 scanner()->current_token() == Token::ARROW); |
2756 | 2758 |
2757 // Inner functions are not part of the cached data. | 2759 // Inner functions are not part of the cached data. |
2758 if (!is_inner_function && consume_cached_parse_data() && | 2760 if (!is_inner_function && consume_cached_parse_data() && |
2759 !cached_parse_data_->rejected()) { | 2761 !cached_parse_data_->rejected()) { |
2760 // If we have cached data, we use it to skip parsing the function. The data | 2762 // If we have cached data, we use it to skip parsing the function. The data |
2761 // contains the information we need to construct the lazy function. | 2763 // contains the information we need to construct the lazy function. |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3120 bool* has_duplicate_parameters, int* expected_property_count, bool* ok) { | 3122 bool* has_duplicate_parameters, int* expected_property_count, bool* ok) { |
3121 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY); | 3123 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY); |
3122 | 3124 |
3123 FunctionState function_state(&function_state_, &scope_state_, function_scope); | 3125 FunctionState function_state(&function_state_, &scope_state_, function_scope); |
3124 | 3126 |
3125 DuplicateFinder duplicate_finder; | 3127 DuplicateFinder duplicate_finder; |
3126 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 3128 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
3127 | 3129 |
3128 if (IsResumableFunction(kind)) PrepareGeneratorVariables(); | 3130 if (IsResumableFunction(kind)) PrepareGeneratorVariables(); |
3129 | 3131 |
| 3132 int expected_parameters_end_pos = parameters_end_pos_; |
| 3133 if (expected_parameters_end_pos != kNoSourcePosition) { |
| 3134 // This is the first function encountered in a CreateDynamicFunction eval. |
| 3135 parameters_end_pos_ = kNoSourcePosition; |
| 3136 // The function name should have been ignored, giving us the empty string |
| 3137 // here. |
| 3138 DCHECK_EQ(function_name, ast_value_factory()->empty_string()); |
| 3139 } |
| 3140 |
3130 ParserFormalParameters formals(function_scope); | 3141 ParserFormalParameters formals(function_scope); |
3131 ParseFormalParameterList(&formals, CHECK_OK); | 3142 ParseFormalParameterList(&formals, CHECK_OK); |
| 3143 if (expected_parameters_end_pos != kNoSourcePosition) { |
| 3144 // Check for '(' or ')' shenanigans in the parameter string for dynamic |
| 3145 // functions. |
| 3146 int position = peek_position(); |
| 3147 if (position < expected_parameters_end_pos) { |
| 3148 ReportMessageAt(Scanner::Location(position, position + 1), |
| 3149 MessageTemplate::kArgStringTerminatesParametersEarly); |
| 3150 *ok = false; |
| 3151 return nullptr; |
| 3152 } else if (position > expected_parameters_end_pos) { |
| 3153 ReportMessageAt(Scanner::Location(expected_parameters_end_pos - 2, |
| 3154 expected_parameters_end_pos), |
| 3155 MessageTemplate::kUnexpectedEndOfArgString); |
| 3156 *ok = false; |
| 3157 return nullptr; |
| 3158 } |
| 3159 } |
3132 Expect(Token::RPAREN, CHECK_OK); | 3160 Expect(Token::RPAREN, CHECK_OK); |
3133 int formals_end_position = scanner()->location().end_pos; | 3161 int formals_end_position = scanner()->location().end_pos; |
3134 *num_parameters = formals.num_parameters(); | 3162 *num_parameters = formals.num_parameters(); |
3135 *function_length = formals.function_length; | 3163 *function_length = formals.function_length; |
3136 | 3164 |
3137 CheckArityRestrictions(formals.arity, kind, formals.has_rest, | 3165 CheckArityRestrictions(formals.arity, kind, formals.has_rest, |
3138 function_scope->start_position(), formals_end_position, | 3166 function_scope->start_position(), formals_end_position, |
3139 CHECK_OK); | 3167 CHECK_OK); |
3140 Expect(Token::LBRACE, CHECK_OK); | 3168 Expect(Token::LBRACE, CHECK_OK); |
3141 | 3169 |
(...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5036 | 5064 |
5037 return final_loop; | 5065 return final_loop; |
5038 } | 5066 } |
5039 | 5067 |
5040 #undef CHECK_OK | 5068 #undef CHECK_OK |
5041 #undef CHECK_OK_VOID | 5069 #undef CHECK_OK_VOID |
5042 #undef CHECK_FAILED | 5070 #undef CHECK_FAILED |
5043 | 5071 |
5044 } // namespace internal | 5072 } // namespace internal |
5045 } // namespace v8 | 5073 } // namespace v8 |
OLD | NEW |