Commit 4f552f5a authored by verwaest's avatar verwaest Committed by Commit bot

Introduce parent ScopeState class and track the scope through the state in the parser

This will allow us to move more state from Scope into ScopeState and lazily allocate full Scopes only when needed.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2160593002
Cr-Commit-Position: refs/heads/master@{#37858}
parent 7c3ddd2c
...@@ -201,10 +201,10 @@ class ParserBase : public Traits { ...@@ -201,10 +201,10 @@ class ParserBase : public Traits {
v8::Extension* extension, AstValueFactory* ast_value_factory, v8::Extension* extension, AstValueFactory* ast_value_factory,
ParserRecorder* log, typename Traits::Type::Parser this_object) ParserRecorder* log, typename Traits::Type::Parser this_object)
: Traits(this_object), : Traits(this_object),
scope_(NULL), scope_state_(nullptr),
function_state_(NULL), function_state_(nullptr),
extension_(extension), extension_(extension),
fni_(NULL), fni_(nullptr),
ast_value_factory_(ast_value_factory), ast_value_factory_(ast_value_factory),
log_(log), log_(log),
mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
...@@ -272,21 +272,34 @@ class ParserBase : public Traits { ...@@ -272,21 +272,34 @@ class ParserBase : public Traits {
class ObjectLiteralCheckerBase; class ObjectLiteralCheckerBase;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// FunctionState and BlockState together implement the parser's scope stack. // ScopeState and its subclasses implement the parser's scope stack.
// The parser's current scope is in scope_. BlockState and FunctionState // ScopeState keeps track of the current scope, and the outer ScopeState. The
// constructors push on the scope stack and the destructors pop. They are also // parser's scope_state_ points to the top ScopeState. ScopeState's
// used to hold the parser's per-function and per-block state. // constructor push on the scope stack and the destructors pop. BlockState and
class BlockState BASE_EMBEDDED { // FunctionState are used to hold additional per-block and per-function state.
class ScopeState BASE_EMBEDDED {
public: public:
BlockState(Scope** scope_stack, Scope* scope) V8_INLINE Scope* scope() const { return scope_; }
: scope_stack_(scope_stack), outer_scope_(*scope_stack) {
*scope_stack_ = scope; protected:
ScopeState(ScopeState** scope_stack, Scope* scope)
: scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) {
*scope_stack = this;
} }
~BlockState() { *scope_stack_ = outer_scope_; } ~ScopeState() { *scope_stack_ = outer_scope_; }
Zone* zone() const { return scope_->zone(); }
private: private:
Scope** scope_stack_; ScopeState** scope_stack_;
Scope* outer_scope_; ScopeState* outer_scope_;
Scope* scope_;
};
class BlockState final : public ScopeState {
public:
BlockState(ScopeState** scope_stack, Scope* scope)
: ScopeState(scope_stack, scope) {}
}; };
struct DestructuringAssignment { struct DestructuringAssignment {
...@@ -356,10 +369,10 @@ class ParserBase : public Traits { ...@@ -356,10 +369,10 @@ class ParserBase : public Traits {
kInsideForInOfBody, kInsideForInOfBody,
}; };
class FunctionState BASE_EMBEDDED { class FunctionState final : public ScopeState {
public: public:
FunctionState(FunctionState** function_state_stack, Scope** scope_stack, FunctionState(FunctionState** function_state_stack,
Scope* scope, FunctionKind kind, ScopeState** scope_stack, Scope* scope, FunctionKind kind,
typename Traits::Type::Factory* factory); typename Traits::Type::Factory* factory);
~FunctionState(); ~FunctionState();
...@@ -458,13 +471,11 @@ class ParserBase : public Traits { ...@@ -458,13 +471,11 @@ class ParserBase : public Traits {
private: private:
void AddDestructuringAssignment(DestructuringAssignment pair) { void AddDestructuringAssignment(DestructuringAssignment pair) {
destructuring_assignments_to_rewrite_.Add(pair, (*scope_stack_)->zone()); destructuring_assignments_to_rewrite_.Add(pair, this->zone());
} }
V8_INLINE Scope* scope() { return *scope_stack_; }
void AddNonPatternForRewriting(ExpressionT expr, bool* ok) { void AddNonPatternForRewriting(ExpressionT expr, bool* ok) {
non_patterns_to_rewrite_.Add(expr, (*scope_stack_)->zone()); non_patterns_to_rewrite_.Add(expr, this->zone());
if (non_patterns_to_rewrite_.length() >= if (non_patterns_to_rewrite_.length() >=
std::numeric_limits<uint16_t>::max()) std::numeric_limits<uint16_t>::max())
*ok = false; *ok = false;
...@@ -495,8 +506,6 @@ class ParserBase : public Traits { ...@@ -495,8 +506,6 @@ class ParserBase : public Traits {
FunctionState** function_state_stack_; FunctionState** function_state_stack_;
FunctionState* outer_function_state_; FunctionState* outer_function_state_;
Scope** scope_stack_;
Scope* outer_scope_;
ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_;
TailCallExpressionList tail_call_expressions_; TailCallExpressionList tail_call_expressions_;
...@@ -815,7 +824,7 @@ class ParserBase : public Traits { ...@@ -815,7 +824,7 @@ class ParserBase : public Traits {
return function_state_->factory(); return function_state_->factory();
} }
LanguageMode language_mode() { return scope_->language_mode(); } LanguageMode language_mode() { return scope()->language_mode(); }
bool is_generator() const { return function_state_->is_generator(); } bool is_generator() const { return function_state_->is_generator(); }
bool is_async_function() const { bool is_async_function() const {
return function_state_->is_async_function(); return function_state_->is_async_function();
...@@ -1191,7 +1200,10 @@ class ParserBase : public Traits { ...@@ -1191,7 +1200,10 @@ class ParserBase : public Traits {
bool has_seen_constructor_; bool has_seen_constructor_;
}; };
Scope* scope_; // Scope stack. ModuleDescriptor* module() const { return scope()->module(); }
Scope* scope() const { return scope_state_->scope(); }
ScopeState* scope_state_; // Scope stack.
FunctionState* function_state_; // Function state stack. FunctionState* function_state_; // Function state stack.
v8::Extension* extension_; v8::Extension* extension_;
FuncNameInferrer* fni_; FuncNameInferrer* fni_;
...@@ -1221,9 +1233,10 @@ class ParserBase : public Traits { ...@@ -1221,9 +1233,10 @@ class ParserBase : public Traits {
template <class Traits> template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState( ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, FunctionState** function_state_stack, ScopeState** scope_stack,
FunctionKind kind, typename Traits::Type::Factory* factory) Scope* scope, FunctionKind kind, typename Traits::Type::Factory* factory)
: next_materialized_literal_index_(0), : ScopeState(scope_stack, scope),
next_materialized_literal_index_(0),
expected_property_count_(0), expected_property_count_(0),
this_location_(Scanner::Location::invalid()), this_location_(Scanner::Location::invalid()),
return_location_(Scanner::Location::invalid()), return_location_(Scanner::Location::invalid()),
...@@ -1232,8 +1245,6 @@ ParserBase<Traits>::FunctionState::FunctionState( ...@@ -1232,8 +1245,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
generator_object_variable_(NULL), generator_object_variable_(NULL),
function_state_stack_(function_state_stack), function_state_stack_(function_state_stack),
outer_function_state_(*function_state_stack), outer_function_state_(*function_state_stack),
scope_stack_(scope_stack),
outer_scope_(*scope_stack),
destructuring_assignments_to_rewrite_(16, scope->zone()), destructuring_assignments_to_rewrite_(16, scope->zone()),
tail_call_expressions_(scope->zone()), tail_call_expressions_(scope->zone()),
return_expr_context_(ReturnExprContext::kInsideValidBlock), return_expr_context_(ReturnExprContext::kInsideValidBlock),
...@@ -1242,7 +1253,6 @@ ParserBase<Traits>::FunctionState::FunctionState( ...@@ -1242,7 +1253,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
factory_(factory), factory_(factory),
next_function_is_parenthesized_(false), next_function_is_parenthesized_(false),
this_function_is_parenthesized_(false) { this_function_is_parenthesized_(false) {
*scope_stack_ = scope;
*function_state_stack = this; *function_state_stack = this;
if (outer_function_state_) { if (outer_function_state_) {
this_function_is_parenthesized_ = this_function_is_parenthesized_ =
...@@ -1254,7 +1264,6 @@ ParserBase<Traits>::FunctionState::FunctionState( ...@@ -1254,7 +1264,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
template <class Traits> template <class Traits>
ParserBase<Traits>::FunctionState::~FunctionState() { ParserBase<Traits>::FunctionState::~FunctionState() {
*scope_stack_ = outer_scope_;
*function_state_stack_ = outer_function_state_; *function_state_stack_ = outer_function_state_;
} }
...@@ -1370,7 +1379,7 @@ ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, ...@@ -1370,7 +1379,7 @@ ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
} }
} }
if (this->IsArguments(name)) { if (this->IsArguments(name)) {
scope_->RecordArgumentsUsage(); scope()->RecordArgumentsUsage();
classifier->RecordStrictModeFormalParameterError( classifier->RecordStrictModeFormalParameterError(
scanner()->location(), MessageTemplate::kStrictEvalArguments); scanner()->location(), MessageTemplate::kStrictEvalArguments);
if (is_strict(language_mode())) { if (is_strict(language_mode())) {
...@@ -1438,7 +1447,7 @@ ParserBase<Traits>::ParseIdentifierOrStrictReservedWord( ...@@ -1438,7 +1447,7 @@ ParserBase<Traits>::ParseIdentifierOrStrictReservedWord(
} }
IdentifierT name = this->GetSymbol(scanner()); IdentifierT name = this->GetSymbol(scanner());
if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); if (this->IsArguments(name)) scope()->RecordArgumentsUsage();
return name; return name;
} }
...@@ -1458,7 +1467,7 @@ ParserBase<Traits>::ParseIdentifierName(bool* ok) { ...@@ -1458,7 +1467,7 @@ ParserBase<Traits>::ParseIdentifierName(bool* ok) {
} }
IdentifierT name = this->GetSymbol(scanner()); IdentifierT name = this->GetSymbol(scanner());
if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); if (this->IsArguments(name)) scope()->RecordArgumentsUsage();
return name; return name;
} }
...@@ -1516,7 +1525,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, ...@@ -1516,7 +1525,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
case Token::THIS: { case Token::THIS: {
BindingPatternUnexpectedToken(classifier); BindingPatternUnexpectedToken(classifier);
Consume(Token::THIS); Consume(Token::THIS);
return this->ThisExpression(scope_, factory(), beg_pos); return this->ThisExpression(scope(), factory(), beg_pos);
} }
case Token::NULL_LITERAL: case Token::NULL_LITERAL:
...@@ -1549,7 +1558,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, ...@@ -1549,7 +1558,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
// Using eval or arguments in this context is OK even in strict mode. // Using eval or arguments in this context is OK even in strict mode.
IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK);
return this->ExpressionFromIdentifier( return this->ExpressionFromIdentifier(
name, beg_pos, scanner()->location().end_pos, scope_, factory()); name, beg_pos, scanner()->location().end_pos, scope(), factory());
} }
case Token::STRING: { case Token::STRING: {
...@@ -1975,7 +1984,7 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -1975,7 +1984,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
} }
} }
ExpressionT lhs = this->ExpressionFromIdentifier( ExpressionT lhs = this->ExpressionFromIdentifier(
*name, next_beg_pos, next_end_pos, scope_, factory()); *name, next_beg_pos, next_end_pos, scope(), factory());
CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
if (peek() == Token::ASSIGN) { if (peek() == Token::ASSIGN) {
...@@ -2282,7 +2291,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, ...@@ -2282,7 +2291,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
IdentifierT name = IdentifierT name =
ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
expression = this->ExpressionFromIdentifier( expression = this->ExpressionFromIdentifier(
name, position(), scanner()->location().end_pos, scope_, factory()); name, position(), scanner()->location().end_pos, scope(), factory());
} }
if (peek() == Token::ARROW) { if (peek() == Token::ARROW) {
...@@ -2298,13 +2307,13 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, ...@@ -2298,13 +2307,13 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
Scope* scope = this->NewScope(scope_, FUNCTION_SCOPE, Scope* scope = this->NewScope(this->scope(), FUNCTION_SCOPE,
is_async ? FunctionKind::kAsyncArrowFunction is_async ? FunctionKind::kAsyncArrowFunction
: FunctionKind::kArrowFunction); : FunctionKind::kArrowFunction);
// Because the arrow's parameters were parsed in the outer scope, any // Because the arrow's parameters were parsed in the outer scope, any
// usage flags that might have been triggered there need to be copied // usage flags that might have been triggered there need to be copied
// to the arrow scope. // to the arrow scope.
scope_->PropagateUsageFlagsToScope(scope); this->scope()->PropagateUsageFlagsToScope(scope);
FormalParametersT parameters(scope); FormalParametersT parameters(scope);
if (!arrow_formals_classifier.is_simple_parameter_list()) { if (!arrow_formals_classifier.is_simple_parameter_list()) {
scope->SetHasNonSimpleParameters(); scope->SetHasNonSimpleParameters();
...@@ -2726,7 +2735,7 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier, ...@@ -2726,7 +2735,7 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
MessageTemplate::kAwaitBindingIdentifier); MessageTemplate::kAwaitBindingIdentifier);
return this->ExpressionFromIdentifier( return this->ExpressionFromIdentifier(
name, beg_pos, scanner()->location().end_pos, scope_, factory()); name, beg_pos, scanner()->location().end_pos, scope(), factory());
} }
default: default:
break; break;
...@@ -2871,7 +2880,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression( ...@@ -2871,7 +2880,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
// no explicit receiver. // no explicit receiver.
// These calls are marked as potentially direct eval calls. Whether // These calls are marked as potentially direct eval calls. Whether
// they are actually direct calls to eval is determined at run time. // they are actually direct calls to eval is determined at run time.
this->CheckPossibleEvalCall(result, scope_); this->CheckPossibleEvalCall(result, scope());
bool is_super_call = result->IsSuperCallReference(); bool is_super_call = result->IsSuperCallReference();
if (spread_pos.IsValid()) { if (spread_pos.IsValid()) {
...@@ -2884,7 +2893,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression( ...@@ -2884,7 +2893,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
// Explicit calls to the super constructor using super() perform an // Explicit calls to the super constructor using super() perform an
// implicit binding assignment to the 'this' variable. // implicit binding assignment to the 'this' variable.
if (is_super_call) { if (is_super_call) {
ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); ExpressionT this_expr = this->ThisExpression(scope(), factory(), pos);
result = result =
factory()->NewAssignment(Token::INIT, this_expr, result, pos); factory()->NewAssignment(Token::INIT, this_expr, result, pos);
} }
...@@ -3022,7 +3031,7 @@ ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, ...@@ -3022,7 +3031,7 @@ ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier,
return this->EmptyExpression(); return this->EmptyExpression();
} }
return this->FunctionSentExpression(scope_, factory(), pos); return this->FunctionSentExpression(scope(), factory(), pos);
} }
bool is_generator = Check(Token::MUL); bool is_generator = Check(Token::MUL);
...@@ -3065,13 +3074,13 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, ...@@ -3065,13 +3074,13 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
Expect(Token::SUPER, CHECK_OK); Expect(Token::SUPER, CHECK_OK);
int pos = position(); int pos = position();
Scope* scope = scope_->ReceiverScope(); Scope* scope = this->scope()->ReceiverScope();
FunctionKind kind = scope->function_kind(); FunctionKind kind = scope->function_kind();
if (IsConciseMethod(kind) || IsAccessorFunction(kind) || if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
IsClassConstructor(kind)) { IsClassConstructor(kind)) {
if (peek() == Token::PERIOD || peek() == Token::LBRACK) { if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
scope->RecordSuperPropertyUsage(); scope->RecordSuperPropertyUsage();
return this->NewSuperPropertyReference(scope_, factory(), pos); return this->NewSuperPropertyReference(this->scope(), factory(), pos);
} }
// new super() is never allowed. // new super() is never allowed.
// super() is only allowed in derived constructor // super() is only allowed in derived constructor
...@@ -3079,7 +3088,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, ...@@ -3079,7 +3088,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
// TODO(rossberg): This might not be the correct FunctionState for the // TODO(rossberg): This might not be the correct FunctionState for the
// method here. // method here.
function_state_->set_super_location(scanner()->location()); function_state_->set_super_location(scanner()->location());
return this->NewSuperCallReference(scope_, factory(), pos); return this->NewSuperCallReference(this->scope(), factory(), pos);
} }
} }
...@@ -3108,14 +3117,14 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { ...@@ -3108,14 +3117,14 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
int pos = position(); int pos = position();
ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
if (!scope_->ReceiverScope()->is_function_scope()) { if (!scope()->ReceiverScope()->is_function_scope()) {
ReportMessageAt(scanner()->location(), ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedNewTarget); MessageTemplate::kUnexpectedNewTarget);
*ok = false; *ok = false;
return this->EmptyExpression(); return this->EmptyExpression();
} }
return this->NewTargetExpression(scope_, factory(), pos); return this->NewTargetExpression(scope(), factory(), pos);
} }
template <class Traits> template <class Traits>
...@@ -3357,7 +3366,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral( ...@@ -3357,7 +3366,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
{ {
typename Traits::Type::Factory function_factory(ast_value_factory()); typename Traits::Type::Factory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, FunctionState function_state(&function_state_, &scope_state_,
formal_parameters.scope, arrow_kind, formal_parameters.scope, arrow_kind,
&function_factory); &function_factory);
...@@ -3372,7 +3381,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral( ...@@ -3372,7 +3381,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
// Multiple statement body // Multiple statement body
Consume(Token::LBRACE); Consume(Token::LBRACE);
bool is_lazily_parsed = bool is_lazily_parsed =
(mode() == PARSE_LAZILY && scope_->AllowsLazyParsing()); (mode() == PARSE_LAZILY && scope()->AllowsLazyParsing());
if (is_lazily_parsed) { if (is_lazily_parsed) {
body = this->NewStatementList(0, zone()); body = this->NewStatementList(0, zone());
this->SkipLazyFunctionBody(&materialized_literal_count, this->SkipLazyFunctionBody(&materialized_literal_count,
......
...@@ -199,8 +199,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, ...@@ -199,8 +199,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
{ {
AstNodeFactory function_factory(ast_value_factory()); AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, function_scope, FunctionState function_state(&function_state_, &scope_state_,
kind, &function_factory); function_scope, kind, &function_factory);
body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
if (call_super) { if (call_super) {
...@@ -217,7 +217,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, ...@@ -217,7 +217,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
ZoneList<Expression*>* args = ZoneList<Expression*>* args =
new (zone()) ZoneList<Expression*>(2, zone()); new (zone()) ZoneList<Expression*>(2, zone());
VariableProxy* this_function_proxy = scope_->NewUnresolved( VariableProxy* this_function_proxy = this->scope()->NewUnresolved(
factory(), ast_value_factory()->this_function_string(), factory(), ast_value_factory()->this_function_string(),
Variable::NORMAL, pos); Variable::NORMAL, pos);
ZoneList<Expression*>* tmp = ZoneList<Expression*>* tmp =
...@@ -232,7 +232,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, ...@@ -232,7 +232,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
new (zone()) ZoneList<Expression*>(1, zone()); new (zone()) ZoneList<Expression*>(1, zone());
spread_args_expr->Add(spread_args, zone()); spread_args_expr->Add(spread_args, zone());
args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone()); args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone());
VariableProxy* new_target_proxy = scope_->NewUnresolved( VariableProxy* new_target_proxy = this->scope()->NewUnresolved(
factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, factory(), ast_value_factory()->new_target_string(), Variable::NORMAL,
pos); pos);
args->Add(new_target_proxy, zone()); args->Add(new_target_proxy, zone());
...@@ -909,8 +909,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -909,8 +909,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Note that this function can be called from the main thread or from a // Note that this function can be called from the main thread or from a
// background thread. We should not access anything Isolate / heap dependent // background thread. We should not access anything Isolate / heap dependent
// via ParseInfo, and also not pass it forward. // via ParseInfo, and also not pass it forward.
DCHECK(scope_ == NULL); DCHECK_NULL(scope_state_);
DCHECK(target_stack_ == NULL); DCHECK_NULL(target_stack_);
Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY;
if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY;
...@@ -919,7 +919,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -919,7 +919,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
{ {
// TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
// context, which will have the "this" binding for script scopes. // context, which will have the "this" binding for script scopes.
Scope* scope = NewScope(scope_, SCRIPT_SCOPE); Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
info->set_script_scope(scope); info->set_script_scope(scope);
if (!info->context().is_null() && !info->context()->IsNativeContext()) { if (!info->context().is_null() && !info->context()->IsNativeContext()) {
scope = Scope::DeserializeScopeChain(info->isolate(), zone(), scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
...@@ -946,7 +946,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -946,7 +946,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Enter 'scope' with the given parsing mode. // Enter 'scope' with the given parsing mode.
ParsingModeScope parsing_mode_scope(this, parsing_mode); ParsingModeScope parsing_mode_scope(this, parsing_mode);
AstNodeFactory function_factory(ast_value_factory()); AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope, FunctionState function_state(&function_state_, &scope_state_, scope,
kNormalFunction, &function_factory); kNormalFunction, &function_factory);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
...@@ -956,11 +956,11 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -956,11 +956,11 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
if (parsing_module_) { if (parsing_module_) {
ParseModuleItemList(body, &ok); ParseModuleItemList(body, &ok);
ok = ok && ok = ok &&
scope_->module()->Validate(scope_, &pending_error_handler_, zone()); module()->Validate(this->scope(), &pending_error_handler_, zone());
} else { } else {
// Don't count the mode in the use counters--give the program a chance // Don't count the mode in the use counters--give the program a chance
// to enable script-wide strict mode below. // to enable script-wide strict mode below.
scope_->SetLanguageMode(info->language_mode()); this->scope()->SetLanguageMode(info->language_mode());
ParseStatementList(body, Token::EOS, &ok); ParseStatementList(body, Token::EOS, &ok);
} }
...@@ -981,7 +981,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -981,7 +981,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
InsertSloppyBlockFunctionVarBindings(scope, nullptr, &ok); InsertSloppyBlockFunctionVarBindings(scope, nullptr, &ok);
} }
if (ok) { if (ok) {
CheckConflictingVarDeclarations(scope_, &ok); CheckConflictingVarDeclarations(this->scope(), &ok);
} }
if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
...@@ -997,7 +997,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -997,7 +997,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
if (ok) { if (ok) {
ParserTraits::RewriteDestructuringAssignments(); ParserTraits::RewriteDestructuringAssignments();
result = factory()->NewScriptOrEvalFunctionLiteral( result = factory()->NewScriptOrEvalFunctionLiteral(
scope_, body, function_state.materialized_literal_count(), this->scope(), body, function_state.materialized_literal_count(),
function_state.expected_property_count()); function_state.expected_property_count());
} }
} }
...@@ -1066,8 +1066,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, ...@@ -1066,8 +1066,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
Utf16CharacterStream* source) { Utf16CharacterStream* source) {
Handle<SharedFunctionInfo> shared_info = info->shared_info(); Handle<SharedFunctionInfo> shared_info = info->shared_info();
scanner_.Initialize(source); scanner_.Initialize(source);
DCHECK(scope_ == NULL); DCHECK_NULL(scope_state_);
DCHECK(target_stack_ == NULL); DCHECK_NULL(target_stack_);
Handle<String> name(String::cast(shared_info->name())); Handle<String> name(String::cast(shared_info->name()));
DCHECK(ast_value_factory()); DCHECK(ast_value_factory());
...@@ -1078,11 +1078,11 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, ...@@ -1078,11 +1078,11 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
ParsingModeScope parsing_mode(this, PARSE_EAGERLY); ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
// Place holder for the result. // Place holder for the result.
FunctionLiteral* result = NULL; FunctionLiteral* result = nullptr;
{ {
// Parse the function literal. // Parse the function literal.
Scope* scope = NewScope(scope_, SCRIPT_SCOPE); Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
info->set_script_scope(scope); info->set_script_scope(scope);
if (!info->context().is_null()) { if (!info->context().is_null()) {
// Ok to use Isolate here, since lazy function parsing is only done in the // Ok to use Isolate here, since lazy function parsing is only done in the
...@@ -1093,7 +1093,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, ...@@ -1093,7 +1093,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
} }
original_scope_ = scope; original_scope_ = scope;
AstNodeFactory function_factory(ast_value_factory()); AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope, FunctionState function_state(&function_state_, &scope_state_, scope,
shared_info->kind(), &function_factory); shared_info->kind(), &function_factory);
DCHECK(is_sloppy(scope->language_mode()) || DCHECK(is_sloppy(scope->language_mode()) ||
is_strict(info->language_mode())); is_strict(info->language_mode()));
...@@ -1118,7 +1118,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, ...@@ -1118,7 +1118,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
// TODO(adamk): We should construct this scope from the ScopeInfo. // TODO(adamk): We should construct this scope from the ScopeInfo.
Scope* scope = Scope* scope =
NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); NewScope(this->scope(), FUNCTION_SCOPE, FunctionKind::kArrowFunction);
// These two bits only need to be explicitly set because we're // These two bits only need to be explicitly set because we're
// not passing the ScopeInfo to the Scope constructor. // not passing the ScopeInfo to the Scope constructor.
...@@ -1137,7 +1137,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, ...@@ -1137,7 +1137,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
// Parsing patterns as variable reference expression creates // Parsing patterns as variable reference expression creates
// NewUnresolved references in current scope. Entrer arrow function // NewUnresolved references in current scope. Entrer arrow function
// scope for formal parameter parsing. // scope for formal parameter parsing.
BlockState block_state(&scope_, scope); BlockState block_state(&scope_state_, scope);
if (Check(Token::LPAREN)) { if (Check(Token::LPAREN)) {
// '(' StrictFormalParameters ')' // '(' StrictFormalParameters ')'
ParseFormalParameterList(&formals, &formals_classifier, &ok); ParseFormalParameterList(&formals, &formals_classifier, &ok);
...@@ -1187,13 +1187,13 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, ...@@ -1187,13 +1187,13 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
shared_info->language_mode(), &ok); shared_info->language_mode(), &ok);
} }
// Make sure the results agree. // Make sure the results agree.
DCHECK(ok == (result != NULL)); DCHECK(ok == (result != nullptr));
} }
// Make sure the target stack is empty. // Make sure the target stack is empty.
DCHECK(target_stack_ == NULL); DCHECK_NULL(target_stack_);
if (result != NULL) { if (result != nullptr) {
Handle<String> inferred_name(shared_info->inferred_name()); Handle<String> inferred_name(shared_info->inferred_name());
result->set_inferred_name(inferred_name); result->set_inferred_name(inferred_name);
} }
...@@ -1242,11 +1242,11 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, ...@@ -1242,11 +1242,11 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
token_loc.end_pos - token_loc.beg_pos == token_loc.end_pos - token_loc.beg_pos ==
ast_value_factory()->use_strict_string()->length() + 2; ast_value_factory()->use_strict_string()->length() + 2;
if (use_strict_found) { if (use_strict_found) {
if (is_sloppy(scope_->language_mode())) { if (is_sloppy(this->scope()->language_mode())) {
RaiseLanguageMode(STRICT); RaiseLanguageMode(STRICT);
} }
if (!scope_->HasSimpleParameters()) { if (!this->scope()->HasSimpleParameters()) {
// TC39 deemed "use strict" directives to be an error when occurring // TC39 deemed "use strict" directives to be an error when occurring
// in the body of a function with non-simple parameter list, on // in the body of a function with non-simple parameter list, on
// 29/7/2015. https://goo.gl/ueA7Ln // 29/7/2015. https://goo.gl/ueA7Ln
...@@ -1261,7 +1261,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, ...@@ -1261,7 +1261,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
// of the eval call, it is likely that functions declared in strict // of the eval call, it is likely that functions declared in strict
// eval code will be used within the eval code, so lazy parsing is // eval code will be used within the eval code, so lazy parsing is
// probably not a win. // probably not a win.
if (scope_->is_eval_scope()) mode_ = PARSE_EAGERLY; if (this->scope()->is_eval_scope()) mode_ = PARSE_EAGERLY;
} else if (literal->raw_value()->AsString() == } else if (literal->raw_value()->AsString() ==
ast_value_factory()->use_asm_string() && ast_value_factory()->use_asm_string() &&
token_loc.end_pos - token_loc.beg_pos == token_loc.end_pos - token_loc.beg_pos ==
...@@ -1269,7 +1269,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, ...@@ -1269,7 +1269,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
// Store the usage count; The actual use counter on the isolate is // Store the usage count; The actual use counter on the isolate is
// incremented after parsing is done. // incremented after parsing is done.
++use_counts_[v8::Isolate::kUseAsm]; ++use_counts_[v8::Isolate::kUseAsm];
scope_->SetAsmModule(); this->scope()->SetAsmModule();
} else { } else {
// Should not change mode, but will increment UseCounter // Should not change mode, but will increment UseCounter
// if appropriate. Ditto usages below. // if appropriate. Ditto usages below.
...@@ -1354,7 +1354,7 @@ void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) { ...@@ -1354,7 +1354,7 @@ void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
// ModuleBody : // ModuleBody :
// ModuleItem* // ModuleItem*
DCHECK(scope_->is_module_scope()); DCHECK(scope()->is_module_scope());
while (peek() != Token::EOS) { while (peek() != Token::EOS) {
Statement* stat = ParseModuleItem(CHECK_OK); Statement* stat = ParseModuleItem(CHECK_OK);
if (stat && !stat->IsEmpty()) { if (stat && !stat->IsEmpty()) {
...@@ -1499,8 +1499,7 @@ void* Parser::ParseImportDeclaration(bool* ok) { ...@@ -1499,8 +1499,7 @@ void* Parser::ParseImportDeclaration(bool* ok) {
if (tok == Token::STRING) { if (tok == Token::STRING) {
const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK);
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
scope_->module()->AddEmptyImport( module()->AddEmptyImport(module_specifier, scanner()->location(), zone());
module_specifier, scanner()->location(), zone());
return nullptr; return nullptr;
} }
...@@ -1548,9 +1547,8 @@ void* Parser::ParseImportDeclaration(bool* ok) { ...@@ -1548,9 +1547,8 @@ void* Parser::ParseImportDeclaration(bool* ok) {
// declarations. // declarations.
if (module_namespace_binding != nullptr) { if (module_namespace_binding != nullptr) {
scope_->module()->AddStarImport( module()->AddStarImport(module_namespace_binding, module_specifier,
module_namespace_binding, module_specifier, module_namespace_binding_loc, zone());
module_namespace_binding_loc, zone());
// TODO(neis): Create special immutable binding for the namespace object. // TODO(neis): Create special immutable binding for the namespace object.
} }
...@@ -1560,22 +1558,20 @@ void* Parser::ParseImportDeclaration(bool* ok) { ...@@ -1560,22 +1558,20 @@ void* Parser::ParseImportDeclaration(bool* ok) {
// location? // location?
if (import_default_binding != nullptr) { if (import_default_binding != nullptr) {
scope_->module()->AddImport( module()->AddImport(ast_value_factory()->default_string(),
ast_value_factory()->default_string(), import_default_binding, import_default_binding, module_specifier,
module_specifier, import_default_binding_loc, zone()); import_default_binding_loc, zone());
// DeclareImport(import_default_binding, pos, CHECK_OK); // DeclareImport(import_default_binding, pos, CHECK_OK);
} }
if (named_imports != nullptr) { if (named_imports != nullptr) {
if (named_imports->length() == 0) { if (named_imports->length() == 0) {
scope_->module()->AddEmptyImport( module()->AddEmptyImport(module_specifier, scanner()->location(), zone());
module_specifier, scanner()->location(), zone());
} else { } else {
for (int i = 0; i < named_imports->length(); ++i) { for (int i = 0; i < named_imports->length(); ++i) {
const NamedImport* import = named_imports->at(i); const NamedImport* import = named_imports->at(i);
scope_->module()->AddImport( module()->AddImport(import->import_name, import->local_name,
import->import_name, import->local_name, module_specifier, import->location, zone());
module_specifier, import->location, zone());
// DeclareImport(import->local_name, pos, CHECK_OK); // DeclareImport(import->local_name, pos, CHECK_OK);
} }
} }
...@@ -1631,7 +1627,7 @@ Statement* Parser::ParseExportDefault(bool* ok) { ...@@ -1631,7 +1627,7 @@ Statement* Parser::ParseExportDefault(bool* ok) {
// writing to it. // writing to it.
VariableProxy* proxy = NewUnresolved(local_name, CONST); VariableProxy* proxy = NewUnresolved(local_name, CONST);
Declaration* declaration = Declaration* declaration =
factory()->NewVariableDeclaration(proxy, CONST, scope_, pos); factory()->NewVariableDeclaration(proxy, CONST, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
proxy->var()->set_initializer_position(position()); proxy->var()->set_initializer_position(position());
...@@ -1645,9 +1641,9 @@ Statement* Parser::ParseExportDefault(bool* ok) { ...@@ -1645,9 +1641,9 @@ Statement* Parser::ParseExportDefault(bool* ok) {
} }
DCHECK_EQ(local_names.length(), 1); DCHECK_EQ(local_names.length(), 1);
scope_->module()->AddExport( module()->AddExport(local_names.first(),
local_names.first(), ast_value_factory()->default_string(), default_loc, ast_value_factory()->default_string(), default_loc,
zone()); zone());
DCHECK_NOT_NULL(result); DCHECK_NOT_NULL(result);
return result; return result;
...@@ -1675,8 +1671,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1675,8 +1671,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
ExpectContextualKeyword(CStrVector("from"), CHECK_OK); ExpectContextualKeyword(CStrVector("from"), CHECK_OK);
const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK);
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
scope_->module()->AddStarExport( module()->AddStarExport(module_specifier, scanner()->location(), zone());
module_specifier, scanner()->location(), zone());
return factory()->NewEmptyStatement(pos); return factory()->NewEmptyStatement(pos);
} }
...@@ -1713,17 +1708,16 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1713,17 +1708,16 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
DCHECK_EQ(length, export_locations.length()); DCHECK_EQ(length, export_locations.length());
if (module_specifier == nullptr) { if (module_specifier == nullptr) {
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
scope_->module()->AddExport(original_names[i], export_names[i], module()->AddExport(original_names[i], export_names[i],
export_locations[i], zone()); export_locations[i], zone());
} }
} else if (length == 0) { } else if (length == 0) {
scope_->module()->AddEmptyImport( module()->AddEmptyImport(module_specifier, scanner()->location(),
module_specifier, scanner()->location(), zone()); zone());
} else { } else {
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
scope_->module()->AddExport( module()->AddExport(original_names[i], export_names[i],
original_names[i], export_names[i], module_specifier, module_specifier, export_locations[i], zone());
export_locations[i], zone());
} }
} }
return factory()->NewEmptyStatement(pos); return factory()->NewEmptyStatement(pos);
...@@ -1760,7 +1754,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1760,7 +1754,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
return nullptr; return nullptr;
} }
ModuleDescriptor* descriptor = scope_->module(); ModuleDescriptor* descriptor = module();
for (int i = 0; i < names.length(); ++i) { for (int i = 0; i < names.length(); ++i) {
// TODO(neis): Provide better location. // TODO(neis): Provide better location.
descriptor->AddExport(names[i], names[i], scanner()->location(), zone()); descriptor->AddExport(names[i], names[i], scanner()->location(), zone());
...@@ -1910,8 +1904,9 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name, ...@@ -1910,8 +1904,9 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name,
// truly local variable, and the scope of the variable is always the function // truly local variable, and the scope of the variable is always the function
// scope. // scope.
// Let/const variables are always added to the immediately enclosing scope. // Let/const variables are always added to the immediately enclosing scope.
Scope* scope = Scope* scope = IsLexicalVariableMode(mode)
IsLexicalVariableMode(mode) ? scope_ : scope_->DeclarationScope(); ? this->scope()
: this->scope()->DeclarationScope();
return scope->NewUnresolved(factory(), name, Variable::NORMAL, return scope->NewUnresolved(factory(), name, Variable::NORMAL,
scanner()->location().beg_pos, scanner()->location().beg_pos,
scanner()->location().end_pos); scanner()->location().end_pos);
...@@ -1922,7 +1917,7 @@ void* Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { ...@@ -1922,7 +1917,7 @@ void* Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) {
DCHECK_NOT_NULL(local_name); DCHECK_NOT_NULL(local_name);
VariableProxy* proxy = NewUnresolved(local_name, IMPORT); VariableProxy* proxy = NewUnresolved(local_name, IMPORT);
Declaration* declaration = Declaration* declaration =
factory()->NewVariableDeclaration(proxy, IMPORT, scope_, pos); factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
return nullptr; return nullptr;
} }
...@@ -1937,7 +1932,7 @@ Variable* Parser::Declare(Declaration* declaration, ...@@ -1937,7 +1932,7 @@ Variable* Parser::Declare(Declaration* declaration,
VariableMode mode = declaration->mode(); VariableMode mode = declaration->mode();
DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY);
bool is_function_declaration = declaration->IsFunctionDeclaration(); bool is_function_declaration = declaration->IsFunctionDeclaration();
if (scope == nullptr) scope = scope_; if (scope == nullptr) scope = this->scope();
Scope* declaration_scope = Scope* declaration_scope =
IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope(); IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope();
Variable* var = NULL; Variable* var = NULL;
...@@ -2109,14 +2104,14 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { ...@@ -2109,14 +2104,14 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
// accessible while parsing the first time not when reparsing // accessible while parsing the first time not when reparsing
// because of lazy compilation. // because of lazy compilation.
// TODO(adamk): Should this be ClosureScope()? // TODO(adamk): Should this be ClosureScope()?
scope_->DeclarationScope()->ForceEagerCompilation(); scope()->DeclarationScope()->ForceEagerCompilation();
// TODO(1240846): It's weird that native function declarations are // TODO(1240846): It's weird that native function declarations are
// introduced dynamically when we meet their declarations, whereas // introduced dynamically when we meet their declarations, whereas
// other functions are set up when entering the surrounding scope. // other functions are set up when entering the surrounding scope.
VariableProxy* proxy = NewUnresolved(name, VAR); VariableProxy* proxy = NewUnresolved(name, VAR);
Declaration* declaration = Declaration* declaration =
factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); factory()->NewVariableDeclaration(proxy, VAR, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
NativeFunctionLiteral* lit = NativeFunctionLiteral* lit =
factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition); factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition);
...@@ -2202,11 +2197,11 @@ Statement* Parser::ParseHoistableDeclaration( ...@@ -2202,11 +2197,11 @@ Statement* Parser::ParseHoistableDeclaration(
// In ES6, a function behaves as a lexical binding, except in // In ES6, a function behaves as a lexical binding, except in
// a script scope, or the initial scope of eval or another function. // a script scope, or the initial scope of eval or another function.
VariableMode mode = VariableMode mode =
(!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
: VAR; : VAR;
VariableProxy* proxy = NewUnresolved(variable_name, mode); VariableProxy* proxy = NewUnresolved(variable_name, mode);
Declaration* declaration = Declaration* declaration =
factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
if (names) names->Add(variable_name, zone()); if (names) names->Add(variable_name, zone());
EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition);
...@@ -2215,11 +2210,11 @@ Statement* Parser::ParseHoistableDeclaration( ...@@ -2215,11 +2210,11 @@ Statement* Parser::ParseHoistableDeclaration(
// sloppy_block_function_map. Don't add them to the map for async functions. // sloppy_block_function_map. Don't add them to the map for async functions.
// Generators are also supposed to be prohibited; currently doing this behind // Generators are also supposed to be prohibited; currently doing this behind
// a flag and UseCounting violations to assess web compatibility. // a flag and UseCounting violations to assess web compatibility.
if (is_sloppy(language_mode()) && !scope_->is_declaration_scope() && if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
!is_async && !(allow_harmony_restrictive_generators() && is_generator)) { !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
SloppyBlockFunctionStatement* delegate = SloppyBlockFunctionStatement* delegate =
factory()->NewSloppyBlockFunctionStatement(empty, scope_); factory()->NewSloppyBlockFunctionStatement(empty, scope());
scope_->DeclarationScope()->sloppy_block_function_map()->Declare( scope()->DeclarationScope()->sloppy_block_function_map()->Declare(
variable_name, delegate); variable_name, delegate);
return delegate; return delegate;
} }
...@@ -2265,7 +2260,7 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, ...@@ -2265,7 +2260,7 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
VariableProxy* proxy = NewUnresolved(variable_name, LET); VariableProxy* proxy = NewUnresolved(variable_name, LET);
Declaration* declaration = Declaration* declaration =
factory()->NewVariableDeclaration(proxy, LET, scope_, pos); factory()->NewVariableDeclaration(proxy, LET, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
proxy->var()->set_initializer_position(position()); proxy->var()->set_initializer_position(position());
Assignment* assignment = Assignment* assignment =
...@@ -2286,12 +2281,13 @@ Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, ...@@ -2286,12 +2281,13 @@ Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels,
// Construct block expecting 16 statements. // Construct block expecting 16 statements.
Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition);
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
// Parse the statements and collect escaping labels. // Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK); Expect(Token::LBRACE, CHECK_OK);
block_scope->set_start_position(scanner()->location().beg_pos); block_scope->set_start_position(scanner()->location().beg_pos);
{ BlockState block_state(&scope_, block_scope); {
BlockState block_state(&scope_state_, block_scope);
Target target(&this->target_stack_, body); Target target(&this->target_stack_, body);
while (peek() != Token::RBRACE) { while (peek() != Token::RBRACE) {
...@@ -2397,7 +2393,7 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2397,7 +2393,7 @@ Block* Parser::ParseVariableDeclarations(
UNREACHABLE(); // by current callers UNREACHABLE(); // by current callers
} }
parsing_result->descriptor.scope = scope_; parsing_result->descriptor.scope = scope();
parsing_result->descriptor.hoist_scope = nullptr; parsing_result->descriptor.hoist_scope = nullptr;
...@@ -2585,7 +2581,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement( ...@@ -2585,7 +2581,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
// Remove the "ghost" variable that turned out to be a label // Remove the "ghost" variable that turned out to be a label
// from the top scope. This way, we don't try to resolve it // from the top scope. This way, we don't try to resolve it
// during the scope processing. // during the scope processing.
scope_->RemoveUnresolved(var); scope()->RemoveUnresolved(var);
Expect(Token::COLON, CHECK_OK); Expect(Token::COLON, CHECK_OK);
// ES#sec-labelled-function-declarations Labelled Function Declarations // ES#sec-labelled-function-declarations Labelled Function Declarations
if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { if (peek() == Token::FUNCTION && is_sloppy(language_mode())) {
...@@ -2724,7 +2720,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2724,7 +2720,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
tok == Token::RBRACE || tok == Token::RBRACE ||
tok == Token::EOS) { tok == Token::EOS) {
if (IsSubclassConstructor(function_state_->kind())) { if (IsSubclassConstructor(function_state_->kind())) {
return_value = ThisExpression(scope_, factory(), loc.beg_pos); return_value = ThisExpression(scope(), factory(), loc.beg_pos);
} else { } else {
return_value = GetLiteralUndefined(position()); return_value = GetLiteralUndefined(position());
} }
...@@ -2749,8 +2745,8 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2749,8 +2745,8 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
// %_IsJSReceiver(temp) ? temp : 1; // %_IsJSReceiver(temp) ? temp : 1;
// temp = expr // temp = expr
Variable* temp = scope_->NewTemporary( Variable* temp =
ast_value_factory()->empty_string()); scope()->NewTemporary(ast_value_factory()->empty_string());
Assignment* assign = factory()->NewAssignment( Assignment* assign = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos); Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos);
...@@ -2773,7 +2769,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2773,7 +2769,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
// is_undefined ? this : is_object_conditional // is_undefined ? this : is_object_conditional
return_value = factory()->NewConditional( return_value = factory()->NewConditional(
is_undefined, ThisExpression(scope_, factory(), pos), is_undefined, ThisExpression(scope(), factory(), pos),
is_object_conditional, pos); is_object_conditional, pos);
} else { } else {
ReturnExprScope maybe_allow_tail_calls( ReturnExprScope maybe_allow_tail_calls(
...@@ -2796,7 +2792,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2796,7 +2792,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
result = factory()->NewReturnStatement(return_value, loc.beg_pos); result = factory()->NewReturnStatement(return_value, loc.beg_pos);
Scope* decl_scope = scope_->DeclarationScope(); Scope* decl_scope = scope()->DeclarationScope();
if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) { if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) {
ReportMessageAt(loc, MessageTemplate::kIllegalReturn); ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
*ok = false; *ok = false;
...@@ -2824,9 +2820,10 @@ Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels, ...@@ -2824,9 +2820,10 @@ Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels,
Expression* expr = ParseExpression(true, CHECK_OK); Expression* expr = ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Scope* with_scope = NewScope(scope_, WITH_SCOPE); Scope* with_scope = NewScope(scope(), WITH_SCOPE);
Statement* body; Statement* body;
{ BlockState block_state(&scope_, with_scope); {
BlockState block_state(&scope_state_, with_scope);
with_scope->set_start_position(scanner()->peek_location().beg_pos); with_scope->set_start_position(scanner()->peek_location().beg_pos);
body = ParseScopedStatement(labels, true, CHECK_OK); body = ParseScopedStatement(labels, true, CHECK_OK);
with_scope->set_end_position(scanner()->location().end_pos); with_scope->set_end_position(scanner()->location().end_pos);
...@@ -2891,7 +2888,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels, ...@@ -2891,7 +2888,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Variable* tag_variable = Variable* tag_variable =
scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string()); scope()->NewTemporary(ast_value_factory()->dot_switch_tag_string());
Assignment* tag_assign = factory()->NewAssignment( Assignment* tag_assign = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag,
tag->position()); tag->position());
...@@ -2908,7 +2905,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels, ...@@ -2908,7 +2905,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
zone()); zone());
Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE);
cases_scope->SetNonlinear(); cases_scope->SetNonlinear();
SwitchStatement* switch_statement = SwitchStatement* switch_statement =
...@@ -2916,7 +2913,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels, ...@@ -2916,7 +2913,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
cases_scope->set_start_position(scanner()->location().beg_pos); cases_scope->set_start_position(scanner()->location().beg_pos);
{ {
BlockState cases_block_state(&scope_, cases_scope); BlockState cases_block_state(&scope_state_, cases_scope);
Target target(&this->target_stack_, switch_statement); Target target(&this->target_stack_, switch_statement);
Expression* tag_read = factory()->NewVariableProxy(tag_variable); Expression* tag_read = factory()->NewVariableProxy(tag_variable);
...@@ -3000,23 +2997,23 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { ...@@ -3000,23 +2997,23 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
Consume(Token::CATCH); Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
catch_scope = NewScope(scope_, CATCH_SCOPE); catch_scope = NewScope(scope(), CATCH_SCOPE);
catch_scope->set_start_position(scanner()->location().beg_pos); catch_scope->set_start_position(scanner()->location().beg_pos);
{ {
CollectExpressionsInTailPositionToListScope CollectExpressionsInTailPositionToListScope
collect_tail_call_expressions_scope( collect_tail_call_expressions_scope(
function_state_, &tail_call_expressions_in_catch_block); function_state_, &tail_call_expressions_in_catch_block);
BlockState block_state(&scope_, catch_scope); BlockState block_state(&scope_state_, catch_scope);
catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
// Create a block scope to hold any lexical declarations created // Create a block scope to hold any lexical declarations created
// as part of destructuring the catch parameter. // as part of destructuring the catch parameter.
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
block_scope->set_start_position(scanner()->location().beg_pos); block_scope->set_start_position(scanner()->location().beg_pos);
{ {
BlockState block_state(&scope_, block_scope); BlockState block_state(&scope_state_, block_scope);
Target target(&this->target_stack_, catch_block); Target target(&this->target_stack_, catch_block);
const AstRawString* name = ast_value_factory()->dot_catch_string(); const AstRawString* name = ast_value_factory()->dot_catch_string();
...@@ -3038,7 +3035,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { ...@@ -3038,7 +3035,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
DeclarationDescriptor descriptor; DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::NORMAL; descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
descriptor.parser = this; descriptor.parser = this;
descriptor.scope = scope_; descriptor.scope = scope();
descriptor.hoist_scope = nullptr; descriptor.hoist_scope = nullptr;
descriptor.mode = LET; descriptor.mode = LET;
descriptor.declaration_pos = pattern->position(); descriptor.declaration_pos = pattern->position();
...@@ -3240,12 +3237,12 @@ Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -3240,12 +3237,12 @@ Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt,
} else { } else {
if (each->IsArrayLiteral() || each->IsObjectLiteral()) { if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
Variable* temp = Variable* temp =
scope_->NewTemporary(ast_value_factory()->empty_string()); scope()->NewTemporary(ast_value_factory()->empty_string());
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment(
this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy,
kNoSourcePosition), kNoSourcePosition),
scope_); scope());
auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition); auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition);
block->statements()->Add( block->statements()->Add(
factory()->NewExpressionStatement(assign_each, kNoSourcePosition), factory()->NewExpressionStatement(assign_each, kNoSourcePosition),
...@@ -3274,10 +3271,10 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of, ...@@ -3274,10 +3271,10 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
auto avfactory = ast_value_factory(); auto avfactory = ast_value_factory();
Variable* iterator = Variable* iterator =
scope_->NewTemporary(ast_value_factory()->dot_iterator_string()); scope()->NewTemporary(ast_value_factory()->dot_iterator_string());
Variable* result = Variable* result =
scope_->NewTemporary(ast_value_factory()->dot_result_string()); scope()->NewTemporary(ast_value_factory()->dot_result_string());
Variable* completion = scope_->NewTemporary(avfactory->empty_string()); Variable* completion = scope()->NewTemporary(avfactory->empty_string());
// iterator = iterable[Symbol.iterator]() // iterator = iterable[Symbol.iterator]()
Expression* assign_iterator; Expression* assign_iterator;
...@@ -3333,7 +3330,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of, ...@@ -3333,7 +3330,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
// do { let tmp = #result_value; #set_completion_abrupt; tmp } // do { let tmp = #result_value; #set_completion_abrupt; tmp }
// Expression* result_value (gets overwritten) // Expression* result_value (gets overwritten)
if (finalize) { if (finalize) {
Variable* var_tmp = scope_->NewTemporary(avfactory->empty_string()); Variable* var_tmp = scope()->NewTemporary(avfactory->empty_string());
Expression* tmp = factory()->NewVariableProxy(var_tmp); Expression* tmp = factory()->NewVariableProxy(var_tmp);
Expression* assignment = Expression* assignment =
factory()->NewAssignment(Token::ASSIGN, tmp, result_value, nopos); factory()->NewAssignment(Token::ASSIGN, tmp, result_value, nopos);
...@@ -3353,7 +3350,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of, ...@@ -3353,7 +3350,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
factory()->NewAssignment(Token::ASSIGN, each, result_value, nopos); factory()->NewAssignment(Token::ASSIGN, each, result_value, nopos);
if (each->IsArrayLiteral() || each->IsObjectLiteral()) { if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
assign_each = PatternRewriter::RewriteDestructuringAssignment( assign_each = PatternRewriter::RewriteDestructuringAssignment(
this, assign_each->AsAssignment(), scope_); this, assign_each->AsAssignment(), scope());
} }
} }
...@@ -3443,7 +3440,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3443,7 +3440,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
// make statement: temp_x = x. // make statement: temp_x = x.
for (int i = 0; i < names->length(); i++) { for (int i = 0; i < names->length(); i++) {
VariableProxy* proxy = NewUnresolved(names->at(i), LET); VariableProxy* proxy = NewUnresolved(names->at(i), LET);
Variable* temp = scope_->NewTemporary(temp_name); Variable* temp = scope()->NewTemporary(temp_name);
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy, Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy,
proxy, kNoSourcePosition); proxy, kNoSourcePosition);
...@@ -3456,7 +3453,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3456,7 +3453,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Variable* first = NULL; Variable* first = NULL;
// Make statement: first = 1. // Make statement: first = 1.
if (next) { if (next) {
first = scope_->NewTemporary(temp_name); first = scope()->NewTemporary(temp_name);
VariableProxy* first_proxy = factory()->NewVariableProxy(first); VariableProxy* first_proxy = factory()->NewVariableProxy(first);
Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition);
Assignment* assignment = factory()->NewAssignment( Assignment* assignment = factory()->NewAssignment(
...@@ -3480,11 +3477,11 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3480,11 +3477,11 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
ForStatement* outer_loop = ForStatement* outer_loop =
factory()->NewForStatement(NULL, kNoSourcePosition); factory()->NewForStatement(NULL, kNoSourcePosition);
outer_block->statements()->Add(outer_loop, zone()); outer_block->statements()->Add(outer_loop, zone());
outer_block->set_scope(scope_); outer_block->set_scope(scope());
Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition); Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition);
{ {
BlockState block_state(&scope_, inner_scope); BlockState block_state(&scope_state_, inner_scope);
Block* ignore_completion_block = Block* ignore_completion_block =
factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition); factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition);
...@@ -3494,7 +3491,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3494,7 +3491,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
for (int i = 0; i < names->length(); i++) { for (int i = 0; i < names->length(); i++) {
VariableProxy* proxy = NewUnresolved(names->at(i), mode); VariableProxy* proxy = NewUnresolved(names->at(i), mode);
Declaration* declaration = factory()->NewVariableDeclaration( Declaration* declaration = factory()->NewVariableDeclaration(
proxy, mode, scope_, kNoSourcePosition); proxy, mode, scope(), kNoSourcePosition);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
inner_vars.Add(declaration->proxy()->var(), zone()); inner_vars.Add(declaration->proxy()->var(), zone());
VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i));
...@@ -3533,7 +3530,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -3533,7 +3530,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
ignore_completion_block->statements()->Add(clear_first_or_next, zone()); ignore_completion_block->statements()->Add(clear_first_or_next, zone());
} }
Variable* flag = scope_->NewTemporary(temp_name); Variable* flag = scope()->NewTemporary(temp_name);
// Make statement: flag = 1. // Make statement: flag = 1.
{ {
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
...@@ -3640,9 +3637,9 @@ Statement* Parser::ParseScopedStatement(ZoneList<const AstRawString*>* labels, ...@@ -3640,9 +3637,9 @@ Statement* Parser::ParseScopedStatement(ZoneList<const AstRawString*>* labels,
} }
// Make a block around the statement for a lexical binding // Make a block around the statement for a lexical binding
// is introduced by a FunctionDeclaration. // is introduced by a FunctionDeclaration.
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
body_scope->set_start_position(scanner()->location().beg_pos); body_scope->set_start_position(scanner()->location().beg_pos);
BlockState block_state(&scope_, body_scope); BlockState block_state(&scope_state_, body_scope);
Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
Statement* body = ParseFunctionDeclaration(CHECK_OK); Statement* body = ParseFunctionDeclaration(CHECK_OK);
block->statements()->Add(body, zone()); block->statements()->Add(body, zone());
...@@ -3661,9 +3658,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3661,9 +3658,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
bool bound_names_are_lexical = false; bool bound_names_are_lexical = false;
// Create an in-between scope for let-bound iteration variables. // Create an in-between scope for let-bound iteration variables.
Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); Scope* for_scope = NewScope(scope(), BLOCK_SCOPE);
BlockState block_state(&scope_, for_scope); BlockState block_state(&scope_state_, for_scope);
Expect(Token::FOR, CHECK_OK); Expect(Token::FOR, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
for_scope->set_start_position(scanner()->location().beg_pos); for_scope->set_start_position(scanner()->location().beg_pos);
...@@ -3719,7 +3716,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3719,7 +3716,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
++use_counts_[v8::Isolate::kForInInitializer]; ++use_counts_[v8::Isolate::kForInInitializer];
const AstRawString* name = const AstRawString* name =
decl.pattern->AsVariableProxy()->raw_name(); decl.pattern->AsVariableProxy()->raw_name();
VariableProxy* single_var = scope_->NewUnresolved( VariableProxy* single_var = scope()->NewUnresolved(
factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos);
init_block = factory()->NewBlock( init_block = factory()->NewBlock(
nullptr, 2, true, parsing_result.descriptor.declaration_pos); nullptr, 2, true, parsing_result.descriptor.declaration_pos);
...@@ -3748,7 +3745,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3748,7 +3745,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// } // }
Variable* temp = Variable* temp =
scope_->NewTemporary(ast_value_factory()->dot_for_string()); scope()->NewTemporary(ast_value_factory()->dot_for_string());
ForEachStatement* loop = ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, stmt_pos); factory()->NewForEachStatement(mode, labels, stmt_pos);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
...@@ -3766,7 +3763,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3766,7 +3763,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
body_scope->set_start_position(scanner()->location().beg_pos); body_scope->set_start_position(scanner()->location().beg_pos);
Block* body_block = Block* body_block =
...@@ -3776,7 +3773,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3776,7 +3773,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
{ {
ReturnExprScope no_tail_calls(function_state_, ReturnExprScope no_tail_calls(function_state_,
ReturnExprContext::kInsideForInOfBody); ReturnExprContext::kInsideForInOfBody);
BlockState block_state(&scope_, body_scope); BlockState block_state(&scope_state_, body_scope);
Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); Statement* body = ParseScopedStatement(NULL, true, CHECK_OK);
...@@ -3806,7 +3803,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3806,7 +3803,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// all of the names declared in the init of the for-of we're // all of the names declared in the init of the for-of we're
// parsing. // parsing.
if (is_for_var_of) { if (is_for_var_of) {
Scope* catch_scope = scope_; Scope* catch_scope = scope();
while (catch_scope != nullptr && while (catch_scope != nullptr &&
!catch_scope->is_declaration_scope()) { !catch_scope->is_declaration_scope()) {
if (catch_scope->is_catch_scope()) { if (catch_scope->is_catch_scope()) {
...@@ -3852,7 +3849,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3852,7 +3849,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// but visible to everything else. // but visible to everything else.
VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET); VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET);
Declaration* tdz_decl = factory()->NewVariableDeclaration( Declaration* tdz_decl = factory()->NewVariableDeclaration(
tdz_proxy, LET, scope_, kNoSourcePosition); tdz_proxy, LET, scope(), kNoSourcePosition);
Variable* tdz_var = Declare( Variable* tdz_var = Declare(
tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK); tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK);
tdz_var->set_initializer_position(position()); tdz_var->set_initializer_position(position());
...@@ -3947,13 +3944,13 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3947,13 +3944,13 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// If there are let bindings, then condition and the next statement of the // If there are let bindings, then condition and the next statement of the
// for loop must be parsed in a new scope. // for loop must be parsed in a new scope.
Scope* inner_scope = scope_; Scope* inner_scope = scope();
if (bound_names_are_lexical && bound_names.length() > 0) { if (bound_names_are_lexical && bound_names.length() > 0) {
inner_scope = NewScope(for_scope, BLOCK_SCOPE); inner_scope = NewScope(for_scope, BLOCK_SCOPE);
inner_scope->set_start_position(scanner()->location().beg_pos); inner_scope->set_start_position(scanner()->location().beg_pos);
} }
{ {
BlockState block_state(&scope_, inner_scope); BlockState block_state(&scope_state_, inner_scope);
if (peek() != Token::SEMICOLON) { if (peek() != Token::SEMICOLON) {
cond = ParseExpression(true, CHECK_OK); cond = ParseExpression(true, CHECK_OK);
...@@ -3971,7 +3968,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3971,7 +3968,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Statement* result = NULL; Statement* result = NULL;
if (bound_names_are_lexical && bound_names.length() > 0) { if (bound_names_are_lexical && bound_names.length() > 0) {
BlockState block_state(&scope_, for_scope); BlockState block_state(&scope_state_, for_scope);
result = DesugarLexicalBindingsInForStatement( result = DesugarLexicalBindingsInForStatement(
inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init, inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init,
cond, next, body, CHECK_OK); cond, next, body, CHECK_OK);
...@@ -4120,7 +4117,7 @@ void ParserTraits::ParseArrowFunctionFormalParameters( ...@@ -4120,7 +4117,7 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
// parse-time side-effect for parameters that are single-names (not // parse-time side-effect for parameters that are single-names (not
// patterns; for patterns that happens uniformly in // patterns; for patterns that happens uniformly in
// PatternRewriter::VisitVariableProxy). // PatternRewriter::VisitVariableProxy).
parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); parser_->scope()->RemoveUnresolved(expr->AsVariableProxy());
} else if (expr->IsAssignment()) { } else if (expr->IsAssignment()) {
Assignment* assignment = expr->AsAssignment(); Assignment* assignment = expr->AsAssignment();
DCHECK(!assignment->is_compound()); DCHECK(!assignment->is_compound());
...@@ -4129,7 +4126,7 @@ void ParserTraits::ParseArrowFunctionFormalParameters( ...@@ -4129,7 +4126,7 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
// TODO(adamk): Only call this if necessary. // TODO(adamk): Only call this if necessary.
RewriteParameterInitializerScope(parser_->stack_limit(), initializer, RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
parser_->scope_, parameters->scope); parser_->scope(), parameters->scope);
} }
AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
...@@ -4139,7 +4136,7 @@ void ParserTraits::ParseAsyncArrowSingleExpressionBody( ...@@ -4139,7 +4136,7 @@ void ParserTraits::ParseAsyncArrowSingleExpressionBody(
ZoneList<Statement*>* body, bool accept_IN, ZoneList<Statement*>* body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok) { Type::ExpressionClassifier* classifier, int pos, bool* ok) {
parser_->DesugarAsyncFunctionBody( parser_->DesugarAsyncFunctionBody(
parser_->ast_value_factory()->empty_string(), parser_->scope_, body, parser_->ast_value_factory()->empty_string(), parser_->scope(), body,
classifier, kAsyncArrowFunction, FunctionBody::SingleExpression, classifier, kAsyncArrowFunction, FunctionBody::SingleExpression,
accept_IN, pos, ok); accept_IN, pos, ok);
} }
...@@ -4158,8 +4155,8 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, ...@@ -4158,8 +4155,8 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
// } // }
// } // }
scope->ForceContextAllocation(); scope->ForceContextAllocation();
Variable* temp = Variable* temp = this->scope()->NewTemporary(
scope_->NewTemporary(ast_value_factory()->dot_generator_object_string()); ast_value_factory()->dot_generator_object_string());
function_state_->set_generator_object_variable(temp); function_state_->set_generator_object_variable(temp);
Expression* init_generator_variable = factory()->NewAssignment( Expression* init_generator_variable = factory()->NewAssignment(
...@@ -4198,7 +4195,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) { ...@@ -4198,7 +4195,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) {
Expect(Token::DO, CHECK_OK); Expect(Token::DO, CHECK_OK);
Variable* result = Variable* result =
scope_->NewTemporary(ast_value_factory()->dot_result_string()); scope()->NewTemporary(ast_value_factory()->dot_result_string());
Block* block = ParseBlock(nullptr, false, CHECK_OK); Block* block = ParseBlock(nullptr, false, CHECK_OK);
DoExpression* expr = factory()->NewDoExpression(block, result, pos); DoExpression* expr = factory()->NewDoExpression(block, result, pos);
if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { if (!Rewriter::Rewrite(this, expr, ast_value_factory())) {
...@@ -4284,7 +4281,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4284,7 +4281,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_name = ast_value_factory()->empty_string(); function_name = ast_value_factory()->empty_string();
} }
Scope* scope = NewScope(scope_, FUNCTION_SCOPE, kind); Scope* scope = NewScope(this->scope(), FUNCTION_SCOPE, kind);
SetLanguageMode(scope, language_mode); SetLanguageMode(scope, language_mode);
ZoneList<Statement*>* body = NULL; ZoneList<Statement*>* body = NULL;
int arity = -1; int arity = -1;
...@@ -4298,9 +4295,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4298,9 +4295,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Parse function. // Parse function.
{ {
AstNodeFactory function_factory(ast_value_factory()); AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope, kind, FunctionState function_state(&function_state_, &scope_state_, scope, kind,
&function_factory); &function_factory);
scope_->SetScopeName(function_name); this->scope()->SetScopeName(function_name);
ExpressionClassifier formals_classifier(this, &duplicate_finder); ExpressionClassifier formals_classifier(this, &duplicate_finder);
eager_compile_hint = function_state_->this_function_is_parenthesized() eager_compile_hint = function_state_->this_function_is_parenthesized()
...@@ -4312,19 +4309,19 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4312,19 +4309,19 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// because it minimizes the work needed to suspend and resume an // because it minimizes the work needed to suspend and resume an
// activation. The machine code produced for generators (by full-codegen) // activation. The machine code produced for generators (by full-codegen)
// relies on this forced context allocation, but not in an essential way. // relies on this forced context allocation, but not in an essential way.
scope_->ForceContextAllocation(); this->scope()->ForceContextAllocation();
// Calling a generator returns a generator object. That object is stored // Calling a generator returns a generator object. That object is stored
// in a temporary variable, a definition that is used by "yield" // in a temporary variable, a definition that is used by "yield"
// expressions. This also marks the FunctionState as a generator. // expressions. This also marks the FunctionState as a generator.
Variable* temp = scope_->NewTemporary( Variable* temp = this->scope()->NewTemporary(
ast_value_factory()->dot_generator_object_string()); ast_value_factory()->dot_generator_object_string());
function_state.set_generator_object_variable(temp); function_state.set_generator_object_variable(temp);
} }
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
int start_position = scanner()->location().beg_pos; int start_position = scanner()->location().beg_pos;
scope_->set_start_position(start_position); this->scope()->set_start_position(start_position);
ParserFormalParameters formals(scope); ParserFormalParameters formals(scope);
ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
arity = formals.Arity(); arity = formals.Arity();
...@@ -4373,7 +4370,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4373,7 +4370,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// To make this additional case work, both Parser and PreParser implement a // To make this additional case work, both Parser and PreParser implement a
// logic where only top-level functions will be parsed lazily. // logic where only top-level functions will be parsed lazily.
bool is_lazily_parsed = mode() == PARSE_LAZILY && bool is_lazily_parsed = mode() == PARSE_LAZILY &&
scope_->AllowsLazyParsing() && this->scope()->AllowsLazyParsing() &&
!function_state_->this_function_is_parenthesized(); !function_state_->this_function_is_parenthesized();
// Eager or lazy parse? // Eager or lazy parse?
...@@ -4540,14 +4537,14 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count, ...@@ -4540,14 +4537,14 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
if (entry.is_valid() && entry.end_pos() > function_block_pos) { if (entry.is_valid() && entry.end_pos() > function_block_pos) {
scanner()->SeekForward(entry.end_pos() - 1); scanner()->SeekForward(entry.end_pos() - 1);
scope_->set_end_position(entry.end_pos()); scope()->set_end_position(entry.end_pos());
Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void));
total_preparse_skipped_ += scope_->end_position() - function_block_pos; total_preparse_skipped_ += scope()->end_position() - function_block_pos;
*materialized_literal_count = entry.literal_count(); *materialized_literal_count = entry.literal_count();
*expected_property_count = entry.property_count(); *expected_property_count = entry.property_count();
SetLanguageMode(scope_, entry.language_mode()); SetLanguageMode(scope(), entry.language_mode());
if (entry.uses_super_property()) scope_->RecordSuperPropertyUsage(); if (entry.uses_super_property()) scope()->RecordSuperPropertyUsage();
if (entry.calls_eval()) scope_->RecordEvalCall(); if (entry.calls_eval()) scope()->RecordEvalCall();
return; return;
} }
cached_parse_data_->Reject(); cached_parse_data_->Reject();
...@@ -4573,25 +4570,25 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count, ...@@ -4573,25 +4570,25 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
*ok = false; *ok = false;
return; return;
} }
scope_->set_end_position(logger.end()); scope()->set_end_position(logger.end());
Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void));
total_preparse_skipped_ += scope_->end_position() - function_block_pos; total_preparse_skipped_ += scope()->end_position() - function_block_pos;
*materialized_literal_count = logger.literals(); *materialized_literal_count = logger.literals();
*expected_property_count = logger.properties(); *expected_property_count = logger.properties();
SetLanguageMode(scope_, logger.language_mode()); SetLanguageMode(scope(), logger.language_mode());
if (logger.uses_super_property()) { if (logger.uses_super_property()) {
scope_->RecordSuperPropertyUsage(); scope()->RecordSuperPropertyUsage();
} }
if (logger.calls_eval()) { if (logger.calls_eval()) {
scope_->RecordEvalCall(); scope()->RecordEvalCall();
} }
if (produce_cached_parse_data()) { if (produce_cached_parse_data()) {
DCHECK(log_); DCHECK(log_);
// Position right after terminal '}'. // Position right after terminal '}'.
int body_end = scanner()->location().end_pos; int body_end = scanner()->location().end_pos;
log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, log_->LogFunction(function_block_pos, body_end, *materialized_literal_count,
*expected_property_count, scope_->language_mode(), *expected_property_count, scope()->language_mode(),
scope_->uses_super_property(), scope_->calls_eval()); scope()->uses_super_property(), scope()->calls_eval());
} }
} }
...@@ -4656,7 +4653,7 @@ void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) { ...@@ -4656,7 +4653,7 @@ void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) {
Block* Parser::BuildParameterInitializationBlock( Block* Parser::BuildParameterInitializationBlock(
const ParserFormalParameters& parameters, bool* ok) { const ParserFormalParameters& parameters, bool* ok) {
DCHECK(!parameters.is_simple); DCHECK(!parameters.is_simple);
DCHECK(scope_->is_function_scope()); DCHECK(scope()->is_function_scope());
Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition); Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition);
for (int i = 0; i < parameters.params.length(); ++i) { for (int i = 0; i < parameters.params.length(); ++i) {
auto parameter = parameters.params[i]; auto parameter = parameters.params[i];
...@@ -4664,7 +4661,7 @@ Block* Parser::BuildParameterInitializationBlock( ...@@ -4664,7 +4661,7 @@ Block* Parser::BuildParameterInitializationBlock(
DeclarationDescriptor descriptor; DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
descriptor.parser = this; descriptor.parser = this;
descriptor.scope = scope_; descriptor.scope = scope();
descriptor.hoist_scope = nullptr; descriptor.hoist_scope = nullptr;
descriptor.mode = LET; descriptor.mode = LET;
descriptor.declaration_pos = parameter.pattern->position(); descriptor.declaration_pos = parameter.pattern->position();
...@@ -4683,7 +4680,7 @@ Block* Parser::BuildParameterInitializationBlock( ...@@ -4683,7 +4680,7 @@ Block* Parser::BuildParameterInitializationBlock(
// IS_UNDEFINED($param) ? initializer : $param // IS_UNDEFINED($param) ? initializer : $param
// Ensure initializer is rewritten // Ensure initializer is rewritten
RewriteParameterInitializer(parameter.initializer, scope_); RewriteParameterInitializer(parameter.initializer, scope());
auto condition = factory()->NewCompareOperation( auto condition = factory()->NewCompareOperation(
Token::EQ_STRICT, Token::EQ_STRICT,
...@@ -4695,34 +4692,34 @@ Block* Parser::BuildParameterInitializationBlock( ...@@ -4695,34 +4692,34 @@ Block* Parser::BuildParameterInitializationBlock(
initializer_position = parameter.initializer_end_position; initializer_position = parameter.initializer_end_position;
} }
Scope* param_scope = scope_; Scope* param_scope = scope();
Block* param_block = init_block; Block* param_block = init_block;
if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { if (!parameter.is_simple() && scope()->calls_sloppy_eval()) {
param_scope = NewScope(scope_, BLOCK_SCOPE); param_scope = NewScope(scope(), BLOCK_SCOPE);
param_scope->set_is_declaration_scope(); param_scope->set_is_declaration_scope();
param_scope->set_start_position(descriptor.initialization_pos); param_scope->set_start_position(descriptor.initialization_pos);
param_scope->set_end_position(parameter.initializer_end_position); param_scope->set_end_position(parameter.initializer_end_position);
param_scope->RecordEvalCall(); param_scope->RecordEvalCall();
param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
param_block->set_scope(param_scope); param_block->set_scope(param_scope);
descriptor.hoist_scope = scope_; descriptor.hoist_scope = scope();
// Pass the appropriate scope in so that PatternRewriter can appropriately // Pass the appropriate scope in so that PatternRewriter can appropriately
// rewrite inner initializers of the pattern to param_scope // rewrite inner initializers of the pattern to param_scope
descriptor.scope = param_scope; descriptor.scope = param_scope;
// Rewrite the outer initializer to point to param_scope // Rewrite the outer initializer to point to param_scope
RewriteParameterInitializerScope(stack_limit(), initial_value, scope_, RewriteParameterInitializerScope(stack_limit(), initial_value, scope(),
param_scope); param_scope);
} }
{ {
BlockState block_state(&scope_, param_scope); BlockState block_state(&scope_state_, param_scope);
DeclarationParsingResult::Declaration decl( DeclarationParsingResult::Declaration decl(
parameter.pattern, initializer_position, initial_value); parameter.pattern, initializer_position, initial_value);
PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor,
&decl, nullptr, CHECK_OK); &decl, nullptr, CHECK_OK);
} }
if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { if (!parameter.is_simple() && scope()->calls_sloppy_eval()) {
param_scope = param_scope->FinalizeBlockScope(); param_scope = param_scope->FinalizeBlockScope();
if (param_scope != nullptr) { if (param_scope != nullptr) {
CheckConflictingVarDeclarations(param_scope, CHECK_OK); CheckConflictingVarDeclarations(param_scope, CHECK_OK);
...@@ -4736,7 +4733,7 @@ Block* Parser::BuildParameterInitializationBlock( ...@@ -4736,7 +4733,7 @@ Block* Parser::BuildParameterInitializationBlock(
Block* Parser::BuildRejectPromiseOnException(Block* block) { Block* Parser::BuildRejectPromiseOnException(Block* block) {
// try { <block> } catch (error) { return Promise.reject(error); } // try { <block> } catch (error) { return Promise.reject(error); }
Block* try_block = block; Block* try_block = block;
Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); Scope* catch_scope = NewScope(scope(), CATCH_SCOPE);
catch_scope->set_is_hidden(); catch_scope->set_is_hidden();
Variable* catch_variable = Variable* catch_variable =
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR,
...@@ -4763,7 +4760,7 @@ Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { ...@@ -4763,7 +4760,7 @@ Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) {
args->Add(factory()->NewThisFunction(pos), zone()); args->Add(factory()->NewThisFunction(pos), zone());
args->Add(IsArrowFunction(kind) args->Add(IsArrowFunction(kind)
? GetLiteralUndefined(pos) ? GetLiteralUndefined(pos)
: ThisExpression(scope_, factory(), kNoSourcePosition), : ThisExpression(scope(), factory(), kNoSourcePosition),
zone()); zone());
return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args,
pos); pos);
...@@ -4805,10 +4802,10 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -4805,10 +4802,10 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
} }
ZoneList<Statement*>* body = result; ZoneList<Statement*>* body = result;
Scope* inner_scope = scope_; Scope* inner_scope = scope();
Block* inner_block = nullptr; Block* inner_block = nullptr;
if (!parameters.is_simple) { if (!parameters.is_simple) {
inner_scope = NewScope(scope_, BLOCK_SCOPE); inner_scope = NewScope(scope(), BLOCK_SCOPE);
inner_scope->set_is_declaration_scope(); inner_scope->set_is_declaration_scope();
inner_scope->set_start_position(scanner()->location().beg_pos); inner_scope->set_start_position(scanner()->location().beg_pos);
inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
...@@ -4817,7 +4814,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -4817,7 +4814,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
} }
{ {
BlockState block_state(&scope_, inner_scope); BlockState block_state(&scope_state_, inner_scope);
if (IsGeneratorFunction(kind)) { if (IsGeneratorFunction(kind)) {
// We produce: // We produce:
...@@ -4845,9 +4842,9 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -4845,9 +4842,9 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
// The position of the yield is important for reporting the exception // The position of the yield is important for reporting the exception
// caused by calling the .throw method on a generator suspended at the // caused by calling the .throw method on a generator suspended at the
// initial yield (i.e. right after generator instantiation). // initial yield (i.e. right after generator instantiation).
Yield* yield = Yield* yield = factory()->NewYield(get_proxy, assignment,
factory()->NewYield(get_proxy, assignment, scope_->start_position(), scope()->start_position(),
Yield::kOnExceptionThrow); Yield::kOnExceptionThrow);
try_block->statements()->Add( try_block->statements()->Add(
factory()->NewExpressionStatement(yield, kNoSourcePosition), factory()->NewExpressionStatement(yield, kNoSourcePosition),
zone()); zone());
...@@ -4884,19 +4881,19 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -4884,19 +4881,19 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
if (IsSubclassConstructor(kind)) { if (IsSubclassConstructor(kind)) {
body->Add(factory()->NewReturnStatement( body->Add(factory()->NewReturnStatement(
this->ThisExpression(scope_, factory(), kNoSourcePosition), this->ThisExpression(scope(), factory(), kNoSourcePosition),
kNoSourcePosition), kNoSourcePosition),
zone()); zone());
} }
} }
Expect(Token::RBRACE, CHECK_OK); Expect(Token::RBRACE, CHECK_OK);
scope_->set_end_position(scanner()->location().end_pos); scope()->set_end_position(scanner()->location().end_pos);
if (!parameters.is_simple) { if (!parameters.is_simple) {
DCHECK_NOT_NULL(inner_scope); DCHECK_NOT_NULL(inner_scope);
DCHECK_EQ(body, inner_block->statements()); DCHECK_EQ(body, inner_block->statements());
SetLanguageMode(scope_, inner_scope->language_mode()); SetLanguageMode(scope(), inner_scope->language_mode());
Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK);
if (is_sloppy(inner_scope->language_mode())) { if (is_sloppy(inner_scope->language_mode())) {
...@@ -4933,12 +4930,12 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -4933,12 +4930,12 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
// instead of Variables and Proxies as is the case now. // instead of Variables and Proxies as is the case now.
VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY; VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY;
Variable* fvar = new (zone()) Variable* fvar = new (zone())
Variable(scope_, function_name, fvar_mode, Variable::NORMAL, Variable(scope(), function_name, fvar_mode, Variable::NORMAL,
kCreatedInitialized, kNotAssigned); kCreatedInitialized, kNotAssigned);
VariableProxy* proxy = factory()->NewVariableProxy(fvar); VariableProxy* proxy = factory()->NewVariableProxy(fvar);
VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
proxy, fvar_mode, scope_, kNoSourcePosition); proxy, fvar_mode, scope(), kNoSourcePosition);
scope_->DeclareFunctionVar(fvar_declaration); scope()->DeclareFunctionVar(fvar_declaration);
VariableProxy* fproxy = factory()->NewVariableProxy(fvar); VariableProxy* fproxy = factory()->NewVariableProxy(fvar);
result->Set(kFunctionNameAssignmentIndex, result->Set(kFunctionNameAssignmentIndex,
...@@ -4981,8 +4978,9 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( ...@@ -4981,8 +4978,9 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
#undef SET_ALLOW #undef SET_ALLOW
} }
PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
language_mode(), function_state_->kind(), scope_->has_simple_parameters(), language_mode(), function_state_->kind(),
parsing_module_, logger, bookmark, use_counts_); scope()->has_simple_parameters(), parsing_module_, logger, bookmark,
use_counts_);
if (pre_parse_timer_ != NULL) { if (pre_parse_timer_ != NULL) {
pre_parse_timer_->Stop(); pre_parse_timer_->Stop();
} }
...@@ -5007,10 +5005,10 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, ...@@ -5007,10 +5005,10 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
return NULL; return NULL;
} }
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
BlockState block_state(&scope_, block_scope); BlockState block_state(&scope_state_, block_scope);
RaiseLanguageMode(STRICT); RaiseLanguageMode(STRICT);
scope_->SetScopeName(name); scope()->SetScopeName(name);
VariableProxy* proxy = NULL; VariableProxy* proxy = NULL;
if (name != NULL) { if (name != NULL) {
...@@ -5118,7 +5116,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { ...@@ -5118,7 +5116,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
if (extension_ != NULL) { if (extension_ != NULL) {
// The extension structures are only accessible while parsing the // The extension structures are only accessible while parsing the
// very first time not when reparsing because of lazy compilation. // very first time not when reparsing because of lazy compilation.
scope_->DeclarationScope()->ForceEagerCompilation(); scope()->DeclarationScope()->ForceEagerCompilation();
} }
const Runtime::Function* function = Runtime::FunctionForName(name->string()); const Runtime::Function* function = Runtime::FunctionForName(name->string());
...@@ -5666,12 +5664,13 @@ Expression* Parser::SpreadCall(Expression* function, ...@@ -5666,12 +5664,13 @@ Expression* Parser::SpreadCall(Expression* function,
if (function->IsProperty()) { if (function->IsProperty()) {
// Method calls // Method calls
if (function->AsProperty()->IsSuperAccess()) { if (function->AsProperty()->IsSuperAccess()) {
Expression* home = ThisExpression(scope_, factory(), kNoSourcePosition); Expression* home =
ThisExpression(scope(), factory(), kNoSourcePosition);
args->InsertAt(0, function, zone()); args->InsertAt(0, function, zone());
args->InsertAt(1, home, zone()); args->InsertAt(1, home, zone());
} else { } else {
Variable* temp = Variable* temp =
scope_->NewTemporary(ast_value_factory()->empty_string()); scope()->NewTemporary(ast_value_factory()->empty_string());
VariableProxy* obj = factory()->NewVariableProxy(temp); VariableProxy* obj = factory()->NewVariableProxy(temp);
Assignment* assign_obj = factory()->NewAssignment( Assignment* assign_obj = factory()->NewAssignment(
Token::ASSIGN, obj, function->AsProperty()->obj(), Token::ASSIGN, obj, function->AsProperty()->obj(),
...@@ -5716,8 +5715,8 @@ void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) { ...@@ -5716,8 +5715,8 @@ void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) {
void Parser::RaiseLanguageMode(LanguageMode mode) { void Parser::RaiseLanguageMode(LanguageMode mode) {
LanguageMode old = scope_->language_mode(); LanguageMode old = scope()->language_mode();
SetLanguageMode(scope_, old > mode ? old : mode); SetLanguageMode(scope(), old > mode ? old : mode);
} }
void Parser::MarkCollectedTailCallExpressions() { void Parser::MarkCollectedTailCallExpressions() {
...@@ -5776,7 +5775,7 @@ Expression* ParserTraits::RewriteAwaitExpression(Expression* value, ...@@ -5776,7 +5775,7 @@ Expression* ParserTraits::RewriteAwaitExpression(Expression* value,
auto factory = parser_->factory(); auto factory = parser_->factory();
const int nopos = kNoSourcePosition; const int nopos = kNoSourcePosition;
Variable* temp_var = parser_->scope_->NewTemporary( Variable* temp_var = parser_->scope()->NewTemporary(
parser_->ast_value_factory()->empty_string()); parser_->ast_value_factory()->empty_string());
VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var);
Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
...@@ -5913,7 +5912,7 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left, ...@@ -5913,7 +5912,7 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left,
DCHECK_NOT_NULL(lhs->raw_name()); DCHECK_NOT_NULL(lhs->raw_name());
result = result =
this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
lhs->end_position(), scope_, factory()); lhs->end_position(), scope(), factory());
args->Add(left, zone()); args->Add(left, zone());
args->Add(right, zone()); args->Add(right, zone());
Expression* call = Expression* call =
...@@ -5921,8 +5920,8 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left, ...@@ -5921,8 +5920,8 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left,
return factory()->NewAssignment(Token::ASSIGN, result, call, pos); return factory()->NewAssignment(Token::ASSIGN, result, call, pos);
} else if (left->IsProperty()) { } else if (left->IsProperty()) {
Property* prop = left->AsProperty(); Property* prop = left->AsProperty();
auto temp_obj = scope_->NewTemporary(ast_value_factory()->empty_string()); auto temp_obj = scope()->NewTemporary(ast_value_factory()->empty_string());
auto temp_key = scope_->NewTemporary(ast_value_factory()->empty_string()); auto temp_key = scope()->NewTemporary(ast_value_factory()->empty_string());
Expression* assign_obj = factory()->NewAssignment( Expression* assign_obj = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(), Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(),
kNoSourcePosition); kNoSourcePosition);
...@@ -5966,7 +5965,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { ...@@ -5966,7 +5965,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
ZoneList<Expression*>::iterator s = lit->FirstSpread(); ZoneList<Expression*>::iterator s = lit->FirstSpread();
if (s == lit->EndValue()) return nullptr; // no spread, no rewriting... if (s == lit->EndValue()) return nullptr; // no spread, no rewriting...
Variable* result = Variable* result =
scope_->NewTemporary(ast_value_factory()->dot_result_string()); scope()->NewTemporary(ast_value_factory()->dot_result_string());
// NOTE: The value assigned to R is the whole original array literal, // NOTE: The value assigned to R is the whole original array literal,
// spreads included. This will be fixed before the rewritten AST is returned. // spreads included. This will be fixed before the rewritten AST is returned.
// $R = lit // $R = lit
...@@ -5995,7 +5994,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { ...@@ -5995,7 +5994,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
} else { } else {
// If it's a spread, we're adding a for/of loop iterating through it. // If it's a spread, we're adding a for/of loop iterating through it.
Variable* each = Variable* each =
scope_->NewTemporary(ast_value_factory()->dot_for_string()); scope()->NewTemporary(ast_value_factory()->dot_for_string());
Expression* subject = spread->expression(); Expression* subject = spread->expression();
// %AppendElement($R, each) // %AppendElement($R, each)
Statement* append_body; Statement* append_body;
...@@ -6029,7 +6028,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { ...@@ -6029,7 +6028,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) {
DCHECK(expr->IsRewritableExpression()); DCHECK(expr->IsRewritableExpression());
parser_->function_state_->AddDestructuringAssignment( parser_->function_state_->AddDestructuringAssignment(
Parser::DestructuringAssignment(expr, parser_->scope_)); Parser::DestructuringAssignment(expr, parser_->scope()));
} }
...@@ -6180,7 +6179,7 @@ Expression* ParserTraits::RewriteYieldStar( ...@@ -6180,7 +6179,7 @@ Expression* ParserTraits::RewriteYieldStar(
auto factory = parser_->factory(); auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory(); auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope_; auto scope = parser_->scope();
auto zone = parser_->zone(); auto zone = parser_->zone();
...@@ -6745,7 +6744,7 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion, ...@@ -6745,7 +6744,7 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
const int nopos = kNoSourcePosition; const int nopos = kNoSourcePosition;
auto factory = parser_->factory(); auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory(); auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope_; auto scope = parser_->scope();
auto zone = parser_->zone(); auto zone = parser_->zone();
// completion = kNormalCompletion; // completion = kNormalCompletion;
...@@ -6864,7 +6863,7 @@ void ParserTraits::BuildIteratorCloseForCompletion( ...@@ -6864,7 +6863,7 @@ void ParserTraits::BuildIteratorCloseForCompletion(
const int nopos = kNoSourcePosition; const int nopos = kNoSourcePosition;
auto factory = parser_->factory(); auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory(); auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope_; auto scope = parser_->scope();
auto zone = parser_->zone(); auto zone = parser_->zone();
......
...@@ -130,16 +130,17 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction( ...@@ -130,16 +130,17 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
log_ = log; log_ = log;
use_counts_ = use_counts; use_counts_ = use_counts;
// Lazy functions always have trivial outer scopes (no with/catch scopes). // Lazy functions always have trivial outer scopes (no with/catch scopes).
Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); DCHECK_NULL(scope_state_);
PreParserFactory top_factory(NULL); Scope* top_scope = NewScope(nullptr, SCRIPT_SCOPE);
FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, PreParserFactory top_factory(nullptr);
&top_factory); FunctionState top_state(&function_state_, &scope_state_, top_scope,
scope_->SetLanguageMode(language_mode); kNormalFunction, &top_factory);
Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); scope()->SetLanguageMode(language_mode);
Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind);
if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
PreParserFactory function_factory(NULL); PreParserFactory function_factory(nullptr);
FunctionState function_state(&function_state_, &scope_, function_scope, kind, FunctionState function_state(&function_state_, &scope_state_, function_scope,
&function_factory); kind, &function_factory);
DCHECK_EQ(Token::LBRACE, scanner()->current_token()); DCHECK_EQ(Token::LBRACE, scanner()->current_token());
bool ok = true; bool ok = true;
int start_position = peek_position(); int start_position = peek_position();
...@@ -153,7 +154,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction( ...@@ -153,7 +154,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
ReportUnexpectedToken(scanner()->current_token()); ReportUnexpectedToken(scanner()->current_token());
} else { } else {
DCHECK_EQ(Token::RBRACE, scanner()->peek()); DCHECK_EQ(Token::RBRACE, scanner()->peek());
if (is_strict(scope_->language_mode())) { if (is_strict(scope()->language_mode())) {
int end_pos = scanner()->location().end_pos; int end_pos = scanner()->location().end_pos;
CheckStrictOctalLiteral(start_position, end_pos, &ok); CheckStrictOctalLiteral(start_position, end_pos, &ok);
CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos);
...@@ -253,13 +254,13 @@ void PreParser::ParseStatementList(int end_token, bool* ok, ...@@ -253,13 +254,13 @@ void PreParser::ParseStatementList(int end_token, bool* ok,
bool use_strict_found = statement.IsUseStrictLiteral(); bool use_strict_found = statement.IsUseStrictLiteral();
if (use_strict_found) { if (use_strict_found) {
scope_->SetLanguageMode( scope()->SetLanguageMode(
static_cast<LanguageMode>(scope_->language_mode() | STRICT)); static_cast<LanguageMode>(scope()->language_mode() | STRICT));
} else if (!statement.IsStringLiteral()) { } else if (!statement.IsStringLiteral()) {
directive_prologue = false; directive_prologue = false;
} }
if (use_strict_found && !scope_->HasSimpleParameters()) { if (use_strict_found && !scope()->HasSimpleParameters()) {
// TC39 deemed "use strict" directives to be an error when occurring // TC39 deemed "use strict" directives to be an error when occurring
// in the body of a function with non-simple parameter list, on // in the body of a function with non-simple parameter list, on
// 29/7/2015. https://goo.gl/ueA7Ln // 29/7/2015. https://goo.gl/ueA7Ln
...@@ -306,8 +307,8 @@ PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { ...@@ -306,8 +307,8 @@ PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) {
(legacy && allow_harmony_restrictive_declarations())) { (legacy && allow_harmony_restrictive_declarations())) {
return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); return ParseSubStatement(kDisallowLabelledFunctionStatement, ok);
} else { } else {
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
BlockState block_state(&scope_, body_scope); BlockState block_state(&scope_state_, body_scope);
return ParseFunctionDeclaration(ok); return ParseFunctionDeclaration(ok);
} }
} }
...@@ -477,11 +478,11 @@ PreParser::Statement PreParser::ParseBlock(bool* ok) { ...@@ -477,11 +478,11 @@ PreParser::Statement PreParser::ParseBlock(bool* ok) {
// Block :: // Block ::
// '{' StatementList '}' // '{' StatementList '}'
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
Expect(Token::LBRACE, CHECK_OK); Expect(Token::LBRACE, CHECK_OK);
Statement final = Statement::Default(); Statement final = Statement::Default();
{ {
BlockState block_state(&scope_, block_scope); BlockState block_state(&scope_state_, block_scope);
while (peek() != Token::RBRACE) { while (peek() != Token::RBRACE) {
final = ParseStatementListItem(CHECK_OK); final = ParseStatementListItem(CHECK_OK);
} }
...@@ -791,8 +792,8 @@ PreParser::Statement PreParser::ParseWithStatement(bool* ok) { ...@@ -791,8 +792,8 @@ PreParser::Statement PreParser::ParseWithStatement(bool* ok) {
ParseExpression(true, CHECK_OK); ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Scope* with_scope = NewScope(scope_, WITH_SCOPE); Scope* with_scope = NewScope(scope(), WITH_SCOPE);
BlockState block_state(&scope_, with_scope); BlockState block_state(&scope_state_, with_scope);
ParseScopedStatement(true, CHECK_OK); ParseScopedStatement(true, CHECK_OK);
return Statement::Default(); return Statement::Default();
} }
...@@ -807,9 +808,9 @@ PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { ...@@ -807,9 +808,9 @@ PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) {
ParseExpression(true, CHECK_OK); ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE);
{ {
BlockState cases_block_state(&scope_, cases_scope); BlockState cases_block_state(&scope_state_, cases_scope);
Expect(Token::LBRACE, CHECK_OK); Expect(Token::LBRACE, CHECK_OK);
Token::Value token = peek(); Token::Value token = peek();
while (token != Token::RBRACE) { while (token != Token::RBRACE) {
...@@ -868,10 +869,10 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) { ...@@ -868,10 +869,10 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
// 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
// Create an in-between scope for let-bound iteration variables. // Create an in-between scope for let-bound iteration variables.
Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); Scope* for_scope = NewScope(scope(), BLOCK_SCOPE);
bool has_lexical = false; bool has_lexical = false;
BlockState block_state(&scope_, for_scope); BlockState block_state(&scope_state_, for_scope);
Expect(Token::FOR, CHECK_OK); Expect(Token::FOR, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
if (peek() != Token::SEMICOLON) { if (peek() != Token::SEMICOLON) {
...@@ -958,9 +959,9 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) { ...@@ -958,9 +959,9 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
} }
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
{ {
BlockState block_state(&scope_, body_scope); BlockState block_state(&scope_state_, body_scope);
ParseScopedStatement(true, CHECK_OK); ParseScopedStatement(true, CHECK_OK);
} }
return Statement::Default(); return Statement::Default();
...@@ -973,11 +974,11 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) { ...@@ -973,11 +974,11 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
// If there are let bindings, then condition and the next statement of the // If there are let bindings, then condition and the next statement of the
// for loop must be parsed in a new scope. // for loop must be parsed in a new scope.
Scope* inner_scope = scope_; Scope* inner_scope = scope();
if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE); if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE);
{ {
BlockState block_state(&scope_, inner_scope); BlockState block_state(&scope_state_, inner_scope);
if (peek() != Token::SEMICOLON) { if (peek() != Token::SEMICOLON) {
ParseExpression(true, CHECK_OK); ParseExpression(true, CHECK_OK);
...@@ -1042,7 +1043,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) { ...@@ -1042,7 +1043,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
if (tok == Token::CATCH) { if (tok == Token::CATCH) {
Consume(Token::CATCH); Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); Scope* catch_scope = NewScope(scope(), CATCH_SCOPE);
ExpressionClassifier pattern_classifier(this); ExpressionClassifier pattern_classifier(this);
ParsePrimaryExpression(&pattern_classifier, CHECK_OK); ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK); ValidateBindingPattern(&pattern_classifier, CHECK_OK);
...@@ -1051,10 +1052,10 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) { ...@@ -1051,10 +1052,10 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
CollectExpressionsInTailPositionToListScope CollectExpressionsInTailPositionToListScope
collect_tail_call_expressions_scope( collect_tail_call_expressions_scope(
function_state_, &tail_call_expressions_in_catch_block); function_state_, &tail_call_expressions_in_catch_block);
BlockState block_state(&scope_, catch_scope); BlockState block_state(&scope_state_, catch_scope);
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
{ {
BlockState block_state(&scope_, block_scope); BlockState block_state(&scope_state_, block_scope);
ParseBlock(CHECK_OK); ParseBlock(CHECK_OK);
} }
} }
...@@ -1109,12 +1110,12 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -1109,12 +1110,12 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// '(' FormalParameterList? ')' '{' FunctionBody '}' // '(' FormalParameterList? ')' '{' FunctionBody '}'
// Parse function body. // Parse function body.
bool outer_is_script_scope = scope_->is_script_scope(); bool outer_is_script_scope = scope()->is_script_scope();
Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind);
function_scope->SetLanguageMode(language_mode); function_scope->SetLanguageMode(language_mode);
PreParserFactory factory(NULL); PreParserFactory factory(NULL);
FunctionState function_state(&function_state_, &scope_, function_scope, kind, FunctionState function_state(&function_state_, &scope_state_, function_scope,
&factory); kind, &factory);
DuplicateFinder duplicate_finder(scanner()->unicode_cache()); DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(this, &duplicate_finder); ExpressionClassifier formals_classifier(this, &duplicate_finder);
...@@ -1209,7 +1210,7 @@ void PreParser::ParseLazyFunctionLiteralBody(bool* ok, ...@@ -1209,7 +1210,7 @@ void PreParser::ParseLazyFunctionLiteralBody(bool* ok,
log_->LogFunction(body_start, body_end, log_->LogFunction(body_start, body_end,
function_state_->materialized_literal_count(), function_state_->materialized_literal_count(),
function_state_->expected_property_count(), language_mode(), function_state_->expected_property_count(), language_mode(),
scope_->uses_super_property(), scope_->calls_eval()); scope()->uses_super_property(), scope()->calls_eval());
} }
PreParserExpression PreParser::ParseClassLiteral( PreParserExpression PreParser::ParseClassLiteral(
...@@ -1230,12 +1231,12 @@ PreParserExpression PreParser::ParseClassLiteral( ...@@ -1230,12 +1231,12 @@ PreParserExpression PreParser::ParseClassLiteral(
} }
LanguageMode class_language_mode = language_mode(); LanguageMode class_language_mode = language_mode();
Scope* scope = NewScope(scope_, BLOCK_SCOPE); Scope* scope = NewScope(this->scope(), BLOCK_SCOPE);
BlockState block_state(&scope_, scope); BlockState block_state(&scope_state_, scope);
scope_->SetLanguageMode( this->scope()->SetLanguageMode(
static_cast<LanguageMode>(class_language_mode | STRICT)); static_cast<LanguageMode>(class_language_mode | STRICT));
// TODO(marja): Make PreParser use scope names too. // TODO(marja): Make PreParser use scope names too.
// scope_->SetScopeName(name); // this->scope()->SetScopeName(name);
bool has_extends = Check(Token::EXTENDS); bool has_extends = Check(Token::EXTENDS);
if (has_extends) { if (has_extends) {
...@@ -1312,7 +1313,7 @@ PreParserExpression PreParser::ParseDoExpression(bool* ok) { ...@@ -1312,7 +1313,7 @@ PreParserExpression PreParser::ParseDoExpression(bool* ok) {
void PreParserTraits::ParseAsyncArrowSingleExpressionBody( void PreParserTraits::ParseAsyncArrowSingleExpressionBody(
PreParserStatementList body, bool accept_IN, PreParserStatementList body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok) { Type::ExpressionClassifier* classifier, int pos, bool* ok) {
Scope* scope = pre_parser_->scope_; Scope* scope = pre_parser_->scope();
scope->ForceContextAllocation(); scope->ForceContextAllocation();
PreParserExpression return_value = pre_parser_->ParseAssignmentExpression( PreParserExpression return_value = pre_parser_->ParseAssignmentExpression(
......
...@@ -1037,7 +1037,8 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -1037,7 +1037,8 @@ class PreParser : public ParserBase<PreParserTraits> {
// during parsing. // during parsing.
PreParseResult PreParseProgram(int* materialized_literals = 0, PreParseResult PreParseProgram(int* materialized_literals = 0,
bool is_module = false) { bool is_module = false) {
Scope* scope = NewScope(scope_, SCRIPT_SCOPE); DCHECK_NULL(scope_state_);
Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
// ModuleDeclarationInstantiation for Source Text Module Records creates a // ModuleDeclarationInstantiation for Source Text Module Records creates a
// new Module Environment Record whose outer lexical environment record is // new Module Environment Record whose outer lexical environment record is
...@@ -1046,9 +1047,9 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -1046,9 +1047,9 @@ class PreParser : public ParserBase<PreParserTraits> {
scope = NewScope(scope, MODULE_SCOPE); scope = NewScope(scope, MODULE_SCOPE);
} }
PreParserFactory factory(NULL); PreParserFactory factory(nullptr);
FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, FunctionState top_scope(&function_state_, &scope_state_, scope,
&factory); kNormalFunction, &factory);
bool ok = true; bool ok = true;
int start_position = scanner()->peek_location().beg_pos; int start_position = scanner()->peek_location().beg_pos;
parsing_module_ = is_module; parsing_module_ = is_module;
...@@ -1056,7 +1057,7 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -1056,7 +1057,7 @@ class PreParser : public ParserBase<PreParserTraits> {
if (stack_overflow()) return kPreParseStackOverflow; if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) { if (!ok) {
ReportUnexpectedToken(scanner()->current_token()); ReportUnexpectedToken(scanner()->current_token());
} else if (is_strict(scope_->language_mode())) { } else if (is_strict(this->scope()->language_mode())) {
CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, CheckStrictOctalLiteral(start_position, scanner()->location().end_pos,
&ok); &ok);
CheckDecimalLiteralWithLeadingZero(use_counts_, start_position, CheckDecimalLiteralWithLeadingZero(use_counts_, start_position,
...@@ -1245,11 +1246,11 @@ PreParserStatementList PreParser::ParseEagerFunctionBody( ...@@ -1245,11 +1246,11 @@ PreParserStatementList PreParser::ParseEagerFunctionBody(
FunctionLiteral::FunctionType function_type, bool* ok) { FunctionLiteral::FunctionType function_type, bool* ok) {
ParsingModeScope parsing_mode(this, PARSE_EAGERLY); ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
Scope* inner_scope = scope_; Scope* inner_scope = scope();
if (!parameters.is_simple) inner_scope = NewScope(scope_, BLOCK_SCOPE); if (!parameters.is_simple) inner_scope = NewScope(scope(), BLOCK_SCOPE);
{ {
BlockState block_state(&scope_, inner_scope); BlockState block_state(&scope_state_, inner_scope);
ParseStatementList(Token::RBRACE, ok); ParseStatementList(Token::RBRACE, ok);
if (!*ok) return PreParserStatementList(); if (!*ok) return PreParserStatementList();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment