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

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

Issue 1776683003: Remove destructuring and default arguments runtime flags (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 4 years, 9 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
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 parsing_on_main_thread_(true) { 772 parsing_on_main_thread_(true) {
773 // Even though we were passed ParseInfo, we should not store it in 773 // Even though we were passed ParseInfo, we should not store it in
774 // Parser - this makes sure that Isolate is not accidentally accessed via 774 // Parser - this makes sure that Isolate is not accidentally accessed via
775 // ParseInfo during background parsing. 775 // ParseInfo during background parsing.
776 DCHECK(!info->script().is_null() || info->source_stream() != NULL); 776 DCHECK(!info->script().is_null() || info->source_stream() != NULL);
777 set_allow_lazy(info->allow_lazy_parsing()); 777 set_allow_lazy(info->allow_lazy_parsing());
778 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 778 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
779 set_allow_harmony_sloppy(FLAG_harmony_sloppy); 779 set_allow_harmony_sloppy(FLAG_harmony_sloppy);
780 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); 780 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function);
781 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); 781 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let);
782 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters);
783 set_allow_harmony_destructuring_bind(FLAG_harmony_destructuring_bind);
784 set_allow_harmony_destructuring_assignment(
785 FLAG_harmony_destructuring_assignment);
786 set_allow_legacy_const(FLAG_legacy_const); 782 set_allow_legacy_const(FLAG_legacy_const);
787 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 783 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
788 set_allow_harmony_function_name(FLAG_harmony_function_name); 784 set_allow_harmony_function_name(FLAG_harmony_function_name);
789 set_allow_harmony_function_sent(FLAG_harmony_function_sent); 785 set_allow_harmony_function_sent(FLAG_harmony_function_sent);
790 set_allow_harmony_restrictive_declarations( 786 set_allow_harmony_restrictive_declarations(
791 FLAG_harmony_restrictive_declarations); 787 FLAG_harmony_restrictive_declarations);
792 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 788 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
793 ++feature) { 789 ++feature) {
794 use_counts_[feature] = 0; 790 use_counts_[feature] = 0;
795 } 791 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 if (ok && is_strict(language_mode())) { 930 if (ok && is_strict(language_mode())) {
935 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 931 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
936 } 932 }
937 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) { 933 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) {
938 // TODO(littledan): Function bindings on the global object that modify 934 // TODO(littledan): Function bindings on the global object that modify
939 // pre-existing bindings should be made writable, enumerable and 935 // pre-existing bindings should be made writable, enumerable and
940 // nonconfigurable if possible, whereas this code will leave attributes 936 // nonconfigurable if possible, whereas this code will leave attributes
941 // unchanged if the property already exists. 937 // unchanged if the property already exists.
942 InsertSloppyBlockFunctionVarBindings(scope, &ok); 938 InsertSloppyBlockFunctionVarBindings(scope, &ok);
943 } 939 }
944 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy() || 940 if (ok) {
945 allow_harmony_destructuring_bind())) {
946 CheckConflictingVarDeclarations(scope_, &ok); 941 CheckConflictingVarDeclarations(scope_, &ok);
947 } 942 }
948 943
949 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 944 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
950 if (body->length() != 1 || 945 if (body->length() != 1 ||
951 !body->at(0)->IsExpressionStatement() || 946 !body->at(0)->IsExpressionStatement() ||
952 !body->at(0)->AsExpressionStatement()-> 947 !body->at(0)->AsExpressionStatement()->
953 expression()->IsFunctionLiteral()) { 948 expression()->IsFunctionLiteral()) {
954 ReportMessage(MessageTemplate::kSingleFunctionLiteral); 949 ReportMessage(MessageTemplate::kSingleFunctionLiteral);
955 ok = false; 950 ok = false;
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 do { 2311 do {
2317 FuncNameInferrer::State fni_state(fni_); 2312 FuncNameInferrer::State fni_state(fni_);
2318 2313
2319 // Parse name. 2314 // Parse name.
2320 if (!first_declaration) Consume(Token::COMMA); 2315 if (!first_declaration) Consume(Token::COMMA);
2321 2316
2322 Expression* pattern; 2317 Expression* pattern;
2323 int decl_pos = peek_position(); 2318 int decl_pos = peek_position();
2324 { 2319 {
2325 ExpressionClassifier pattern_classifier(this); 2320 ExpressionClassifier pattern_classifier(this);
2326 Token::Value next = peek();
2327 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); 2321 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
2328 ValidateBindingPattern(&pattern_classifier, CHECK_OK); 2322 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
2329 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) { 2323 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) {
2330 ValidateLetPattern(&pattern_classifier, CHECK_OK); 2324 ValidateLetPattern(&pattern_classifier, CHECK_OK);
2331 } 2325 }
2332 if (!allow_harmony_destructuring_bind() && !pattern->IsVariableProxy()) {
2333 ReportUnexpectedToken(next);
2334 *ok = false;
2335 return nullptr;
2336 }
2337 } 2326 }
2338 2327
2339 Scanner::Location variable_loc = scanner()->location(); 2328 Scanner::Location variable_loc = scanner()->location();
2340 const AstRawString* single_name = 2329 const AstRawString* single_name =
2341 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() 2330 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name()
2342 : nullptr; 2331 : nullptr;
2343 if (single_name != nullptr) { 2332 if (single_name != nullptr) {
2344 if (fni_ != NULL) fni_->PushVariableName(single_name); 2333 if (fni_ != NULL) fni_->PushVariableName(single_name);
2345 } 2334 }
2346 2335
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
3140 3129
3141 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 3130 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
3142 Expression* each, Expression* subject, 3131 Expression* each, Expression* subject,
3143 Statement* body) { 3132 Statement* body) {
3144 ForOfStatement* for_of = stmt->AsForOfStatement(); 3133 ForOfStatement* for_of = stmt->AsForOfStatement();
3145 if (for_of != NULL) { 3134 if (for_of != NULL) {
3146 InitializeForOfStatement(for_of, each, subject, body, 3135 InitializeForOfStatement(for_of, each, subject, body,
3147 RelocInfo::kNoPosition); 3136 RelocInfo::kNoPosition);
3148 } else { 3137 } else {
3149 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { 3138 if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
3150 DCHECK(allow_harmony_destructuring_assignment());
3151 Variable* temp = 3139 Variable* temp =
3152 scope_->NewTemporary(ast_value_factory()->empty_string()); 3140 scope_->NewTemporary(ast_value_factory()->empty_string());
3153 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3141 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3154 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( 3142 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment(
3155 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, 3143 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy,
3156 RelocInfo::kNoPosition), 3144 RelocInfo::kNoPosition),
3157 scope_); 3145 scope_);
3158 auto block = 3146 auto block =
3159 factory()->NewBlock(nullptr, 2, false, RelocInfo::kNoPosition); 3147 factory()->NewBlock(nullptr, 2, false, RelocInfo::kNoPosition);
3160 block->statements()->Add(factory()->NewExpressionStatement( 3148 block->statements()->Add(factory()->NewExpressionStatement(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3216 // each = result.value 3204 // each = result.value
3217 { 3205 {
3218 Expression* value_literal = factory()->NewStringLiteral( 3206 Expression* value_literal = factory()->NewStringLiteral(
3219 ast_value_factory()->value_string(), RelocInfo::kNoPosition); 3207 ast_value_factory()->value_string(), RelocInfo::kNoPosition);
3220 Expression* result_proxy = factory()->NewVariableProxy(result); 3208 Expression* result_proxy = factory()->NewVariableProxy(result);
3221 Expression* result_value = factory()->NewProperty( 3209 Expression* result_value = factory()->NewProperty(
3222 result_proxy, value_literal, RelocInfo::kNoPosition); 3210 result_proxy, value_literal, RelocInfo::kNoPosition);
3223 assign_each = factory()->NewAssignment(Token::ASSIGN, each, result_value, 3211 assign_each = factory()->NewAssignment(Token::ASSIGN, each, result_value,
3224 RelocInfo::kNoPosition); 3212 RelocInfo::kNoPosition);
3225 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { 3213 if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
3226 DCHECK(allow_harmony_destructuring_assignment());
3227 assign_each = PatternRewriter::RewriteDestructuringAssignment( 3214 assign_each = PatternRewriter::RewriteDestructuringAssignment(
3228 this, assign_each->AsAssignment(), scope_); 3215 this, assign_each->AsAssignment(), scope_);
3229 } 3216 }
3230 } 3217 }
3231 3218
3232 for_of->Initialize(each, iterable, body, iterator, assign_iterator, 3219 for_of->Initialize(each, iterable, body, iterator, assign_iterator,
3233 next_result, result_done, assign_each); 3220 next_result, result_done, assign_each);
3234 } 3221 }
3235 3222
3236 Statement* Parser::DesugarLexicalBindingsInForStatement( 3223 Statement* Parser::DesugarLexicalBindingsInForStatement(
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
3693 Expression* expression = ParseExpression(false, &classifier, CHECK_OK); 3680 Expression* expression = ParseExpression(false, &classifier, CHECK_OK);
3694 int lhs_end_pos = scanner()->location().end_pos; 3681 int lhs_end_pos = scanner()->location().end_pos;
3695 ForEachStatement::VisitMode mode = ForEachStatement::ENUMERATE; 3682 ForEachStatement::VisitMode mode = ForEachStatement::ENUMERATE;
3696 is_let_identifier_expression = 3683 is_let_identifier_expression =
3697 expression->IsVariableProxy() && 3684 expression->IsVariableProxy() &&
3698 expression->AsVariableProxy()->raw_name() == 3685 expression->AsVariableProxy()->raw_name() ==
3699 ast_value_factory()->let_string(); 3686 ast_value_factory()->let_string();
3700 3687
3701 bool is_for_each = CheckInOrOf(&mode, ok); 3688 bool is_for_each = CheckInOrOf(&mode, ok);
3702 if (!*ok) return nullptr; 3689 if (!*ok) return nullptr;
3703 bool is_destructuring = 3690 bool is_destructuring = is_for_each && (expression->IsArrayLiteral() ||
3704 is_for_each && allow_harmony_destructuring_assignment() && 3691 expression->IsObjectLiteral());
3705 (expression->IsArrayLiteral() || expression->IsObjectLiteral());
3706 3692
3707 if (is_destructuring) { 3693 if (is_destructuring) {
3708 ValidateAssignmentPattern(&classifier, CHECK_OK); 3694 ValidateAssignmentPattern(&classifier, CHECK_OK);
3709 } else { 3695 } else {
3710 RewriteNonPattern(&classifier, CHECK_OK); 3696 RewriteNonPattern(&classifier, CHECK_OK);
3711 } 3697 }
3712 3698
3713 if (is_for_each) { 3699 if (is_for_each) {
3714 if (!is_destructuring) { 3700 if (!is_destructuring) {
3715 expression = this->CheckAndRewriteReferenceExpression( 3701 expression = this->CheckAndRewriteReferenceExpression(
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 Expression* initializer = nullptr; 3935 Expression* initializer = nullptr;
3950 if (expr->IsVariableProxy()) { 3936 if (expr->IsVariableProxy()) {
3951 // When the formal parameter was originally seen, it was parsed as a 3937 // When the formal parameter was originally seen, it was parsed as a
3952 // VariableProxy and recorded as unresolved in the scope. Here we undo that 3938 // VariableProxy and recorded as unresolved in the scope. Here we undo that
3953 // parse-time side-effect for parameters that are single-names (not 3939 // parse-time side-effect for parameters that are single-names (not
3954 // patterns; for patterns that happens uniformly in 3940 // patterns; for patterns that happens uniformly in
3955 // PatternRewriter::VisitVariableProxy). 3941 // PatternRewriter::VisitVariableProxy).
3956 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); 3942 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
3957 } else if (expr->IsAssignment()) { 3943 } else if (expr->IsAssignment()) {
3958 Assignment* assignment = expr->AsAssignment(); 3944 Assignment* assignment = expr->AsAssignment();
3959 DCHECK(parser_->allow_harmony_default_parameters());
3960 DCHECK(!assignment->is_compound()); 3945 DCHECK(!assignment->is_compound());
3961 initializer = assignment->value(); 3946 initializer = assignment->value();
3962 expr = assignment->target(); 3947 expr = assignment->target();
3963 3948
3964 // TODO(adamk): Only call this if necessary. 3949 // TODO(adamk): Only call this if necessary.
3965 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, 3950 RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
3966 parser_->scope_, parameters->scope); 3951 parser_->scope_, parameters->scope);
3967 } 3952 }
3968 3953
3969 // TODO(adamk): params_loc.end_pos is not the correct initializer position, 3954 // TODO(adamk): params_loc.end_pos is not the correct initializer position,
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 ValidateFormalParameters(&formals_classifier, language_mode, 4251 ValidateFormalParameters(&formals_classifier, language_mode,
4267 allow_duplicate_parameters, CHECK_OK); 4252 allow_duplicate_parameters, CHECK_OK);
4268 4253
4269 if (is_strict(language_mode)) { 4254 if (is_strict(language_mode)) {
4270 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 4255 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4271 CHECK_OK); 4256 CHECK_OK);
4272 } 4257 }
4273 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { 4258 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) {
4274 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); 4259 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK);
4275 } 4260 }
4276 if (is_strict(language_mode) || allow_harmony_sloppy() || 4261 CheckConflictingVarDeclarations(scope, CHECK_OK);
4277 allow_harmony_destructuring_bind()) {
4278 CheckConflictingVarDeclarations(scope, CHECK_OK);
4279 }
4280 4262
4281 if (body) { 4263 if (body) {
4282 // If body can be inspected, rewrite queued destructuring assignments 4264 // If body can be inspected, rewrite queued destructuring assignments
4283 ParserTraits::RewriteDestructuringAssignments(); 4265 ParserTraits::RewriteDestructuringAssignments();
4284 } 4266 }
4285 has_duplicate_parameters = 4267 has_duplicate_parameters =
4286 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4268 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4287 } 4269 }
4288 4270
4289 FunctionLiteral::ParameterFlag duplicate_parameters = 4271 FunctionLiteral::ParameterFlag duplicate_parameters =
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
4688 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); 4670 DCHECK_EQ(Token::LBRACE, scanner()->current_token());
4689 4671
4690 if (reusable_preparser_ == NULL) { 4672 if (reusable_preparser_ == NULL) {
4691 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), 4673 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(),
4692 NULL, stack_limit_); 4674 NULL, stack_limit_);
4693 reusable_preparser_->set_allow_lazy(true); 4675 reusable_preparser_->set_allow_lazy(true);
4694 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 4676 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
4695 SET_ALLOW(natives); 4677 SET_ALLOW(natives);
4696 SET_ALLOW(harmony_sloppy); 4678 SET_ALLOW(harmony_sloppy);
4697 SET_ALLOW(harmony_sloppy_let); 4679 SET_ALLOW(harmony_sloppy_let);
4698 SET_ALLOW(harmony_default_parameters);
4699 SET_ALLOW(harmony_destructuring_bind);
4700 SET_ALLOW(harmony_destructuring_assignment);
4701 SET_ALLOW(harmony_do_expressions); 4680 SET_ALLOW(harmony_do_expressions);
4702 SET_ALLOW(harmony_function_name); 4681 SET_ALLOW(harmony_function_name);
4703 SET_ALLOW(harmony_function_sent); 4682 SET_ALLOW(harmony_function_sent);
4704 #undef SET_ALLOW 4683 #undef SET_ALLOW
4705 } 4684 }
4706 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4685 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4707 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4686 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4708 logger, bookmark); 4687 logger, bookmark);
4709 if (pre_parse_timer_ != NULL) { 4688 if (pre_parse_timer_ != NULL) {
4710 pre_parse_timer_->Stop(); 4689 pre_parse_timer_->Stop();
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
5457 for (int i = begin; i < end; i++) { 5436 for (int i = begin; i < end; i++) {
5458 DCHECK(non_patterns_to_rewrite->at(i)->IsRewritableExpression()); 5437 DCHECK(non_patterns_to_rewrite->at(i)->IsRewritableExpression());
5459 rewriter.Rewrite(non_patterns_to_rewrite->at(i)); 5438 rewriter.Rewrite(non_patterns_to_rewrite->at(i));
5460 } 5439 }
5461 non_patterns_to_rewrite->Rewind(begin); 5440 non_patterns_to_rewrite->Rewind(begin);
5462 } 5441 }
5463 } 5442 }
5464 5443
5465 5444
5466 void Parser::RewriteDestructuringAssignments() { 5445 void Parser::RewriteDestructuringAssignments() {
5467 if (!allow_harmony_destructuring_assignment()) return;
5468 const auto& assignments = 5446 const auto& assignments =
5469 function_state_->destructuring_assignments_to_rewrite(); 5447 function_state_->destructuring_assignments_to_rewrite();
5470 for (int i = assignments.length() - 1; i >= 0; --i) { 5448 for (int i = assignments.length() - 1; i >= 0; --i) {
5471 // Rewrite list in reverse, so that nested assignment patterns are rewritten 5449 // Rewrite list in reverse, so that nested assignment patterns are rewritten
5472 // correctly. 5450 // correctly.
5473 const DestructuringAssignment& pair = assignments.at(i); 5451 const DestructuringAssignment& pair = assignments.at(i);
5474 RewritableExpression* to_rewrite = 5452 RewritableExpression* to_rewrite =
5475 pair.assignment->AsRewritableExpression(); 5453 pair.assignment->AsRewritableExpression();
5476 DCHECK_NOT_NULL(to_rewrite); 5454 DCHECK_NOT_NULL(to_rewrite);
5477 if (!to_rewrite->is_rewritten()) { 5455 if (!to_rewrite->is_rewritten()) {
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
6805 try_block, target); 6783 try_block, target);
6806 final_loop = target; 6784 final_loop = target;
6807 } 6785 }
6808 6786
6809 return final_loop; 6787 return final_loop;
6810 } 6788 }
6811 6789
6812 6790
6813 } // namespace internal 6791 } // namespace internal
6814 } // namespace v8 6792 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698