Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: e694d1c0c386f716059d728afbd2bcc6aaea2011
https://github.com/WebKit/WebKit/commit/e694d1c0c386f716059d728afbd2bcc6aaea2011
Author: Sosuke Suzuki <[email protected]>
Date: 2026-10-07 (Wed, 07 Oct 2026)
Changed paths:
A JSTests/stress/using-declaration-in-function-nested-in-switch-clause.js
M Source/JavaScriptCore/parser/Parser.cpp
M Source/JavaScriptCore/parser/Parser.h
Log Message:
-----------
[JSC] `using` declaration should be allowed in a function nested in a switch
clause
https://bugs.webkit.org/show_bug.cgi?id=325952
Reviewed by Yusuke Suzuki.
A `using` or `await using` declaration is a syntax error only when it is
contained directly in the StatementList of a CaseClause or DefaultClause.
However, JSC also rejected the declaration in the body of a function nested
in a clause.
switch (0) {
case 0:
(() => { using x = null; })(); // SyntaxError
}
The parser tracked this with m_insideSwitchCaseBody, which was set while
parsing the statements of a clause and reset only by parseBlockStatement().
A function body is not parsed through parseBlockStatement(), so the flag
leaked into it.
Whether a declaration is directly in a clause is a property of the scope it
is declared in. parseSwitchStatement() already pushes a lexical scope for the
case block and it is the only scope where the switch is counted, while
blocks, function bodies and class static blocks nested in a clause push
their own scope. This patch removes m_insideSwitchCaseBody and checks the
current scope instead, so that there is no state to reset when entering a
nested statement list.
Test: JSTests/stress/using-declaration-in-function-nested-in-switch-clause.js
* JSTests/stress/using-declaration-in-function-nested-in-switch-clause.js:
Added.
(shouldBe):
(shouldParse):
(clauses.outer):
(clauses.async outer):
(let.nested):
(f):
(async f):
(get f):
(set f):
(C):
(C.prototype.f):
(C.f):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseStatementListItem):
(JSC::Parser<LexerType>::parseSwitchClauses):
(JSC::Parser<LexerType>::parseSwitchDefaultClause):
(JSC::Parser<LexerType>::parseBlockStatement):
* Source/JavaScriptCore/parser/Parser.h:
(JSC::Scope::isSwitchBlockScope const):
Canonical link: https://commits.webkit.org/323061@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications