Skip to content

Inspector: check exceptions in JSJavaScriptCallFrame scopeChain/scopeDescriptions and evaluateWithScopeExtension - #406

Merged
alii merged 4 commits into
mainfrom
ali/inspector-exception-checks
Aug 11, 2026
Merged

alii merged 4 commits into
mainfrom
ali/inspector-exception-checks

Conversation

@alii

@alii alii commented Aug 11, 2026

Copy link
Copy Markdown
Member

Pausing in the debugger with validateExceptionChecks on aborts the inspectee: InjectedScript::wrapCallFrames reads callFrame.scopeChain, and JSJavaScriptCallFrame::scopeChain() ends in a bare return constructArray(...) under a ThrowScope. That is why Bun's inspector tests strip the flag for spawned children (test/js/node/inspector/inspector.test.ts) or sit in test/no-validate-exceptions.txt.

  • JSJavaScriptCallFrame::scopeChain: RELEASE_AND_RETURN around constructArray.
  • JSJavaScriptCallFrame::scopeDescriptions: check after constructEmptyArray before the first putDirectIndex.
  • JSJavaScriptCallFrame::evaluateWithScopeExtension and JSInjectedScriptHost::evaluateWithScopeExtension: RELEASE_AND_RETURN on the result after the rethrow.
  • JSInjectedScriptHost::weakMapEntries / weakSetEntries: check after toIntegerOrInfinity on the fetch count.

The prototype-side host functions already RELEASE_AND_RETURN into these. Verified against oven-sh/bun's test/cli/inspect/debugger-buntranspiledmodule.test.ts driven with the flag forced on for the child once the preview build exists.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical exception-check hygiene following established JSC patterns.

What was reviewed:

  • RELEASE_AND_RETURN around constructArray/return result matches the pattern used throughout getInternalProperties in the same file.
  • RETURN_IF_EXCEPTION after constructEmptyArray in scopeDescriptions mirrors every other constructEmptyArray call site in JSInjectedScriptHost.cpp; also guards against null deref on array.
  • RETURN_IF_EXCEPTION after toIntegerOrInfinity in weakMapEntries/weakSetEntries matches the identical check already present in iteratorEntries.
Extended reasoning...

Overview

This PR adds missing exception-check discipline to six sites across two inspector files (JSJavaScriptCallFrame.cpp and JSInjectedScriptHost.cpp). Each change is one of two forms: wrapping a tail return in RELEASE_AND_RETURN(scope, ...), or inserting RETURN_IF_EXCEPTION(scope, { }) after a call that can throw (constructEmptyArray, toIntegerOrInfinity). The motivation is that validateExceptionChecks aborts the process on the debugger pause path without these, forcing Bun's inspector tests to disable the flag.

Security risks

None. scope.release() is a no-op in release builds, and RETURN_IF_EXCEPTION only adds early-return-on-exception paths that are strictly more correct than continuing with a pending exception (and, in the scopeDescriptions case, avoid dereferencing a null array after allocation failure). No new data flows, no auth/permission surface, no user-controlled input handling changed.

Level of scrutiny

Low. These are the canonical JSC exception-scope idioms applied verbatim — the same file already uses RETURN_IF_EXCEPTION after every other constructEmptyArray and after toIntegerOrInfinity in iteratorEntries, and RELEASE_AND_RETURN / scope.release() before tail calls throughout getInternalProperties. The diff is +6/-3 lines of boilerplate with no logic changes. This is inspector/debugger tooling code, not a hot execution path.

Other factors

The PR description confirms the prototype-side callers already RELEASE_AND_RETURN into these functions, so releasing the inner scope correctly hands the check obligation upward. The two evaluateWithScopeExtension changes are identical to each other and to the shape of the surrounding code. No behavioral change in release builds beyond correct early-exit on OOM/throw.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8b548ba4-0e39-4bfe-abd4-ffacfbb95e2a

📥 Commits

Reviewing files that changed from the base of the PR and between 2301a04 and 05ed830.

📒 Files selected for processing (1)
  • Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp

Walkthrough

JavaScriptCore inspector methods now handle exceptions during value conversion, evaluation, property access, iterator inspection, heap queries, and scope construction. Evaluation and scope-chain returns release the throw scope before returning.

Changes

Inspector exception handling

Layer / File(s) Summary
Inspector value conversion safeguards
Source/JavaScriptCore/inspector/InjectedScriptBase.cpp
jsToInspectorValue and toInspectorValue use exception scopes and return nullptr when conversion raises an exception.
Injected script host exception propagation
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Host operations now propagate exceptions from property access, argument conversion, iterator setup, instance checks, and result insertion. evaluateWithScopeExtension releases the throw scope before returning.
JavaScript call frame exception handling
Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp
evaluateWithScopeExtension and scopeChain use RELEASE_AND_RETURN. scopeDescriptions checks for exceptions after creating the result array.

Possibly related PRs

  • oven-sh/WebKit#384: Both PRs modify InjectedScriptBase.cpp value conversion and its exception handling.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and key fixes, but it omits the required bug title, Bugzilla link, reviewer line, and template-style file/function list. Add the bug title and Bugzilla URL, include the required reviewer line, and list each changed file with its affected functions.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Inspector exception-handling changes in call-frame scope methods and evaluateWithScopeExtension.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Preview Builds

Commit Release Date
2301a04b autobuild-preview-pr-406-2301a04b 2026-08-11 16:14:14 UTC
b0c7cc69 autobuild-preview-pr-406-b0c7cc69 2026-08-11 06:51:45 UTC
49b6570c autobuild-preview-pr-406-49b6570c 2026-08-11 05:04:24 UTC

@alii

alii commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

With scopeChain fixed, driving oven-sh/bun's paused-inspectee test against the preview with validateExceptionChecks on for the child trips the next site on the same path: jsToInspectorValue (InjectedScriptBase.cpp, unchecked JSObject::get under InjectedScript::wrapCallFrames). Folded in #376's change for that (49b6570..b0c7cc6); will keep iterating against previews until pause + evaluateOnCallFrame + resume is clean.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical exception-check hygiene following established JSC patterns.

What was reviewed:

  • RELEASE_AND_RETURN on constructArray/eval results and RETURN_IF_EXCEPTION after constructEmptyArray/toIntegerOrInfinity match the surrounding idiom in the same files.
  • jsToInspectorValue: each throwing call (getIndex, get, getOwnPropertyNames, recursion) is now checked before use; the last check in each branch satisfies the ThrowScope destructor.
  • toInspectorValue's new TopExceptionScope + clearExceptionExceptTermination mirrors JSMicrotask.cpp; existing callers (makeCall, the async lambda) already handle a nullptr return.
Extended reasoning...

Overview

The PR adds exception-scope bookkeeping to the JSC inspector's debugger-pause path so that running with --validateExceptionChecks=1 no longer aborts the inspectee. Three files are touched:

  • JSJavaScriptCallFrame.cpp: scopeChain wraps its tail constructArray in RELEASE_AND_RETURN; scopeDescriptions checks after constructEmptyArray before dereferencing the array; evaluateWithScopeExtension releases the scope on the final return after the rethrow.
  • JSInjectedScriptHost.cpp: evaluateWithScopeExtension gets the same RELEASE_AND_RETURN; weakMapEntries/weakSetEntries check after toIntegerOrInfinity on the fetch-count argument.
  • InjectedScriptBase.cpp: jsToInspectorValue gains a ThrowScope in the object branch with RETURN_IF_EXCEPTION after each getIndex/get/getOwnPropertyNames and after each recursive call; toInspectorValue wraps the whole thing in a TopExceptionScope that clears non-termination exceptions and returns nullptr.

Every change is a one- or few-line insertion of an existing macro; no control flow, data structures, or protocol behaviour is altered.

Security risks

None. This is debug-mode assertion hygiene in inspector-only code. The only observable release-build effect is that OOM/termination during getIndex/get/constructEmptyArray now bails out cleanly instead of continuing with a null/garbage value — strictly a correctness improvement, and toInspectorValue's callers already treat nullptr as "object too deep" and surface an error string.

Level of scrutiny

Low-to-moderate. Inspector host functions are dev-tooling paths, not hot execution or security surfaces. The macros used (RELEASE_AND_RETURN, RETURN_IF_EXCEPTION, DECLARE_TOP_EXCEPTION_SCOPE, clearExceptionExceptTermination) are the canonical JSC idioms and appear throughout the same files and runtime/ in identical shapes. I confirmed the TopExceptionScope API in runtime/TopExceptionScope.h matches the new call site, and that in each modified branch of jsToInspectorValue the final potentially-throwing call is followed by a check before the scope destructs, so validation is satisfied without needing a trailing release.

Other factors

The author is iterating against a preview build with Bun's inspector tests driven under validateExceptionChecks, and folded in the InjectedScriptBase.cpp piece after the first preview surfaced it as the next unhandled site — the diff reflects that fold-in. The follow-up comment notes further sites may surface, but each fix here is independently correct and mergeable; remaining sites (e.g. the asString(...)->value(...) branch in jsToInspectorValue, which is pre-existing and untouched) can land separately. The bug-hunting pass found nothing, and there are no outstanding reviewer requests.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical exception-check additions following the standard JSC ThrowScope pattern.

What was reviewed:

  • RELEASE_AND_RETURN on scopeChain/evaluateWithScopeExtension returns — callers in the prototype files already release into these, so the callee-side release is the right fix for validateExceptionChecks.
  • RETURN_IF_EXCEPTION after constructEmptyArray, toIntegerOrInfinity, getIndex/get/getOwnPropertyNames, and the host getInternalProperties — all match surrounding idiom.
  • toInspectorValue now uses TopExceptionScope and clears non-termination exceptions at the JS→JSON boundary; both call sites (makeCall, makeAsyncCall callback) already treat nullptr as an error, so no behavior regression.
Extended reasoning...

Overview

Adds missing exception checks across three inspector files so the debugger pause path is clean under validateExceptionChecks:

  • JSJavaScriptCallFrame.cpp: RELEASE_AND_RETURN around constructArray in scopeChain, around the result in evaluateWithScopeExtension, and a RETURN_IF_EXCEPTION after constructEmptyArray in scopeDescriptions.
  • JSInjectedScriptHost.cpp: RELEASE_AND_RETURN in evaluateWithScopeExtension, RETURN_IF_EXCEPTION after impl().getInternalProperties and after toIntegerOrInfinity in weakMapEntries/weakSetEntries.
  • InjectedScriptBase.cpp: jsToInspectorValue gains a ThrowScope with checks after getIndex, getOwnPropertyNames, object.get, and each recursive call; toInspectorValue wraps the call in a TopExceptionScope and clears any non-termination exception, returning nullptr.

Security risks

None. This is inspector/debugger plumbing — no auth, crypto, or untrusted-input parsing is touched. The only functional effect outside the validator is that in the (rare) case where constructEmptyArray/get/toIntegerOrInfinity actually throw (OOM, termination), the code now bails early instead of dereferencing a null result or continuing with a pending exception, which is strictly safer.

Level of scrutiny

Low. Every hunk is one of two well-worn JSC idioms: RETURN_IF_EXCEPTION(scope, {}) after a potentially-throwing call, or RELEASE_AND_RETURN(scope, expr) on a tail call that itself may throw. I confirmed the prototype-side wrappers in JSJavaScriptCallFramePrototype.cpp already RELEASE_AND_RETURN into evaluateWithScopeExtension/scopeDescriptions/scopeChain, so releasing the inner scope is the correct handshake. The TopExceptionScope + clearExceptionExceptTermination pattern in toInspectorValue matches existing usage elsewhere in the tree (e.g., VM.cpp, JSMicrotask.cpp), and both callers of toInspectorValue in this file already handle a nullptr return by producing an error string.

Other factors

The author is iterating against preview builds with validateExceptionChecks forced on for the inspectee and folding in each site the validator flags — the description and follow-up comment document exactly which sites were hit and why. No control-flow or logic changes beyond early returns on exception; no design decisions to weigh. The bug-hunting pass found nothing.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical exception-check hygiene following established JSC idioms.

What was reviewed:

  • RELEASE_AND_RETURN on scopeChain/evaluateWithScopeExtension returns and RETURN_IF_EXCEPTION after constructEmptyArray/toIntegerOrInfinity/getOwnPropertyNames/putDirectIndex — all standard patterns matching surrounding code.
  • toInspectorValue's new TopExceptionScope with clearExceptionExceptTermination — callers already treat nullptr as conversion failure, so swallowing here preserves the existing contract.
  • queryInstances lambda returns IterationStatus::Done on exception, then the outer RETURN_IF_EXCEPTION after the iteration scope closes propagates it — no exception is dropped.
Extended reasoning...

Overview

This PR adds missing exception-scope checks to JavaScriptCore inspector host functions so they no longer trip validateExceptionChecks when the debugger pauses. Three files are touched: JSJavaScriptCallFrame.cpp (scopeChain, scopeDescriptions, evaluateWithScopeExtension), JSInjectedScriptHost.cpp (evaluateWithScopeExtension, getOwnPrivatePropertySymbols, getInternalProperties, weakMapEntries/weakSetEntries, iteratorEntries, queryInstances, queryHolders), and InjectedScriptBase.cpp (jsToInspectorValue, toInspectorValue). Every hunk is either a RETURN_IF_EXCEPTION(scope, ...) insertion after a call that can throw, or a RELEASE_AND_RETURN(scope, ...) wrapping a tail expression under a live ThrowScope.

Security risks

None. The changes are purely additive control-flow guards on existing error paths in inspector/debugger support code. No new inputs are parsed, no auth or permission logic is touched, and the happy path is byte-for-byte unchanged (the macros only alter behavior when an exception is already pending). The one place that clears an exception (toInspectorValue) uses clearExceptionExceptTermination, so termination still propagates.

Level of scrutiny

Low-to-moderate. This is core JSC code, but the diff is a rote application of the exception-scope discipline used thousands of times elsewhere in the tree. Each site was checked against the surrounding function's existing scope pattern: the RELEASE_AND_RETURN sites all sit at the tail of functions with a DECLARE_THROW_SCOPE, and the RETURN_IF_EXCEPTION sites all follow calls (constructEmptyArray, getIndex, get, getOwnPropertyNames, toIntegerOrInfinity, putDirectIndex, defaultHasInstance) that are documented throwers. The queryInstances change correctly returns IterationStatus::Done from inside the heap-iteration lambda and re-checks after the HeapIterationScope closes.

Other factors

The author validated the primary path (pause → wrapCallFrames → scopeChain/jsToInspectorValue) against Bun's inspector tests with validateExceptionChecks forced on, iterating across preview builds. CodeRabbit found nothing actionable, and the multi-agent bug scan found no issues. The changes are self-contained, pattern-consistent, and carry no risk of regression on the non-exception path.

@alii
alii merged commit 3997b59 into main Aug 11, 2026
42 of 43 checks passed
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Aug 11, 2026
`447082ab6897` → `3997b59485da` is three commits on the fork:

- oven-sh/WebKit#405: JSC's `DebuggerParseData`, `CachedTypes` and
`Completion` switches get a `BunTranspiledModule` arm next to `Module`.
Runtime ESM that Bun hands to JSC with a prebuilt module record (`bun
test --isolate` / `--parallel`, `bun build --compile` output) uses that
source type, and `gatherDebuggerParseDataForSource` returned false for
it, so `Debugger.setBreakpoint` replied "Could not resolve breakpoint"
and `Debugger.setBreakpointByUrl` returned no locations for those files.
- oven-sh/WebKit#406: exception checks on the inspector's pause /
`evaluateOnCallFrame` / `Runtime.evaluate` paths
(`JSJavaScriptCallFrame`, `JSInjectedScriptHost`, `jsToInspectorValue`).
Under `validateExceptionChecks` (the ASAN lane) a paused inspectee used
to abort at `JSJavaScriptCallFrame::scopeChain`, which is why
`inspector.test.ts` stripped the flag for its children and
`inspect.test.ts` sat in `no-validate-exceptions.txt`. Both workarounds
are removed here; all of `test/cli/inspect/*` and
`test/js/node/inspector/inspector.test.ts` pass locally with the flag
forced on for every child.
- oven-sh/WebKit#403 also landed in between: `ALWAYS_INLINE` is
`__always_inline__` again in release builds, so
`NodeUtilTypesModule.cpp` now includes `ObjectPrototypeInlines.h` for
`objectPrototypeToString` (the only out-of-line use that relied on the
old stopgap; release links locally against the new tarball).

`test/cli/inspect/debugger-buntranspiledmodule.test.ts` (from #35754,
updated for the `scriptType` param the Aug 2 upgrade introduced) drives
`bun test --isolate` under `--inspect-wait` and asserts both breakpoint
calls resolve; it fails on `447082ab` and passes here. #35605 makes
every `bun run` module take the `BunTranspiledModule` path; splitting
the bump out so it can land first. Supersedes #35754.

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant