fix(runtime): WeakMap/WeakSet method VALUE reads resolve the prototype thunk - #6225
Merged
Conversation
…e thunk A value read of a WeakMap/WeakSet method (`w.add`, `wm.set`, `typeof w.has`) returned undefined: method CALLS dispatch via js_native_call_method's weak arms, but the by-name read path had no equivalent, so `const f = w.add` / `w.add.bind(w, k)` yielded undefined and the subsequent bind/call threw "Bind must be called on a function". react-server-dom's chunk-preload dedup does `u.add.bind(u, chunk)` on a module-level WeakSet, 500'ing every Next.js App Router dynamic route. Detect a WeakMap/WeakSet receiver in js_object_get_field_by_name (via the GC-header-safe weak_class_id_from_receiver) and return the brand-checking prototype thunk for a known method name with no own-key shadow — mirroring the Map/Set value-read path. Adds test_gap_weak_method_value_read.ts, byte-for-byte against node.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughWeakMap and WeakSet field lookup now returns callable prototype methods for recognized method names when no own property shadows them. A regression test covers bound calls, method-value calls, direct calls, function characteristics, and own-property precedence. ChangesWeak collection method values
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Problem
A value read of a
WeakMap/WeakSetmethod (w.add,wm.set,typeof w.has) returnedundefined. Method calls (w.add(k)) dispatchthrough
js_native_call_method's weak arms, but the by-name property-read path(
js_object_get_field_by_name) had no equivalent, so a bare read yieldedundefinedand any subsequent call or.bindthrew:react-server-dom's client-chunk preload dedup does exactly
u.add.bind(u, chunk)on a module-levelWeakSet, so every Next.js App Routerdynamic route 500'd during flight resolution (#5989).
Fix
In
js_object_get_field_by_name, detect aWeakMap/WeakSetreceiver (via theexisting GC-header-safe
weak_class_id_from_receiver, already guarded againstthe small-handle band) and, for a known method name with no own-key shadow,
return the brand-checking prototype thunk from
collection_proto_method_value— the same thunkMap/Setvalue reads alreadyresolve. Own keys keep precedence (a fresh instance only carries the internal
__perry_wk_entriessentinel, which is not a method name).Validation
New gap test
test_gap_weak_method_value_read.ts, byte-for-byte againstnode --experimental-strip-types:typeofreads,.bind(...)+ call,stored-method
.call(...),WeakMap.set/getround-trip, the bound value beinga real function (
.bind/.callpresent), a method-call regression guard, andown-key precedence over a shadowed method name.
Summary by CodeRabbit
WeakMapandWeakSetinstances so methods such asget,set,has,delete, andaddreturn callable functions as expected.