Repository navigation
refactor(native): drop dead IsExceptionPending checks - #40
Merged
Merged
Conversation
binding.gyp defines NAPI_CPP_EXCEPTIONS, so RequireTerminal throws a C++ exception and no JavaScript exception can be pending at these checks. The README no longer mentions them. Signed-off-by: Thomas Kosiewski <tk@coder.com> --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `medium`_ Change-Id: I57b99f0eb37eb11ab878d29a86ade1618be8804e
Member
Author
|
Verdict: PASS+NOTES I checked this PR against its parent Scenario: the six methods, live and after
Gate (same steps at both commits, all exit 0)
Diff review
Note (not caused by this PR, not blocking)
Generated with |
This was referenced Oct 30, 2026
Merged
ThomasK33
added a commit
that referenced
this pull request
Oct 30, 2026
## Why The `verify-native-lifecycle` skill keeps a sync commit. At that commit, its TLA+ model describes the covered native code. The sync commit was still `7366b75` (#12). Since then, #40 to #43, #46, and #49 changed covered code. #46 promised this follow-up. ## What changed - The sync commit moves to `c54051e`, the current main. It includes #48 and #49. - The coverage rows now name `ghostty_terminal_set` (scrollback byte limit) in the constructor and its failure path, `Resize`'s second `ghostty_terminal_resize` call, and the `GHOSTTY_TERMINAL_DATA_MODE` read in `EncodeMouse`. Ghostty v1.4.0 (#43) brought these. - The "no JS inside native methods" assumption now says how each method reads its arguments: 1. `Snapshot` reads its options before `RequireTerminal`, and it builds its result with `DefineValue` and `DefineIndex`. 2. `Feed` and `Resize` call `RequireTerminal` first. After that, they only test types and read strings, bytes, and numbers, which runs no JS. 3. `GetVisibleText`, `FormatPlain`, and `FormatHtml` read no arguments. 4. The assumption was false for `snapshot` until #46. - The bullet that lists where caller JS can run now names public `feed`: `assertFeedData` runs `data instanceof Uint8Array`, which runs a Proxy's `getPrototypeOf` trap after `#assertUsable`. The native null check covers it, as it does for `snapshot`. - `AddonEnvLifecycle.tla` changes in comments only. The `CreateFails` comment now names the `ghostty_terminal_set` failure too. The model itself does not change. #48 changes only a test. #49 changes only `Feed`'s argument checks, so the `Use(t)` step still describes `feed`. ## Verification - I checked each row against `native/terminal.cc` and `src/index.ts` at `c54051e`. - `git diff 7366b75 c54051e` on the covered paths adds no new static state, `Napi::Reference`, or new place that frees `terminal_` or `mouse_encoder_`. - `run.sh`: all 35 rows match EXPECT (`OK: every result matches EXPECT.`). The current config holds all 5 rules. Each of the 6 mutants breaks the rule it guards. The verifier's two notes on `0ff0941` (the `feed` window and the `CreateFails` comment) are fixed in `584c561`. `run.sh` still passes all 35 rows. Workspace 36beaed175 drafted the first version of this commit. I corrected the assumption bullet: it said that every method reads its arguments before `RequireTerminal`, but `Feed` and `Resize` do not. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
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.
Why
The user wants four small leftovers from the mouse-encoding PR (#12) fixed and landed on main. This PR fixes one of them: dead code in
native/terminal.cc.Six methods run
if (env.IsExceptionPending()) return env.Undefined();right afterRequireTerminal(env).binding.gypdefinesNAPI_CPP_EXCEPTIONS, soRequireTerminalreports a disposed terminal by throwing a C++ exception. That throw skips the check. WhenRequireTerminalreturns, no JavaScript exception can be pending: before each check, onlyinfo.Env()andRequireTerminalrun, and neither calls into JavaScript. So the checks never fire.What changed
native/terminal.cc: I deleted the six checks inFeed,Resize,Snapshot,GetVisibleText,FormatPlainandFormatHtml.native/README.md: I removed the clause about those checks. The part that stays true stays.Scope
This is a behavior-preserving refactor.
RequireTerminaland its use-after-dispose error do not change. The other three #12 leftovers are not in this PR.Blast Radius
The change is limited to the six native methods. Callers see the same results and the same errors. No public API, type, or build setting changes.
Verification
Before (unchanged code at
bf41459) and after (this branch) give the same counts:npm ci && LIBGHOSTTY_VT_PREFIX=<ReleaseFast> npm run build:native && npm run build && npm run verifyrm -rf dist && ... CXXFLAGS="-fsanitize=undefined,float-cast-overflow -fno-sanitize-recover=all" ... npm run build:native && npm test && npm run smokenpx vitest run test/terminal.test.ts -t idempotent --reporter=verboseafter the change:makes dispose idempotent and rejects use after disposepassed..agents/skills/verify-native-lifecycle/run.sh "$(mktemp -d)": exit 0, last lineOK: every result matches EXPECT.The model treatsRequireTerminalas the null guard, and that guard stays.Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:medium