Repository navigation
Conversation
A DOMException wrapper keeps its name and message in the wrapped WebCore::DOMException and exposes them as prototype getters, so it has no own properties and the generic own-property walk in Bun__deepEquals called any two DOMExceptions equal. This affected Bun.deepEquals, expect().toEqual()/toStrictEqual(), assert.deepEqual/deepStrictEqual and util.isDeepStrictEqual. Compare the wrapped name and message plus the own non-enumerable cause when both sides are DOMExceptions (a DOMException never equals anything else), then fall through to the own-property walk for any properties added to the instances. The cause comparison is shared with the ErrorInstance case so the two stay in step.
|
Warning Review limit reached
Next review available in: 24 minutes Limit details: You’ve used all 5 included reviews currently available under your plan. Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
Comment |
|
Status: ready for review. Head is 219e771; CI build 99222 passed on it (179/179 jobs). Reproduced on bun 1.4.0 with Review so far: the mislabelled test row was dropped (48636e4); the comment-length findings were addressed (6e1a947, a952bcd); a test comment that misdescribed where |
There was a problem hiding this comment.
Beyond the inline nit, I also checked: the errorCausesEqual extraction is a byte-faithful lift of the existing ErrorInstanceType cause block (same hasProperty/get/recursive-compare sequence, same RETURN_IF_EXCEPTION placement); domExceptionsDequal has exception checks after its only fallible call and the dynamicDowncast/wrapped()/equalIgnoringNullity reads cannot throw; the swapped specialObjectsDequal(c2, c1) call at bindings.cpp:865 covers the DOMException-on-right-only case; and the c1Type == ObjectType gate means plain object literals (FinalObjectType) skip the new downcast entirely.
Extended reasoning...
Verified the refactor and new handler against the surrounding code in bindings.cpp: the lifted cause helper preserves the original control flow and exception-check ordering, the new DOMException handler follows the same nullopt-then-fall-through contract as temporalObjectsDequal and the URL/Headers cases, and placement inside the ObjectType block keeps it off the plain-object hot path. Not approving because Bun__deepEquals backs every toEqual/deepStrictEqual in the test runner, so a human should confirm the C++ change.
|
Updated 11:50 PM PT - Aug 15th, 2026
✅ @robobun, your commit 219e771d2f78a5444776d33de561526d3b300fb0 passed in 🧪 To try this PR locally: bunx bun-pr 39308That installs a local version of the PR into your bun-39308 --bun |
|
Addressed the review round in 48636e4, 6e1a947 and a952bcd:
No behaviour change beyond that; the three test files still fail on the unfixed binary and pass on the debug build. |
…t order specialObjectsDequal runs twice per pair (once with the arguments swapped), and domExceptionsDequal returned nullopt after recursing into the causes, so every level of a cause chain was compared twice and a chain of n DOMExceptions took 2^n comparisons. Call it once from Bun__deepEquals instead, after the special-object passes and before the own-property walk.
|
219e771 addresses the exponential cause-chain finding: |
There was a problem hiding this comment.
LGTM — the 2^n cause-chain issue from the previous round is resolved: domExceptionsDequal now runs once per Bun__deepEquals frame (outside specialObjectsDequal), and the new "reads each cause once per side" / "long chain of causes in linear time" / cycle tests pin that.
Checked: the errorCausesEqual extraction preserves the ErrorInstanceType path's behaviour (exception propagation via the caller's RETURN_IF_EXCEPTION, pinned by the new "deepEquals error causes" test); the ObjectType fast-path guard means plain FinalObjectType and array pairs skip the dynamicDowncast walks; mixed DOMException/Error and DOMException/plain-object pairs are rejected either by specialObjectsDequal's ErrorInstanceType case or by the new helper's own mixed-pair check; strict-mode subclass distinction still comes from calculatedClassName after the nullopt fall-through.
Extended reasoning...
Overview
Adds DOMException comparison to Bun__deepEquals in src/jsc/bindings/bindings.cpp: a new domExceptionsDequal helper compares the wrapped WebCore::DOMException name/message and the non-enumerable cause, then falls through to the existing own-property walk. The cause block from the ErrorInstanceType case is lifted into a shared errorCausesEqual helper. Tests are added across deep-equals.test.ts, expect.test.js, and the node deep-equal.test.ts matrix.
Since my previous review (the 🔴 2^n finding on the earlier revision), commit 219e771 moved the domExceptionsDequal call out of specialObjectsDequal into Bun__deepEquals directly, so it runs once per frame instead of once per argument order. Regression tests were added for read-count (2 per pair), a 64-deep cause chain, and a self-referential cause cycle.
Security risks
None identified. The comparison reads C++-owned WTF::String state via wrapped() without running user JS for name/message; cause is read via get() with proper RETURN_IF_EXCEPTION guards. No untrusted-size arithmetic, no allocation, no new GC-visible state.
Level of scrutiny
Moderate. Bun__deepEquals backs expect().toEqual(), assert.deepStrictEqual, and util.isDeepStrictEqual, so a regression would surface widely, but the change is additive (new special-object case) plus a mechanical extraction of existing code. I traced: the ObjectType-gate short-circuit keeps the hot path (two FinalObjectType objects, arrays) at two cheap type reads before returning nullopt; mixed pairs (DOMException vs Error, vs {}) are correctly rejected; the extracted errorCausesEqual preserves the original exception semantics because the caller re-checks RETURN_IF_EXCEPTION after the call; strict-mode subclass distinction is handled by the existing calculatedClassName check after fall-through.
Other factors
All earlier review threads (my mislabelled-test-row nit, the comment-cop length findings, my inaccurate-cause-comment nit, and the 🔴 2^n finding) have been addressed in 48636e4 / 6e1a947 / a952bcd / 9a48d91 / 219e771. The bug-hunting pass on the current head found nothing. Test coverage is thorough: both argument orders, both strict modes, subclass, structured clone, nested containers, asymmetric matchers, throwing cause getters, read-count, linear-time chain, and cycle termination — plus a Node-checked matrix and an Error-cause test that pins the lifted block. The PR description notes it was verified under BUN_JSC_validateExceptionChecks=1.
|
Closing this PR because it has been inactive for more than 90 days. |
Problem
Bun.deepEquals(new DOMException("boom", "AbortError"), new DOMException("other", "NotFoundError"))returnstrue. Node'sutil.isDeepStrictEqualreturnsfalse.expect().toEqual()/toStrictEqual()(also insideexpect.objectContaining/arrayContaining),assert.deepEqual,assert.deepStrictEqualandutil.isDeepStrictEqual, so all of them treat any two DOMExceptions as equal, including ones with differentcausevalues.assert.deepEqual(new DOMException("boom"), {})passes as well.WebCore::JSDOMExceptionwrapper (src/jsc/bindings/webcore/JSDOMException.h). Its name and message live in the wrappedWebCore::DOMExceptionand are exposed as getters on the prototype, and the constructor storescauseas a non-enumerable own property (JSDOMException.cpp,construct()). The instance therefore has no enumerable own properties.specialObjectsDequalinsrc/jsc/bindings/bindings.cpphas no case for it (itsErrorInstanceTypecase only matches realJSC::ErrorInstances, and a DOMException wrapper is a plainObjectType), so the comparison falls through to the generic own-property walk, which finds two empty objects.Fix
domExceptionsDequal(new): if exactly one side is a DOMException the values are not equal; if both are, the wrapped names and messages must match and thencauseis compared. On a match it returns nullopt so the existing own-property walk still compares any properties that were assigned onto the instances, exactly as the URL and Headers cases do.Bun__deepEquals, after the twospecialObjectsDequalpasses and before the own-property walk, rather than from insidespecialObjectsDequal: that function runs twice per pair (once per argument order), and since this comparison recurses intocauseand then returns nullopt, placing it there compared every level of a cause chain twice, so a chain of n DOMExceptions cost 2^n comparisons (16 levels took about 6 s on a debug build; a getter inside a cause ran 4 times instead of 2). The helper starts with aJSTypecheck, so pairs of ordinary objects (FinalObjectType) skip the class-chain walks.errorCausesEqual(new) is thecauseblock lifted out of theErrorInstanceTypecase unchanged and now used by both cases, so a DOMException's cause follows the same rules as an Error's (deep-compared in every mode; in strict modes a presentcause: undefinedalso differs from an absent one).Error.prototypein its chain (which includes DOMException) by name, message and cause, then own enumerable properties; Jest 30 does the same forinstanceof Errorvalues; Bun already applies these rules to Error via theErrorInstanceTypecase.codeis not compared separately becauseDOMException.cppderives it from the name. Names and messages are compared withequalIgnoringNullitybecause both getters present a null and an emptyWTF::Stringto JS as"".[[Get]], mirroring thesanitizedNameString/sanitizedMessageStringreads in the Error case: no user code runs for the name and message, and the result is the same for JS subclasses of DOMException, which share the wrapper class.test/js/bun/bun-object/deep-equals.test.ts(newDOMExceptionblock, run in bothBun.deepEqualsmodes, including a getter-read count, a 64-deep cause chain and a cause cycle),test/js/bun/test/expect.test.js(newDOMExceptiontests in the DOM types block, a getter-read count fortoEqual/toStrictEqual, plus an Error cause test that pins the behaviour of the lifted block),test/js/node/assert/deep-equal.test.ts(DOMException rows in the deepStrictEqual / deepEqual / isDeepStrictEqual matrix, askipPrototypecase and a getter-read count, expectations checked against node v26). The DOMException tests fail on the unfixed binary and pass with the fix.deep-equals-temporal,deep-match,jest-extended,test-test,expect-extend, thetest/js/node/assertsuite and the upstreamtest-assert-deep-with-error.js/test-util-isDeepStrictEqual.jsstill pass.BUN_JSC_validateExceptionChecks=1.assert.partialDeepStrictEqualhas its own comparison inNodeUtilTypesModule.cppwith the same blind spot (reported separately); DOMExceptions created internally (for exampleAbortSignal.abort().reason) additionally carry enumerable ownline/column/sourceURLproperties, so two of those created on different lines still compare unequal, as before. DOMException: inherit from ErrorInstance for [[ErrorData]] and .stack #32898 re-parentsJSDOMExceptionontoJSC::ErrorInstanceand changes itsJSType; once it lands, DOMExceptions will take theErrorInstanceTypecase instead, and this helper and itsJSTypecheck should be folded into that case.Background
Bun__deepEquals(bindings.cpp) is one template behind all of Bun's deep-equality entry points; the template parameters select strict vs loose, Jest asymmetric matchers, and node's prototype check. Before the generic own-property walk it callsspecialObjectsDequal(a, b)and thenspecialObjectsDequal(b, a); a case there returnstrue/falseto decide the comparison or nullopt to let the own-property walk decide.JSDOMWrapper<T>) is the JS object for a native WebCore object;wrapped()returns the native object. WebIDL attributes such asDOMException.prototype.nameare getters on the prototype that read from it, so wrapper instances normally have no own properties of their own.JSC::ErrorInstanceis the object class JSC uses for values created by the Error constructors; it is whatspecialObjectsDequal'sErrorInstanceTypecase compares. In Bun today a DOMException is not one, so it needs its own case.JSTypeis the one-byte type tag in every JSC cell header.JSDOMExceptionstructures are created with the plainObjectType; object literals and class instances areFinalObjectType, and most built-ins have their own tags, which is whatspecialObjectsDequalswitches on.Earlier shape of this PR (superseded)
The first revision called
domExceptionsDequalfrom theObjectTypeblock ofspecialObjectsDequal, next to the Temporal handling. Review pointed out that becausespecialObjectsDequalruns once per argument order and the helper recurses intocausebefore returning nullopt, a chain of n DOMException causes took 2^n comparisons. 219e771 moved the single call intoBun__deepEqualsand added the getter-count, chain and cycle tests; the comparison itself is unchanged.Probe used to compare against node (node v26.3.0 vs bun 1.4.0 vs this branch)
{}(loose)Errorwith the same messagecausecausecauseon one side onlyRemaining differences from node are pre-existing and not DOMException-specific: loose mode does not distinguish a present
cause: undefinedfrom an absent cause (same as for Error; recorded as alooseBugrow in the matrix), and internally created DOMExceptions carry enumerableline/columnown properties.