Commit 8804443f authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[class] Disallow return in class static blocks

Bug: v8:11719
Change-Id: Ib9064e09a77b03adc1234e2f1739983cdab24113
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2898778
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74619}
parent 815bab9f
......@@ -5557,6 +5557,14 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement() {
case MODULE_SCOPE:
impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
return impl()->NullStatement();
case BLOCK_SCOPE:
// Class static blocks disallow return. They are their own var scopes and
// have a varblock scope.
if (function_state_->kind() == kClassStaticInitializerFunction) {
impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
return impl()->NullStatement();
}
break;
default:
break;
}
......
......@@ -115,7 +115,15 @@
{
// 'await' is allowed as an identifier name in named function expressions.
class C { static { (function await() {}); } }
class C1 { static { (function await() {}); } }
// 'return' is allowed across function boundaries inside static blocks.
class C2 { static {
function f1() { return; }
function f2() { return 0; }
let f3 = (x => { return x; })
let f4 = (x => { return; })
}
}
}
function assertDoesntParse(expr, context_start, context_end) {
......@@ -142,4 +150,8 @@ for (let [s, e] of [['', ''],
assertDoesntParse('try {} catch ({await}) {}', s, e);
assertDoesntParse('var {await} = 0;', s, e);
assertDoesntParse('({await} = 0);', s, e);
assertDoesntParse('return;', s, e);
assertDoesntParse('return 0;', s, e);
assertDoesntParse('{ return; }', s, e);
assertDoesntParse('{ return 0; }', s, e);
}
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