Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 328cf24b0ded041b2b0c0fd721e48f7ac278de37
https://github.com/WebKit/WebKit/commit/328cf24b0ded041b2b0c0fd721e48f7ac278de37
Author: Sosuke Suzuki <[email protected]>
Date: 2025-12-29 (Mon, 29 Dec 2025)
Changed paths:
A JSTests/stress/unused-catch-binding.js
M Source/JavaScriptCore/parser/Parser.cpp
M Source/JavaScriptCore/parser/Parser.h
Log Message:
-----------
[JSC] Treat unused catch binding as optional catch binding
https://bugs.webkit.org/show_bug.cgi?id=304703
Reviewed by Yusuke Suzuki.
When a catch clause has a binding that is never used (e.g., `catch (e) {}`
where `e` is not used), treat it the same as optional catch binding (`catch
{}`).
This skips emitPushCatchScope and emitPopCatchScope, avoiding unnecessary
SymbolTable creation and bytecode generation.
This benefits legacy code written before ES2019 that couldn't use the
optional catch binding syntax.
The transformation is skipped when:
- The catch parameter is a destructuring pattern
- The catch block uses eval (which may reference the variable dynamically)
Test: JSTests/stress/unused-catch-binding.js
* JSTests/stress/unused-catch-binding.js: Added.
(shouldBe):
(testUnusedCatchWithReturn.f):
(testUnusedCatchWithReturn):
(testUnusedCatchWithFinally):
(testUsedCatchVariable):
(testCatchVariableInClosure.catch.getter):
(testCatchVariableInClosure):
(testCatchVariableWithEval):
(testCatchVariableWithEvalExpression):
(testCatchVariableWithEvalInner.catch.foo):
(testCatchVariableWithEvalInner):
(testOuterVariableNotAffected):
(testOuterVariableAccessible):
(testNestedTryCatch):
(testNestedTryCatchSameName):
(testUnusedCatchInLoop):
(testUsedCatchInLoop):
(testMixedCatchInLoop):
(testUnderscoreNaming):
(testUnderscoreUsed):
(testThrowNonError):
(testCatchModifiesOuter):
(testSequentialCatches):
(testStrictModeUnused):
(testStrictModeWithEval):
(async testAsyncUnusedCatch):
(async testAsyncUsedCatch):
(testGeneratorUnusedCatch.gen):
(testGeneratorUnusedCatch):
(testGeneratorUsedCatch.gen):
(testGeneratorUsedCatch):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseTryStatement):
* Source/JavaScriptCore/parser/Parser.h:
(JSC::Scope::hasVariableBeingHoisted const):
Canonical link: https://commits.webkit.org/304974@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications