Repository navigation
Inspector: check exceptions in JSJavaScriptCallFrame scopeChain/scopeDescriptions and evaluateWithScopeExtension - #406
Conversation
There was a problem hiding this comment.
LGTM — mechanical exception-check hygiene following established JSC patterns.
What was reviewed:
RELEASE_AND_RETURNaroundconstructArray/return resultmatches the pattern used throughoutgetInternalPropertiesin the same file.RETURN_IF_EXCEPTIONafterconstructEmptyArrayinscopeDescriptionsmirrors every otherconstructEmptyArraycall site inJSInjectedScriptHost.cpp; also guards against null deref onarray.RETURN_IF_EXCEPTIONaftertoIntegerOrInfinityinweakMapEntries/weakSetEntriesmatches the identical check already present initeratorEntries.
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughJavaScriptCore 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. ChangesInspector exception handling
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
Preview Builds
|
|
With |
There was a problem hiding this comment.
LGTM — mechanical exception-check hygiene following established JSC patterns.
What was reviewed:
RELEASE_AND_RETURNonconstructArray/eval results andRETURN_IF_EXCEPTIONafterconstructEmptyArray/toIntegerOrInfinitymatch 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 newTopExceptionScope+clearExceptionExceptTerminationmirrorsJSMicrotask.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:scopeChainwraps its tailconstructArrayinRELEASE_AND_RETURN;scopeDescriptionschecks afterconstructEmptyArraybefore dereferencing the array;evaluateWithScopeExtensionreleases the scope on the final return after the rethrow.JSInjectedScriptHost.cpp:evaluateWithScopeExtensiongets the sameRELEASE_AND_RETURN;weakMapEntries/weakSetEntriescheck aftertoIntegerOrInfinityon the fetch-count argument.InjectedScriptBase.cpp:jsToInspectorValuegains aThrowScopein the object branch withRETURN_IF_EXCEPTIONafter eachgetIndex/get/getOwnPropertyNamesand after each recursive call;toInspectorValuewraps the whole thing in aTopExceptionScopethat clears non-termination exceptions and returnsnullptr.
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.
There was a problem hiding this comment.
LGTM — mechanical exception-check additions following the standard JSC ThrowScope pattern.
What was reviewed:
RELEASE_AND_RETURNonscopeChain/evaluateWithScopeExtensionreturns — callers in the prototype files already release into these, so the callee-side release is the right fix forvalidateExceptionChecks.RETURN_IF_EXCEPTIONafterconstructEmptyArray,toIntegerOrInfinity,getIndex/get/getOwnPropertyNames, and the hostgetInternalProperties— all match surrounding idiom.toInspectorValuenow usesTopExceptionScopeand clears non-termination exceptions at the JS→JSON boundary; both call sites (makeCall,makeAsyncCallcallback) already treatnullptras 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_RETURNaroundconstructArrayinscopeChain, around the result inevaluateWithScopeExtension, and aRETURN_IF_EXCEPTIONafterconstructEmptyArrayinscopeDescriptions.JSInjectedScriptHost.cpp:RELEASE_AND_RETURNinevaluateWithScopeExtension,RETURN_IF_EXCEPTIONafterimpl().getInternalPropertiesand aftertoIntegerOrInfinityinweakMapEntries/weakSetEntries.InjectedScriptBase.cpp:jsToInspectorValuegains aThrowScopewith checks aftergetIndex,getOwnPropertyNames,object.get, and each recursive call;toInspectorValuewraps the call in aTopExceptionScopeand clears any non-termination exception, returningnullptr.
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.
There was a problem hiding this comment.
LGTM — mechanical exception-check hygiene following established JSC idioms.
What was reviewed:
RELEASE_AND_RETURNonscopeChain/evaluateWithScopeExtensionreturns andRETURN_IF_EXCEPTIONafterconstructEmptyArray/toIntegerOrInfinity/getOwnPropertyNames/putDirectIndex— all standard patterns matching surrounding code.toInspectorValue's newTopExceptionScopewithclearExceptionExceptTermination— callers already treatnullptras conversion failure, so swallowing here preserves the existing contract.queryInstanceslambda returnsIterationStatus::Doneon exception, then the outerRETURN_IF_EXCEPTIONafter 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.
`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>
Pausing in the debugger with
validateExceptionCheckson aborts the inspectee:InjectedScript::wrapCallFramesreadscallFrame.scopeChain, andJSJavaScriptCallFrame::scopeChain()ends in a barereturn constructArray(...)under aThrowScope. 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_RETURNaroundconstructArray.JSJavaScriptCallFrame::scopeDescriptions: check afterconstructEmptyArraybefore the firstputDirectIndex.JSJavaScriptCallFrame::evaluateWithScopeExtensionandJSInjectedScriptHost::evaluateWithScopeExtension:RELEASE_AND_RETURNon the result after the rethrow.JSInjectedScriptHost::weakMapEntries/weakSetEntries: check aftertoIntegerOrInfinityon the fetch count.The prototype-side host functions already
RELEASE_AND_RETURNinto these. Verified against oven-sh/bun'stest/cli/inspect/debugger-buntranspiledmodule.test.tsdriven with the flag forced on for the child once the preview build exists.