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

Unified Diff: src/parser.cc

Issue 883823002: Implement proper scoping for "this" in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased against master, plus fixes. Only 4 tests failing (+2 in TurboFan) 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/ast-graph-builder.cc ('k') | src/scopeinfo.cc » ('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 b1d427e2529f4ec23a4ac702094ba4f874657443..e20e508da8d18a15c953e13f4b8f71fc549cc010 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -673,7 +673,9 @@ const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory,
int pos) {
- return factory->NewVariableProxy(scope->receiver(), pos);
+ return scope->NewUnresolved(factory,
+ parser_->ast_value_factory()->this_string(),
+ Variable::THIS, pos);
}
Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory,
@@ -721,8 +723,8 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
// for Traits::DeclareArrowParametersFromExpression() to be able to
// pick the names of the parameters.
return parser_->parsing_lazy_arrow_parameters_
- ? factory->NewVariableProxy(name, false, pos)
- : scope->NewUnresolved(factory, name, pos);
+ ? factory->NewVariableProxy(name, Variable::NORMAL, pos)
+ : scope->NewUnresolved(factory, name, Variable::NORMAL, pos);
}
@@ -1792,7 +1794,8 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name,
// scope.
// Let/const variables in harmony mode are always added to the immediately
// enclosing scope.
- return DeclarationScope(mode)->NewUnresolved(factory(), name, position());
+ return DeclarationScope(mode)
+ ->NewUnresolved(factory(), name, Variable::NORMAL, position());
}
@@ -1877,7 +1880,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
// For global const variables we bind the proxy to a variable.
DCHECK(resolve); // should be set by all callers
Variable::Kind kind = Variable::NORMAL;
- var = new (zone()) Variable(declaration_scope, name, mode, true, kind,
+ var = new (zone()) Variable(declaration_scope, name, mode, kind,
kNeedsInitialization, kNotAssigned);
} else if (declaration_scope->is_eval_scope() &&
is_sloppy(declaration_scope->language_mode())) {
@@ -1886,7 +1889,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
// DeclareLookupSlot runtime function.
Variable::Kind kind = Variable::NORMAL;
// TODO(sigurds) figure out if kNotAssigned is OK here
- var = new (zone()) Variable(declaration_scope, name, mode, true, kind,
+ var = new (zone()) Variable(declaration_scope, name, mode, kind,
declaration->initialization(), kNotAssigned);
var->AllocateTo(Variable::LOOKUP, -1);
resolve = true;
@@ -2408,8 +2411,8 @@ Block* Parser::ParseVariableDeclarations(
// 'var' initializations are simply assignments (with all the consequences
// if they are inside a 'with' statement - they may change a 'with' object
// property).
- VariableProxy* proxy =
- initialization_scope->NewUnresolved(factory(), name);
+ VariableProxy* proxy = initialization_scope->NewUnresolved(
+ factory(), name, Variable::NORMAL);
Assignment* assignment =
factory()->NewAssignment(init_op, proxy, value, pos);
block->AddStatement(
@@ -3271,7 +3274,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Expression* enumerable = ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
- VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos);
+ VariableProxy* each =
+ scope_->NewUnresolved(factory(), name, Variable::NORMAL, each_pos);
Statement* body = ParseSubStatement(NULL, CHECK_OK);
InitializeForEachStatement(loop, each, enumerable, body);
Block* result =
@@ -3331,7 +3335,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
scope_ = for_scope;
Expect(Token::RPAREN, CHECK_OK);
- VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos);
+ VariableProxy* each =
+ scope_->NewUnresolved(factory(), name, Variable::NORMAL, each_pos);
Statement* body = ParseSubStatement(NULL, CHECK_OK);
Block* body_block =
factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition);
@@ -3772,8 +3777,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
: CONST_LEGACY;
DCHECK(function_name != NULL);
fvar = new (zone())
- Variable(scope_, function_name, fvar_mode, true /* is valid LHS */,
- Variable::NORMAL, kCreatedInitialized, kNotAssigned);
+ Variable(scope_, function_name, fvar_mode, Variable::NORMAL,
+ kCreatedInitialized, kNotAssigned);
VariableProxy* proxy = factory()->NewVariableProxy(fvar);
VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
proxy, fvar_mode, scope_, RelocInfo::kNoPosition);
@@ -3964,7 +3969,8 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone());
if (fvar != NULL) {
- VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name);
+ VariableProxy* fproxy =
+ scope_->NewUnresolved(factory(), function_name, Variable::NORMAL);
fproxy->BindTo(fvar);
body->Add(factory()->NewExpressionStatement(
factory()->NewAssignment(fvar_init_op,
« no previous file with comments | « src/compiler/ast-graph-builder.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698