Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 138963318c8793eb4db5973edc1eebf1eb78d170
https://github.com/WebKit/WebKit/commit/138963318c8793eb4db5973edc1eebf1eb78d170
Author: Sosuke Suzuki <[email protected]>
Date: 2026-03-15 (Sun, 15 Mar 2026)
Changed paths:
A JSTests/stress/for-using-initializer-dispose-on-false-condition.js
M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Log Message:
-----------
[JSC] for-using statement should dispose resources when condition is false on
first check
https://bugs.webkit.org/show_bug.cgi?id=309960
Reviewed by Yusuke Suzuki.
When a for statement has a using declaration in its initializer, the loop
body is wrapped in a synthesized try-finally by emitBodyWithUsingIfNeeded
so that resources are disposed on all exit paths. However, the condition
checks generated a direct conditional branch to the loop's breakTarget,
which is emitted after the finally block. This caused disposal to be
skipped when the condition was false on the first iteration:
for (using x = { [Symbol.dispose]() { disposed = true } }; false; ) {}
disposed; // JSC: false, expected: true
test262 did not catch this because
initializer-disposed-at-end-of-forstatement.js
starts with i=0 and tests i<1, always executing at least one iteration before
the bottom check (FallThroughMeansFalse) correctly falls through to the finally.
This patch adds a loopEnd label at the end of the loop body (inside the try)
and routes both condition checks to it when using declarations are present.
When there are no using declarations, the condition false target remains
breakTarget as before, and the unused loopEnd label produces no bytecode.
Test: JSTests/stress/for-using-initializer-dispose-on-false-condition.js
* JSTests/stress/for-using-initializer-dispose-on-false-condition.js: Added.
(shouldBe):
(throw.new.Error):
(shouldBe.f):
(loopTest):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::ForNode::emitBytecode):
Canonical link: https://commits.webkit.org/309304@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications