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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 true), | 579 true), |
580 scanner_(info->unicode_cache()), | 580 scanner_(info->unicode_cache()), |
581 reusable_preparser_(nullptr), | 581 reusable_preparser_(nullptr), |
582 original_scope_(nullptr), | 582 original_scope_(nullptr), |
583 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 583 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
584 target_stack_(nullptr), | 584 target_stack_(nullptr), |
585 compile_options_(info->compile_options()), | 585 compile_options_(info->compile_options()), |
586 cached_parse_data_(nullptr), | 586 cached_parse_data_(nullptr), |
587 total_preparse_skipped_(0), | 587 total_preparse_skipped_(0), |
588 temp_zoned_(false), | 588 temp_zoned_(false), |
589 log_(nullptr) { | 589 log_(nullptr), |
590 parameters_end_pos_(info->parameters_end_pos()) { | |
590 // Even though we were passed ParseInfo, we should not store it in | 591 // Even though we were passed ParseInfo, we should not store it in |
591 // Parser - this makes sure that Isolate is not accidentally accessed via | 592 // Parser - this makes sure that Isolate is not accidentally accessed via |
592 // ParseInfo during background parsing. | 593 // ParseInfo during background parsing. |
593 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 594 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
594 info->character_stream() != nullptr); | 595 info->character_stream() != nullptr); |
595 // Determine if functions can be lazily compiled. This is necessary to | 596 // Determine if functions can be lazily compiled. This is necessary to |
596 // allow some of our builtin JS files to be lazily compiled. These | 597 // allow some of our builtin JS files to be lazily compiled. These |
597 // builtins cannot be handled lazily by the parser, since we have to know | 598 // builtins cannot be handled lazily by the parser, since we have to know |
598 // if a function uses the special natives syntax, which is something the | 599 // if a function uses the special natives syntax, which is something the |
599 // parser records. | 600 // parser records. |
(...skipping 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3159 int* expected_property_count, bool* ok) { | 3160 int* expected_property_count, bool* ok) { |
3160 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY); | 3161 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY); |
3161 | 3162 |
3162 FunctionState function_state(&function_state_, &scope_state_, function_scope); | 3163 FunctionState function_state(&function_state_, &scope_state_, function_scope); |
3163 | 3164 |
3164 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 3165 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
3165 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 3166 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
3166 | 3167 |
3167 if (IsGeneratorFunction(kind)) PrepareGeneratorVariables(&function_state); | 3168 if (IsGeneratorFunction(kind)) PrepareGeneratorVariables(&function_state); |
3168 | 3169 |
3170 int expected_parameters_end_pos = parameters_end_pos_; | |
3171 if (expected_parameters_end_pos != kNoSourcePosition) { | |
3172 // This is the first function encountered in an only-single-function eval. | |
Dan Ehrenberg
2016/12/06 00:32:13
I thought this happens only in the Function constr
jwolfe
2017/01/13 00:28:48
Updated comment to be more clear.
| |
3173 parameters_end_pos_ = kNoSourcePosition; | |
3174 // The function name should have been ignored, giving us null here. | |
3175 DCHECK_NULL(function_name); | |
3176 } | |
3177 | |
3169 ParserFormalParameters formals(function_scope); | 3178 ParserFormalParameters formals(function_scope); |
3170 ParseFormalParameterList(&formals, CHECK_OK); | 3179 ParseFormalParameterList(&formals, CHECK_OK); |
3180 if (expected_parameters_end_pos != kNoSourcePosition) { | |
3181 // Check for '(' or ')' shenanigans in the parameter string for dynamic | |
3182 // functions. | |
3183 if (peek_position() != expected_parameters_end_pos) { | |
3184 ReportMessageAt(Scanner::Location(expected_parameters_end_pos, | |
3185 expected_parameters_end_pos + 1), | |
3186 MessageTemplate::kExpectedEndOfParameters); | |
Dan Ehrenberg
2016/12/06 00:32:13
Will CreateDynamicFunction always trigger eager co
jwolfe
2017/01/13 00:28:47
Done. It looks like it's always eagerly parsed. I
| |
3187 *ok = false; | |
3188 return nullptr; | |
3189 } | |
3190 } | |
3171 Expect(Token::RPAREN, CHECK_OK); | 3191 Expect(Token::RPAREN, CHECK_OK); |
3172 int formals_end_position = scanner()->location().end_pos; | 3192 int formals_end_position = scanner()->location().end_pos; |
3173 *num_parameters = formals.num_parameters(); | 3193 *num_parameters = formals.num_parameters(); |
3174 *function_length = formals.function_length; | 3194 *function_length = formals.function_length; |
3175 | 3195 |
3176 CheckArityRestrictions(formals.arity, kind, formals.has_rest, | 3196 CheckArityRestrictions(formals.arity, kind, formals.has_rest, |
3177 function_scope->start_position(), formals_end_position, | 3197 function_scope->start_position(), formals_end_position, |
3178 CHECK_OK); | 3198 CHECK_OK); |
3179 Expect(Token::LBRACE, CHECK_OK); | 3199 Expect(Token::LBRACE, CHECK_OK); |
3180 | 3200 |
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5477 | 5497 |
5478 return final_loop; | 5498 return final_loop; |
5479 } | 5499 } |
5480 | 5500 |
5481 #undef CHECK_OK | 5501 #undef CHECK_OK |
5482 #undef CHECK_OK_VOID | 5502 #undef CHECK_OK_VOID |
5483 #undef CHECK_FAILED | 5503 #undef CHECK_FAILED |
5484 | 5504 |
5485 } // namespace internal | 5505 } // namespace internal |
5486 } // namespace v8 | 5506 } // namespace v8 |
OLD | NEW |