You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
runtime: honor flat depth in dynamic Array.prototype.flat dispatch #2800
Perry has a depth-aware Array.prototype.flat(depth) lowering path, but the dynamic runtime method-dispatch branch ignores the supplied depth argument and always calls the legacy depth-1 helper. Calls that reach dynamic dispatch, such as anyArray.flat(0), anyArray.flat(2), or anyArray.flat(Infinity), should preserve Node's depth coercion semantics.
The top-level result array accounts for the final residual depth of 1 in the fully flattened cases.
Current Perry behavior in source
The static/codegen path is depth-aware:
crates/perry-codegen/src/lower_array_method.rs:198-218 sends zero-arg flat() to js_array_flat, but sends calls with an argument to js_array_flat_depth(recv, depth).
crates/perry-runtime/src/array/flat_clone.rs:31-47 converts NaN / non-positive depth to 0, finite positive depth to an integer depth, and Infinity to u32::MAX.
But dynamic method dispatch ignores the argument:
crates/perry-runtime/src/object/native_call_method.rs:1243-1246 handles "flat" by calling crate::array::js_array_flat(arr) unconditionally and never reads args_ptr / args_len.
So any call that falls through to dynamic method dispatch gets depth 1 regardless of whether the JS call supplied 0, 2, Infinity, or another value.
Expected fix shape
The dynamic flat branch should mirror the static path:
Omitted depth: call js_array_flat or js_array_flat_depth(arr, 1).
Supplied depth: pass the first argument to js_array_flat_depth after normal JS number coercion.
Preserve Node behavior for 0, negative values, NaN, finite positive depths, and Infinity.
Please add regression coverage for dynamically dispatched flat(0), flat(2), flat(Infinity), and the zero-argument default.
Activity
fix(array): honor fromIndex/start/end/depth in indexOf/fill/flat/copy…