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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | test/mjsunit/regress/regress-3501.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index dff7de9e6b25c9c9370c866ab5bd4f52646852a6..0c0fe36f1b9635a772a0251ade4a29dfdf0afbd8 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -723,7 +723,14 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
PrintF("# Variable %.*s ", name->length(), name->raw_data());
#endif
Interface* interface = Interface::NewUnknown(parser_->zone());
- return scope->NewUnresolved(factory, name, interface, pos);
+
+ // Arrow function parameters are parsed as an expression. When
+ // parsing lazily, it is enough to create a VariableProxy in order
+ // for Traits::DeclareArrowParametersFromExpression() to be able to
+ // pick the names of the parameters.
+ return parser_->parsing_lazy_arrow_parameters_
+ ? factory->NewVariableProxy(name, false, interface, pos)
+ : scope->NewUnresolved(factory, name, interface, pos);
}
@@ -788,6 +795,7 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
target_stack_(NULL),
cached_parse_data_(NULL),
info_(info),
+ parsing_lazy_arrow_parameters_(false),
has_pending_error_(false),
pending_error_message_(NULL),
pending_error_arg_(NULL),
@@ -1061,6 +1069,10 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
bool ok = true;
if (shared_info->is_arrow()) {
+ // The first expression being parsed is the parameter list of the arrow
+ // function. Setting this avoids prevents ExpressionFromIdentifier()
+ // from creating unresolved variables in already-resolved scopes.
+ parsing_lazy_arrow_parameters_ = true;
Expression* expression = ParseExpression(false, &ok);
DCHECK(expression->IsFunctionLiteral());
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
@@ -3341,6 +3353,10 @@ int ParserTraits::DeclareArrowParametersFromExpression(
Expression* expression, Scope* scope, Scanner::Location* dupe_loc,
bool* ok) {
int num_params = 0;
+ // Always reset the flag: It only needs to be set for the first expression
+ // parsed as arrow function parameter list, becauseonly top-level functions
+ // are parsed lazily.
+ parser_->parsing_lazy_arrow_parameters_ = false;
*ok = CheckAndDeclareArrowParameter(this, expression, scope, &num_params,
dupe_loc);
return num_params;
« 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