Commit 1594b706 authored by neis's avatar neis Committed by Commit bot

[modules] Disallow return statement in module body.

R=adamk@chromium.org
BUG=v8:1569

Review-Url: https://codereview.chromium.org/2367403003
Cr-Commit-Position: refs/heads/master@{#39740}
parent 0614eb54
......@@ -4702,6 +4702,17 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement(
Expect(Token::RETURN, CHECK_OK);
Scanner::Location loc = scanner()->location();
switch (GetDeclarationScope()->scope_type()) {
case SCRIPT_SCOPE:
case EVAL_SCOPE:
case MODULE_SCOPE:
impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
*ok = false;
return impl()->NullStatement();
default:
break;
}
Token::Value tok = peek();
ExpressionT return_value = impl()->EmptyExpression();
if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::SEMICOLON ||
......@@ -4730,13 +4741,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement(
}
ExpectSemicolon(CHECK_OK);
return_value = impl()->RewriteReturn(return_value, loc.beg_pos);
DeclarationScope* decl_scope = GetDeclarationScope();
if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) {
impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
*ok = false;
return impl()->NullStatement();
}
return factory()->NewReturnStatement(return_value, loc.beg_pos);
}
......
......@@ -637,7 +637,6 @@
'language/module-code/eval-*': [SKIP],
'language/module-code/instn-*': [SKIP],
'language/module-code/namespace/*': [SKIP],
'language/module-code/parse-err-*': [SKIP],
}], # 'variant == ignition'
]
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