Repository navigation
A [Symbol.dispose]() that throws while an exception unwinds no longer terminates - #749
Merged
Merged
Conversation
…er terminates
A disposal that threw on the way out of an exception - `try { using d = ...; throw "x" } catch`
with a throwing dispose - terminated the process in every model, in both tiers, on both back ends.
- Windows: the cleanup region ran in a cleanup funclet, and an exception out of one is thrown
during unwinding to the MSVC personality (0x80000003). A cleanup that may throw is now entered
through a catch-all pad, as #733 did for `finally` (windowsCleanupCatches).
- Linux: the cleanup shared its landing pad with the try's catch, ran before it with nothing
caught, and its dispose call had no unwind edge, so the exception left the function. With a
catch or finally of its own, such a cleanup is a catch-all of its own that rethrows to them
(linuxCleanupCatches).
- The cleanup's calls unwind to a copy of the cleanup (cleanupRetries), which re-runs it - each
disposal's flag is cleared before its call - so the resources still to dispose are disposed and
the releases after the throwing call run. Without it the ownership verifier reported every
`using` as leaking on that path. The copy's pad is nested in the cleanup's, so the cleanup's
terminator moves after it, where Win32ExceptionPass reads the nesting from.
The disposal's exception replaces the one it interrupted, as a throw in a `finally` does; there
is no SuppressedError. A second disposal that throws is a nested exception from the copy: this
try's catch takes it on Windows, the caller on Linux.
Test: 00using_dispose_throws.ts (compile, JIT, and the rc/none corpus). Also corrects the
00nested_catch.ts header, which still said reading a catch value was broken (item 5am, fixed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
[Symbol.dispose]()that throws while another exception is unwinding through itsusingterminated the process: every memory model, JIT and AOT, Windows and Linux.What changed (
TryOpLowering)finally(windowsCleanupCatches).linuxCleanupCatches).cleanupRetries). Each disposal's flag is cleared before its call, so the copy skips what was attempted, disposes the remaining resources and runs the releases. Without this the ownership verifier reported everyusingas leaking on that path. The copy's pad is nested in the cleanup's, so the cleanup's terminator moves after it: Win32ExceptionPass reads nesting from code order.Semantics
finallydoes. tslang has noSuppressedError(TC39 wraps both); adding one is a separate decision.Tests
00using_dispose_throws.tscovers: the try's own catch; finally only; a nested block; the caller catching; a catch of another type; a loop; twousings on both paths; both disposals throwing; a disposal that does not throw. It is registered for compile and JIT, plus the rc/none corpus.00nested_catch.tsheader no longer claims that reading a catch value is broken (item 5am, already fixed).🤖 Generated with Claude Code