Repository navigation
fix(runtime): dispatch user-assigned callable methods on exotic (RegExp/Date/Error) receivers #6004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1546,6 +1546,31 @@ pub unsafe extern "C" fn js_native_call_method( | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Exotic receivers (RegExp / Date / Error) with a user-assigned own | ||||||||||||||||||||||||||||||||||||||
| // property that is a callable: `var r = /x/; r.f = function(){...}; r.f()` | ||||||||||||||||||||||||||||||||||||||
| // and `String.prototype.toLowerCase.call`-style borrows like | ||||||||||||||||||||||||||||||||||||||
| // `reg.toLowerCase = String.prototype.toLowerCase; reg.toLowerCase()` | ||||||||||||||||||||||||||||||||||||||
| // (test262 String/prototype/{toLowerCase,toUpperCase,...}/*_A1_T14). These | ||||||||||||||||||||||||||||||||||||||
| // objects store dynamic props in the exotic-expando side table, not the | ||||||||||||||||||||||||||||||||||||||
| // ObjectHeader field map, so the field/vtable/prototype dispatch above | ||||||||||||||||||||||||||||||||||||||
| // never sees them. Look the name up there; if it is a callable, invoke it | ||||||||||||||||||||||||||||||||||||||
| // with the receiver bound as `this` (via IMPLICIT_THIS, matching the | ||||||||||||||||||||||||||||||||||||||
| // closure-field dispatch path above). | ||||||||||||||||||||||||||||||||||||||
| if jsval.is_pointer() { | ||||||||||||||||||||||||||||||||||||||
| if let Some((addr, kind)) = super::exotic_expando::exotic_expando_kind_of_value(object) { | ||||||||||||||||||||||||||||||||||||||
| if let Some(bits) = super::exotic_expando::value_lookup(kind, addr, method_name) { | ||||||||||||||||||||||||||||||||||||||
| let candidate = f64::from_bits(bits); | ||||||||||||||||||||||||||||||||||||||
| if crate::collection_iter::is_callable(candidate) { | ||||||||||||||||||||||||||||||||||||||
| let prev_this = IMPLICIT_THIS.with(|c| c.replace(object.to_bits())); | ||||||||||||||||||||||||||||||||||||||
| let result = | ||||||||||||||||||||||||||||||||||||||
| crate::closure::js_native_call_value(candidate, args_ptr, args_len); | ||||||||||||||||||||||||||||||||||||||
| IMPLICIT_THIS.with(|c| c.set(prev_this)); | ||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1562
to
+1568
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Use an exact callable check before returning.
Proposed direction let candidate = f64::from_bits(bits);
- if crate::collection_iter::is_callable(candidate) {
+ let raw = (crate::value::js_nanbox_get_pointer(candidate) & !0x7) as usize;
+ let callable = (crate::value::addr_class::is_above_handle_band(raw)
+ && crate::closure::is_closure_ptr(raw))
+ || crate::proxy::js_proxy_is_proxy(candidate) == 1;
+ if callable {
let prev_this = IMPLICIT_THIS.with(|c| c.replace(object.to_bits()));
let result =
crate::closure::js_native_call_value(candidate, args_ptr, args_len);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| crate::object::class_registry::report_dispatch_miss( | ||||||||||||||||||||||||||||||||||||||
| "call-method (no method/field/proto match)", | ||||||||||||||||||||||||||||||||||||||
| object, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Don’t gate the expando lookup on
jsval.is_pointer().Line 1559 makes the helper’s raw-I64 branch unreachable here, so any exotic receiver encoded that way still falls through to
TypeErrordespiteexotic_expando_kind_of_valueexplicitly supporting it.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents