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

Unified Diff: src/parsing/parser-base.h

Issue 2367403003: [modules] Disallow return statement in module body. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/test262/test262.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 47d96d2ddbd1af14486c3cfee884e016f244c06d..ff8f19be381dba783d57ecb31525e2e1b6d97e54 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -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);
}
« no previous file with comments | « no previous file | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698