Commit 4e600299 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[parsing] Add helper for wrapping statement in no-completion block.

BUG=

Change-Id: Id77205450d286be228b493deb69e1489a1e12895
Reviewed-on: https://chromium-review.googlesource.com/445906
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43501}
parent 1c578f24
...@@ -1261,11 +1261,8 @@ Statement* Parser::ParseExportDefault(bool* ok) { ...@@ -1261,11 +1261,8 @@ Statement* Parser::ParseExportDefault(bool* ok) {
Assignment* assignment = factory()->NewAssignment( Assignment* assignment = factory()->NewAssignment(
Token::INIT, decl->proxy(), value, kNoSourcePosition); Token::INIT, decl->proxy(), value, kNoSourcePosition);
Block* block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); result = IgnoreCompletion(
block->statements()->Add( factory()->NewExpressionStatement(assignment, kNoSourcePosition));
factory()->NewExpressionStatement(assignment, kNoSourcePosition),
zone());
result = block;
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
break; break;
...@@ -1512,10 +1509,8 @@ Statement* Parser::DeclareClass(const AstRawString* variable_name, ...@@ -1512,10 +1509,8 @@ Statement* Parser::DeclareClass(const AstRawString* variable_name,
Assignment* assignment = factory()->NewAssignment(Token::INIT, decl->proxy(), Assignment* assignment = factory()->NewAssignment(Token::INIT, decl->proxy(),
value, class_token_pos); value, class_token_pos);
Block* block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); return IgnoreCompletion(
block->statements()->Add( factory()->NewExpressionStatement(assignment, kNoSourcePosition));
factory()->NewExpressionStatement(assignment, kNoSourcePosition), zone());
return block;
} }
Statement* Parser::DeclareNative(const AstRawString* name, int pos, bool* ok) { Statement* Parser::DeclareNative(const AstRawString* name, int pos, bool* ok) {
...@@ -1573,6 +1568,12 @@ bool Parser::ContainsLabel(ZoneList<const AstRawString*>* labels, ...@@ -1573,6 +1568,12 @@ bool Parser::ContainsLabel(ZoneList<const AstRawString*>* labels,
return false; return false;
} }
Block* Parser::IgnoreCompletion(Statement* statement) {
Block* block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
block->statements()->Add(statement, zone());
return block;
}
Expression* Parser::RewriteReturn(Expression* return_value, int pos) { Expression* Parser::RewriteReturn(Expression* return_value, int pos) {
if (IsDerivedConstructor(function_state_->kind())) { if (IsDerivedConstructor(function_state_->kind())) {
// For subclass constructors we need to return this in case of undefined // For subclass constructors we need to return this in case of undefined
...@@ -2096,10 +2097,8 @@ Statement* Parser::InitializeForOfStatement( ...@@ -2096,10 +2097,8 @@ Statement* Parser::InitializeForOfStatement(
Token::ASSIGN, proxy, Token::ASSIGN, proxy,
factory()->NewSmiLiteral(Parser::kAbruptCompletion, nopos), nopos); factory()->NewSmiLiteral(Parser::kAbruptCompletion, nopos), nopos);
Block* block = factory()->NewBlock(nullptr, 1, true, nopos); set_completion_abrupt =
block->statements()->Add( IgnoreCompletion(factory()->NewExpressionStatement(assignment, nopos));
factory()->NewExpressionStatement(assignment, nopos), zone());
set_completion_abrupt = block;
} }
// do { let tmp = #result_value; #set_completion_abrupt; tmp } // do { let tmp = #result_value; #set_completion_abrupt; tmp }
...@@ -2137,10 +2136,8 @@ Statement* Parser::InitializeForOfStatement( ...@@ -2137,10 +2136,8 @@ Statement* Parser::InitializeForOfStatement(
Token::ASSIGN, proxy, Token::ASSIGN, proxy,
factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos); factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
Block* block = factory()->NewBlock(nullptr, 1, true, nopos); set_completion_normal =
block->statements()->Add( IgnoreCompletion(factory()->NewExpressionStatement(assignment, nopos));
factory()->NewExpressionStatement(assignment, nopos), zone());
set_completion_normal = block;
} }
// { #loop-body; #set_completion_normal } // { #loop-body; #set_completion_normal }
...@@ -2384,10 +2381,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement( ...@@ -2384,10 +2381,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Statement* empty = factory()->NewEmptyStatement(kNoSourcePosition); Statement* empty = factory()->NewEmptyStatement(kNoSourcePosition);
Statement* if_flag_break = Statement* if_flag_break =
factory()->NewIfStatement(compare, stop, empty, kNoSourcePosition); factory()->NewIfStatement(compare, stop, empty, kNoSourcePosition);
Block* ignore_completion_block = inner_block->statements()->Add(IgnoreCompletion(if_flag_break), zone());
factory()->NewBlock(NULL, 1, true, kNoSourcePosition);
ignore_completion_block->statements()->Add(if_flag_break, zone());
inner_block->statements()->Add(ignore_completion_block, zone());
} }
inner_block->set_scope(inner_scope); inner_block->set_scope(inner_scope);
...@@ -3014,13 +3008,11 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) { ...@@ -3014,13 +3008,11 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) {
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);
Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
Expression* promise_reject = BuildRejectPromise( Expression* promise_reject = BuildRejectPromise(
factory()->NewVariableProxy(catch_variable), kNoSourcePosition); factory()->NewVariableProxy(catch_variable), kNoSourcePosition);
ReturnStatement* return_promise_reject = Block* catch_block = IgnoreCompletion(
factory()->NewReturnStatement(promise_reject, kNoSourcePosition); factory()->NewReturnStatement(promise_reject, kNoSourcePosition));
catch_block->statements()->Add(return_promise_reject, zone());
TryStatement* try_catch_statement = TryStatement* try_catch_statement =
factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope,
...@@ -3028,13 +3020,10 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) { ...@@ -3028,13 +3020,10 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) {
kNoSourcePosition); kNoSourcePosition);
// There is no TryCatchFinally node, so wrap it in an outer try/finally // There is no TryCatchFinally node, so wrap it in an outer try/finally
Block* outer_try_block = Block* outer_try_block = IgnoreCompletion(try_catch_statement);
factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
outer_try_block->statements()->Add(try_catch_statement, zone());
// finally { %AsyncFunctionPromiseRelease(.promise) } // finally { %AsyncFunctionPromiseRelease(.promise) }
Block* finally_block = Block* finally_block;
factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
{ {
ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone());
args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); args->Add(factory()->NewVariableProxy(PromiseVariable()), zone());
...@@ -3042,7 +3031,7 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) { ...@@ -3042,7 +3031,7 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) {
Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX, args, kNoSourcePosition); Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX, args, kNoSourcePosition);
Statement* promise_release = factory()->NewExpressionStatement( Statement* promise_release = factory()->NewExpressionStatement(
call_promise_release, kNoSourcePosition); call_promise_release, kNoSourcePosition);
finally_block->statements()->Add(promise_release, zone()); finally_block = IgnoreCompletion(promise_release);
} }
Statement* try_finally_statement = factory()->NewTryFinallyStatement( Statement* try_finally_statement = factory()->NewTryFinallyStatement(
...@@ -4793,11 +4782,8 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion, ...@@ -4793,11 +4782,8 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion,
type); type);
DCHECK(block->statements()->length() == 2); DCHECK(block->statements()->length() == 2);
maybe_close = factory()->NewBlock(nullptr, 1, true, nopos); maybe_close = IgnoreCompletion(factory()->NewIfStatement(
maybe_close->statements()->Add( condition, block, factory()->NewEmptyStatement(nopos), nopos));
factory()->NewIfStatement(condition, block,
factory()->NewEmptyStatement(nopos), nopos),
zone());
} }
// try { #try_block } // try { #try_block }
......
...@@ -371,6 +371,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -371,6 +371,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos, V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos,
bool* ok); bool* ok);
V8_INLINE Block* IgnoreCompletion(Statement* statement);
class PatternRewriter final : public AstVisitor<PatternRewriter> { class PatternRewriter final : public AstVisitor<PatternRewriter> {
public: public:
static void DeclareAndInitializeVariables( static void DeclareAndInitializeVariables(
......
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