Skip to content

test262: Function conformance fixes (wave 13) - #70

Merged
hiett merged 1 commit into
experiment/js-frontendfrom
js262/wave13-Function
Jul 15, 2026
Merged

test262: Function conformance fixes (wave 13)#70
hiett merged 1 commit into
experiment/js-frontendfrom
js262/wave13-Function

Conversation

@hiett

@hiett hiett commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Implements Function.prototype.bind (ES2024 §20.2.3.2) for the reachable subset.

What

  • New runtime func_bind/2 returns a partially-applied function: it prepends the saved bound arguments to each call's own arguments and applies the target. Bound closure arity = target length − #bound args (floored at 0, per SetFunctionLength), so remaining call args forward correctly; extra trailing args are dropped by the same arity-fitting call/apply already use.
  • Routed x.bind(...) in lower.gleam beside call/apply (func_bind op); a non-function receiver delegates to a same-named user bind method.

Deviations (documented, gated on absent function-object model)

  • thisArg is dropped — plain functions carry no receiver in this model (same as call/apply).
  • The bound function does not carry the target's length/name/prototype; property-bearing function objects are out of scope for v1.

Impact

test/built-ins/Function/prototype: pass 17 → 30 (+13), runtime_error 36 → 21. No pass regressions. New spec-driven tests appended to js_compiler_test.gleam.

Out of scope (honest): the bulk of the remaining Function/prototype failures are gated on a full function-object model (.length/.name/prototype/caller/arguments poisoning), real this-binding, Object.defineProperty, the arguments object, [[Construct]] on bound functions, and the Function constructor / eval (permanent AOT boundary).

Implement Function.prototype.bind (ES2024 §20.2.3.2) for the reachable
subset: return a new function that prepends the saved bound arguments to
its own call arguments and applies the target. As with call/apply, the
thisArg is dropped (a plain function carries no receiver in this model)
and the bound function does not carry the target's own length/name/
prototype properties, which would need a full function-object model. The
bound closure's arity is the target length minus the number of bound
arguments (floored at 0, per SetFunctionLength) so remaining call
arguments forward correctly.

Raises test/built-ins/Function/prototype from 17 to 30 passing.
@hiett
hiett merged commit fa53997 into experiment/js-frontend Jul 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant