Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/parsing/parser.cc

Issue 2156303002: Implement new Function.prototype.toString and fix CreateDynamicFunction parsing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 scanner_(info->unicode_cache()), 512 scanner_(info->unicode_cache()),
513 reusable_preparser_(nullptr), 513 reusable_preparser_(nullptr),
514 original_scope_(nullptr), 514 original_scope_(nullptr),
515 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. 515 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
516 target_stack_(nullptr), 516 target_stack_(nullptr),
517 compile_options_(info->compile_options()), 517 compile_options_(info->compile_options()),
518 cached_parse_data_(nullptr), 518 cached_parse_data_(nullptr),
519 total_preparse_skipped_(0), 519 total_preparse_skipped_(0),
520 temp_zoned_(false), 520 temp_zoned_(false),
521 log_(nullptr), 521 log_(nullptr),
522 preparsed_scope_data_(info->preparsed_scope_data()) { 522 preparsed_scope_data_(info->preparsed_scope_data()),
523 parameters_end_pos_(info->parameters_end_pos()) {
523 // Even though we were passed ParseInfo, we should not store it in 524 // Even though we were passed ParseInfo, we should not store it in
524 // Parser - this makes sure that Isolate is not accidentally accessed via 525 // Parser - this makes sure that Isolate is not accidentally accessed via
525 // ParseInfo during background parsing. 526 // ParseInfo during background parsing.
526 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || 527 DCHECK(!info->script().is_null() || info->source_stream() != nullptr ||
527 info->character_stream() != nullptr); 528 info->character_stream() != nullptr);
528 // Determine if functions can be lazily compiled. This is necessary to 529 // Determine if functions can be lazily compiled. This is necessary to
529 // allow some of our builtin JS files to be lazily compiled. These 530 // allow some of our builtin JS files to be lazily compiled. These
530 // builtins cannot be handled lazily by the parser, since we have to know 531 // builtins cannot be handled lazily by the parser, since we have to know
531 // if a function uses the special natives syntax, which is something the 532 // if a function uses the special natives syntax, which is something the
532 // parser records. 533 // parser records.
(...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 } 2736 }
2736 return function_literal; 2737 return function_literal;
2737 } 2738 }
2738 2739
2739 Parser::LazyParsingResult Parser::SkipFunction( 2740 Parser::LazyParsingResult Parser::SkipFunction(
2740 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, 2741 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters,
2741 int* function_length, bool* has_duplicate_parameters, 2742 int* function_length, bool* has_duplicate_parameters,
2742 int* materialized_literal_count, int* expected_property_count, 2743 int* materialized_literal_count, int* expected_property_count,
2743 bool is_inner_function, bool may_abort, bool* ok) { 2744 bool is_inner_function, bool may_abort, bool* ok) {
2744 DCHECK_NE(kNoSourcePosition, function_scope->start_position()); 2745 DCHECK_NE(kNoSourcePosition, function_scope->start_position());
2746 DCHECK_EQ(kNoSourcePosition, parameters_end_pos_);
2745 if (produce_cached_parse_data()) CHECK(log_); 2747 if (produce_cached_parse_data()) CHECK(log_);
2746 2748
2747 DCHECK_IMPLIES(IsArrowFunction(kind), 2749 DCHECK_IMPLIES(IsArrowFunction(kind),
2748 scanner()->current_token() == Token::ARROW); 2750 scanner()->current_token() == Token::ARROW);
2749 2751
2750 // Inner functions are not part of the cached data. 2752 // Inner functions are not part of the cached data.
2751 if (!is_inner_function && consume_cached_parse_data() && 2753 if (!is_inner_function && consume_cached_parse_data() &&
2752 !cached_parse_data_->rejected()) { 2754 !cached_parse_data_->rejected()) {
2753 // If we have cached data, we use it to skip parsing the function. The data 2755 // 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. 2756 // contains the information we need to construct the lazy function.
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
3115 int* expected_property_count, bool* ok) { 3117 int* expected_property_count, bool* ok) {
3116 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY); 3118 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
3117 3119
3118 FunctionState function_state(&function_state_, &scope_state_, function_scope); 3120 FunctionState function_state(&function_state_, &scope_state_, function_scope);
3119 3121
3120 DuplicateFinder duplicate_finder; 3122 DuplicateFinder duplicate_finder;
3121 ExpressionClassifier formals_classifier(this, &duplicate_finder); 3123 ExpressionClassifier formals_classifier(this, &duplicate_finder);
3122 3124
3123 if (IsResumableFunction(kind)) PrepareGeneratorVariables(); 3125 if (IsResumableFunction(kind)) PrepareGeneratorVariables();
3124 3126
3127 int expected_parameters_end_pos = parameters_end_pos_;
3128 if (expected_parameters_end_pos != kNoSourcePosition) {
3129 // This is the first function encountered in a CreateDynamicFunction eval.
3130 parameters_end_pos_ = kNoSourcePosition;
3131 // The function name should have been ignored, giving us the empty string
3132 // here.
3133 DCHECK_EQ(function_name, ast_value_factory()->empty_string());
3134 }
3135
3125 ParserFormalParameters formals(function_scope); 3136 ParserFormalParameters formals(function_scope);
3126 ParseFormalParameterList(&formals, CHECK_OK); 3137 ParseFormalParameterList(&formals, CHECK_OK);
3138 if (expected_parameters_end_pos != kNoSourcePosition) {
3139 // Check for '(' or ')' shenanigans in the parameter string for dynamic
3140 // functions.
3141 int position = peek_position();
3142 if (position < expected_parameters_end_pos) {
3143 ReportMessageAt(Scanner::Location(position, position + 1),
3144 MessageTemplate::kArgStringTerminatesParametersEarly);
3145 *ok = false;
3146 return nullptr;
3147 } else if (position > expected_parameters_end_pos) {
Dan Ehrenberg 2017/02/13 17:32:32 Optional: This branch will always be taken if we r
jwolfe 2017/02/13 21:31:05 The case where position == expected_parameters_end
3148 ReportMessageAt(Scanner::Location(expected_parameters_end_pos - 2,
3149 expected_parameters_end_pos),
3150 MessageTemplate::kUnexpectedEndOfArgString);
3151 *ok = false;
3152 return nullptr;
3153 }
3154 }
3127 Expect(Token::RPAREN, CHECK_OK); 3155 Expect(Token::RPAREN, CHECK_OK);
3128 int formals_end_position = scanner()->location().end_pos; 3156 int formals_end_position = scanner()->location().end_pos;
3129 *num_parameters = formals.num_parameters(); 3157 *num_parameters = formals.num_parameters();
3130 *function_length = formals.function_length; 3158 *function_length = formals.function_length;
3131 3159
3132 CheckArityRestrictions(formals.arity, kind, formals.has_rest, 3160 CheckArityRestrictions(formals.arity, kind, formals.has_rest,
3133 function_scope->start_position(), formals_end_position, 3161 function_scope->start_position(), formals_end_position,
3134 CHECK_OK); 3162 CHECK_OK);
3135 Expect(Token::LBRACE, CHECK_OK); 3163 Expect(Token::LBRACE, CHECK_OK);
3136 3164
(...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after
5018 5046
5019 return final_loop; 5047 return final_loop;
5020 } 5048 }
5021 5049
5022 #undef CHECK_OK 5050 #undef CHECK_OK
5023 #undef CHECK_OK_VOID 5051 #undef CHECK_OK_VOID
5024 #undef CHECK_FAILED 5052 #undef CHECK_FAILED
5025 5053
5026 } // namespace internal 5054 } // namespace internal
5027 } // namespace v8 5055 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698