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

Side by Side Diff: src/parser.cc

Issue 880253004: Do not create unresolved variables when parsing arrow functions lazily (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/parser.h ('k') | test/mjsunit/regress/regress-3501.js » ('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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, 716 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
717 int pos, Scope* scope, 717 int pos, Scope* scope,
718 AstNodeFactory* factory) { 718 AstNodeFactory* factory) {
719 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); 719 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name);
720 // The name may refer to a module instance object, so its type is unknown. 720 // The name may refer to a module instance object, so its type is unknown.
721 #ifdef DEBUG 721 #ifdef DEBUG
722 if (FLAG_print_interface_details) 722 if (FLAG_print_interface_details)
723 PrintF("# Variable %.*s ", name->length(), name->raw_data()); 723 PrintF("# Variable %.*s ", name->length(), name->raw_data());
724 #endif 724 #endif
725 Interface* interface = Interface::NewUnknown(parser_->zone()); 725 Interface* interface = Interface::NewUnknown(parser_->zone());
726 return scope->NewUnresolved(factory, name, interface, pos); 726
727 // Arrow function parameters are parsed as an expression. When
728 // parsing lazily, it is enough to create a VariableProxy in order
729 // for Traits::DeclareArrowParametersFromExpression() to be able to
730 // pick the names of the parameters.
731 return parser_->parsing_lazy_arrow_parameters_
732 ? factory->NewVariableProxy(name, false, interface, pos)
733 : scope->NewUnresolved(factory, name, interface, pos);
727 } 734 }
728 735
729 736
730 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, 737 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner,
731 AstNodeFactory* factory) { 738 AstNodeFactory* factory) {
732 const AstRawString* symbol = GetSymbol(scanner); 739 const AstRawString* symbol = GetSymbol(scanner);
733 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); 740 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
734 return factory->NewStringLiteral(symbol, pos); 741 return factory->NewStringLiteral(symbol, pos);
735 } 742 }
736 743
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) 788 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
782 : ParserBase<ParserTraits>(info->isolate(), info->zone(), &scanner_, 789 : ParserBase<ParserTraits>(info->isolate(), info->zone(), &scanner_,
783 parse_info->stack_limit, info->extension(), NULL, 790 parse_info->stack_limit, info->extension(), NULL,
784 this), 791 this),
785 scanner_(parse_info->unicode_cache), 792 scanner_(parse_info->unicode_cache),
786 reusable_preparser_(NULL), 793 reusable_preparser_(NULL),
787 original_scope_(NULL), 794 original_scope_(NULL),
788 target_stack_(NULL), 795 target_stack_(NULL),
789 cached_parse_data_(NULL), 796 cached_parse_data_(NULL),
790 info_(info), 797 info_(info),
798 parsing_lazy_arrow_parameters_(false),
791 has_pending_error_(false), 799 has_pending_error_(false),
792 pending_error_message_(NULL), 800 pending_error_message_(NULL),
793 pending_error_arg_(NULL), 801 pending_error_arg_(NULL),
794 pending_error_char_arg_(NULL), 802 pending_error_char_arg_(NULL),
795 total_preparse_skipped_(0), 803 total_preparse_skipped_(0),
796 pre_parse_timer_(NULL) { 804 pre_parse_timer_(NULL) {
797 DCHECK(!script().is_null() || info->source_stream() != NULL); 805 DCHECK(!script().is_null() || info->source_stream() != NULL);
798 set_allow_lazy(false); // Must be explicitly enabled. 806 set_allow_lazy(false); // Must be explicitly enabled.
799 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 807 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
800 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 808 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 DCHECK(info()->strict_mode() == shared_info->strict_mode()); 1062 DCHECK(info()->strict_mode() == shared_info->strict_mode());
1055 scope->SetStrictMode(shared_info->strict_mode()); 1063 scope->SetStrictMode(shared_info->strict_mode());
1056 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 1064 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
1057 ? (shared_info->is_anonymous() 1065 ? (shared_info->is_anonymous()
1058 ? FunctionLiteral::ANONYMOUS_EXPRESSION 1066 ? FunctionLiteral::ANONYMOUS_EXPRESSION
1059 : FunctionLiteral::NAMED_EXPRESSION) 1067 : FunctionLiteral::NAMED_EXPRESSION)
1060 : FunctionLiteral::DECLARATION; 1068 : FunctionLiteral::DECLARATION;
1061 bool ok = true; 1069 bool ok = true;
1062 1070
1063 if (shared_info->is_arrow()) { 1071 if (shared_info->is_arrow()) {
1072 // The first expression being parsed is the parameter list of the arrow
1073 // function. Setting this avoids prevents ExpressionFromIdentifier()
1074 // from creating unresolved variables in already-resolved scopes.
1075 parsing_lazy_arrow_parameters_ = true;
1064 Expression* expression = ParseExpression(false, &ok); 1076 Expression* expression = ParseExpression(false, &ok);
1065 DCHECK(expression->IsFunctionLiteral()); 1077 DCHECK(expression->IsFunctionLiteral());
1066 result = expression->AsFunctionLiteral(); 1078 result = expression->AsFunctionLiteral();
marja 2015/01/29 09:53:01 Why are setting parsing_lazy_arrow_parameters_ to
aperez 2015/01/29 14:38:03 That does not work. ParseExpression() here parses
1067 } else if (shared_info->is_default_constructor()) { 1079 } else if (shared_info->is_default_constructor()) {
1068 result = DefaultConstructor(shared_info->uses_super_constructor_call(), 1080 result = DefaultConstructor(shared_info->uses_super_constructor_call(),
1069 scope, shared_info->start_position(), 1081 scope, shared_info->start_position(),
1070 shared_info->end_position()); 1082 shared_info->end_position());
1071 } else { 1083 } else {
1072 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), 1084 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(),
1073 false, // Strict mode name already checked. 1085 false, // Strict mode name already checked.
1074 shared_info->kind(), RelocInfo::kNoPosition, 1086 shared_info->kind(), RelocInfo::kNoPosition,
1075 function_type, 1087 function_type,
1076 FunctionLiteral::NORMAL_ARITY, &ok); 1088 FunctionLiteral::NORMAL_ARITY, &ok);
(...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after
3334 3346
3335 // Any other kind of expression is not a valid parameter list. 3347 // Any other kind of expression is not a valid parameter list.
3336 return false; 3348 return false;
3337 } 3349 }
3338 3350
3339 3351
3340 int ParserTraits::DeclareArrowParametersFromExpression( 3352 int ParserTraits::DeclareArrowParametersFromExpression(
3341 Expression* expression, Scope* scope, Scanner::Location* dupe_loc, 3353 Expression* expression, Scope* scope, Scanner::Location* dupe_loc,
3342 bool* ok) { 3354 bool* ok) {
3343 int num_params = 0; 3355 int num_params = 0;
3356 // Always reset the flag: It only needs to be set for the first expression
3357 // parsed as arrow function parameter list, becauseonly top-level functions
3358 // are parsed lazily.
3359 parser_->parsing_lazy_arrow_parameters_ = false;
3344 *ok = CheckAndDeclareArrowParameter(this, expression, scope, &num_params, 3360 *ok = CheckAndDeclareArrowParameter(this, expression, scope, &num_params,
3345 dupe_loc); 3361 dupe_loc);
3346 return num_params; 3362 return num_params;
3347 } 3363 }
3348 3364
3349 3365
3350 FunctionLiteral* Parser::ParseFunctionLiteral( 3366 FunctionLiteral* Parser::ParseFunctionLiteral(
3351 const AstRawString* function_name, Scanner::Location function_name_location, 3367 const AstRawString* function_name, Scanner::Location function_name_location,
3352 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, 3368 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
3353 FunctionLiteral::FunctionType function_type, 3369 FunctionLiteral::FunctionType function_type,
(...skipping 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after
5143 } else { 5159 } else {
5144 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5160 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5145 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5161 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5146 raw_string->length()); 5162 raw_string->length());
5147 } 5163 }
5148 } 5164 }
5149 5165
5150 return running_hash; 5166 return running_hash;
5151 } 5167 }
5152 } } // namespace v8::internal 5168 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | test/mjsunit/regress/regress-3501.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698