Commit 7631b923 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[ast] Remove variable_ field from TryCatchStatement.

This is always the single variable declared in the catch scope.

BUG=

Change-Id: I05ccc48f57394268432c9b5b8c76f9db1b3b6312
Reviewed-on: https://chromium-review.googlesource.com/448041Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43571}
parent a022a1a9
......@@ -1101,7 +1101,6 @@ class TryStatement : public Statement {
class TryCatchStatement final : public TryStatement {
public:
Scope* scope() { return scope_; }
Variable* variable() { return variable_; }
Block* catch_block() const { return catch_block_; }
void set_catch_block(Block* b) { catch_block_ = b; }
......@@ -1122,18 +1121,15 @@ class TryCatchStatement final : public TryStatement {
private:
friend class AstNodeFactory;
TryCatchStatement(Block* try_block, Scope* scope, Variable* variable,
Block* catch_block,
TryCatchStatement(Block* try_block, Scope* scope, Block* catch_block,
HandlerTable::CatchPrediction catch_prediction, int pos)
: TryStatement(try_block, pos, kTryCatchStatement),
scope_(scope),
variable_(variable),
catch_block_(catch_block) {
catch_prediction_ = catch_prediction;
}
Scope* scope_;
Variable* variable_;
Block* catch_block_;
};
......@@ -3245,38 +3241,33 @@ class AstNodeFactory final BASE_EMBEDDED {
}
TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope,
Variable* variable,
Block* catch_block, int pos) {
return new (zone_) TryCatchStatement(
try_block, scope, variable, catch_block, HandlerTable::CAUGHT, pos);
return new (zone_) TryCatchStatement(try_block, scope, catch_block,
HandlerTable::CAUGHT, pos);
}
TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block,
Scope* scope,
Variable* variable,
Block* catch_block,
int pos) {
return new (zone_) TryCatchStatement(
try_block, scope, variable, catch_block, HandlerTable::UNCAUGHT, pos);
return new (zone_) TryCatchStatement(try_block, scope, catch_block,
HandlerTable::UNCAUGHT, pos);
}
TryCatchStatement* NewTryCatchStatementForDesugaring(Block* try_block,
Scope* scope,
Variable* variable,
Block* catch_block,
int pos) {
return new (zone_) TryCatchStatement(
try_block, scope, variable, catch_block, HandlerTable::DESUGARING, pos);
return new (zone_) TryCatchStatement(try_block, scope, catch_block,
HandlerTable::DESUGARING, pos);
}
TryCatchStatement* NewTryCatchStatementForAsyncAwait(Block* try_block,
Scope* scope,
Variable* variable,
Block* catch_block,
int pos) {
return new (zone_)
TryCatchStatement(try_block, scope, variable, catch_block,
HandlerTable::ASYNC_AWAIT, pos);
return new (zone_) TryCatchStatement(try_block, scope, catch_block,
HandlerTable::ASYNC_AWAIT, pos);
}
TryFinallyStatement* NewTryFinallyStatement(Block* try_block,
......
......@@ -856,9 +856,8 @@ void AstPrinter::VisitForOfStatement(ForOfStatement* node) {
void AstPrinter::VisitTryCatchStatement(TryCatchStatement* node) {
IndentedScope indent(this, "TRY CATCH", node->position());
PrintTryStatement(node);
PrintLiteralWithModeIndented("CATCHVAR",
node->variable(),
node->variable()->name());
PrintLiteralWithModeIndented("CATCHVAR", node->scope()->catch_variable(),
node->scope()->catch_variable()->name());
PrintIndentedVisit("CATCH", node->catch_block());
}
......
......@@ -360,10 +360,10 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
// The scope immediately surrounding this scope, or NULL.
Scope* outer_scope() const { return outer_scope_; }
const AstRawString* catch_variable_name() const {
Variable* catch_variable() const {
DCHECK(is_catch_scope());
DCHECK_EQ(1, num_var());
return static_cast<AstRawString*>(variables_.Start()->key);
return static_cast<Variable*>(variables_.Start()->value);
}
// ---------------------------------------------------------------------------
......
......@@ -222,8 +222,7 @@ void ALAA::VisitSloppyBlockFunctionStatement(
void ALAA::VisitTryCatchStatement(TryCatchStatement* stmt) {
Visit(stmt->try_block());
Visit(stmt->catch_block());
// TODO(turbofan): are catch variables well-scoped?
AnalyzeAssignment(stmt->variable());
AnalyzeAssignment(stmt->scope()->catch_variable());
}
......
......@@ -1392,7 +1392,7 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
try_control_builder.EndTry();
// Create a catch scope that binds the exception.
BuildNewLocalCatchContext(stmt->variable(), stmt->scope());
BuildNewLocalCatchContext(stmt->scope());
builder()->StoreAccumulatorInRegister(context);
// If requested, clear message object as we enter the catch block.
......@@ -3248,15 +3248,15 @@ void BytecodeGenerator::BuildNewLocalWithContext(Scope* scope) {
builder()->CreateWithContext(extension_object, scope);
}
void BytecodeGenerator::BuildNewLocalCatchContext(Variable* variable,
Scope* scope) {
void BytecodeGenerator::BuildNewLocalCatchContext(Scope* scope) {
ValueResultScope value_execution_result(this);
DCHECK(variable->IsContextSlot());
DCHECK(scope->catch_variable()->IsContextSlot());
Register exception = register_allocator()->NewRegister();
builder()->StoreAccumulatorInRegister(exception);
VisitFunctionClosureForContext();
builder()->CreateCatchContext(exception, variable->raw_name(), scope);
builder()->CreateCatchContext(exception, scope->catch_variable()->raw_name(),
scope);
}
void BytecodeGenerator::VisitObjectLiteralAccessor(
......
......@@ -122,7 +122,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
void BuildNewLocalActivationContext();
void BuildLocalActivationContextInitialization();
void BuildNewLocalBlockContext(Scope* scope);
void BuildNewLocalCatchContext(Variable* variable, Scope* scope);
void BuildNewLocalCatchContext(Scope* scope);
void BuildNewLocalWithContext(Scope* scope);
void VisitGeneratorPrologue();
......
......@@ -587,7 +587,6 @@ class ParserBase {
public:
explicit CatchInfo(ParserBase* parser)
: name(parser->impl()->EmptyIdentifier()),
variable(nullptr),
pattern(parser->impl()->EmptyExpression()),
scope(nullptr),
init_block(parser->impl()->NullBlock()),
......@@ -595,7 +594,6 @@ class ParserBase {
bound_names(1, parser->zone()),
tail_call_expressions(parser->zone()) {}
IdentifierT name;
Variable* variable;
ExpressionT pattern;
Scope* scope;
BlockT init_block;
......
......@@ -1676,7 +1676,8 @@ void Parser::RewriteCatchPattern(CatchInfo* catch_info, bool* ok) {
DCHECK_NOT_NULL(catch_info->pattern);
catch_info->name = ast_value_factory()->dot_catch_string();
}
catch_info->variable = catch_info->scope->DeclareLocal(catch_info->name, VAR);
Variable* catch_variable =
catch_info->scope->DeclareLocal(catch_info->name, VAR);
if (catch_info->pattern != nullptr) {
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
......@@ -1690,7 +1691,7 @@ void Parser::RewriteCatchPattern(CatchInfo* catch_info, bool* ok) {
DeclarationParsingResult::Declaration decl(
catch_info->pattern, initializer_position,
factory()->NewVariableProxy(catch_info->variable));
factory()->NewVariableProxy(catch_variable));
catch_info->init_block =
factory()->NewBlock(nullptr, 8, true, kNoSourcePosition);
......@@ -1732,10 +1733,8 @@ Statement* Parser::RewriteTryStatement(Block* try_block, Block* catch_block,
if (catch_block != nullptr && finally_block != nullptr) {
// If we have both, create an inner try/catch.
DCHECK_NOT_NULL(catch_info.scope);
DCHECK_NOT_NULL(catch_info.variable);
TryCatchStatement* statement;
statement = factory()->NewTryCatchStatement(try_block, catch_info.scope,
catch_info.variable,
catch_block, kNoSourcePosition);
try_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
......@@ -1751,9 +1750,8 @@ Statement* Parser::RewriteTryStatement(Block* try_block, Block* catch_block,
DCHECK_NULL(finally_block);
DCHECK_NOT_NULL(catch_info.scope);
DCHECK_NOT_NULL(catch_info.variable);
return factory()->NewTryCatchStatement(
try_block, catch_info.scope, catch_info.variable, catch_block, pos);
return factory()->NewTryCatchStatement(try_block, catch_info.scope,
catch_block, pos);
} else {
DCHECK_NOT_NULL(finally_block);
return factory()->NewTryFinallyStatement(try_block, finally_block, pos);
......@@ -1992,7 +1990,7 @@ void Parser::DesugarBindingInForEachStatement(ForInfo* for_info,
Scope* catch_scope = scope();
while (catch_scope != nullptr && !catch_scope->is_declaration_scope()) {
if (catch_scope->is_catch_scope()) {
auto name = catch_scope->catch_variable_name();
auto name = catch_scope->catch_variable()->raw_name();
// If it's a simple binding and the name is declared in the for loop.
if (name != ast_value_factory()->dot_catch_string() &&
for_info->bound_names.Contains(name)) {
......@@ -3015,9 +3013,8 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) {
factory()->NewReturnStatement(promise_reject, kNoSourcePosition));
TryStatement* try_catch_statement =
factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope,
catch_variable, catch_block,
kNoSourcePosition);
factory()->NewTryCatchStatementForAsyncAwait(
inner_block, catch_scope, catch_block, kNoSourcePosition);
// There is no TryCatchFinally node, so wrap it in an outer try/finally
Block* outer_try_block = IgnoreCompletion(try_catch_statement);
......@@ -4511,10 +4508,10 @@ Expression* Parser::RewriteYieldStar(Expression* generator,
Scope* catch_scope = NewScope(CATCH_SCOPE);
catch_scope->set_is_hidden();
const AstRawString* name = ast_value_factory()->dot_catch_string();
Variable* catch_variable = catch_scope->DeclareLocal(name, VAR);
catch_scope->DeclareLocal(name, VAR);
try_catch = factory()->NewTryCatchStatementForDesugaring(
try_block, catch_scope, catch_variable, catch_block, nopos);
try_block, catch_scope, catch_block, nopos);
}
// try { ... } finally { ... }
......@@ -4815,7 +4812,7 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion,
catch_block->statements()->Add(rethrow, zone());
try_catch = factory()->NewTryCatchStatementForReThrow(
iterator_use, catch_scope, catch_variable, catch_block, nopos);
iterator_use, catch_scope, catch_block, nopos);
}
// try { #try_catch } finally { #maybe_close }
......@@ -4913,12 +4910,11 @@ void Parser::BuildIteratorCloseForCompletion(Scope* scope,
Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos);
Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE);
Variable* catch_variable =
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR);
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR);
catch_scope->set_is_hidden();
try_call_return = factory()->NewTryCatchStatement(
try_block, catch_scope, catch_variable, catch_block, nopos);
try_call_return = factory()->NewTryCatchStatement(try_block, catch_scope,
catch_block, nopos);
}
// let output = %_Call(iteratorReturn, iterator);
......
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