js-on-sx: Function.prototype call/apply/bind/toString delegate to real impl
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

This commit is contained in:
2026-05-09 12:36:48 +00:00
parent adc4cb89c6
commit cd014cdb29
2 changed files with 3 additions and 1 deletions

View File

@@ -23,7 +23,7 @@
;; ── Boolean coercion (ToBoolean) ──────────────────────────────────
(define js-function-global {:__callable__ (fn (&rest args) (js-function-ctor args)) :prototype {:call (fn (&rest args) :js-undefined) :length 0 :bind (fn (&rest args) (fn () :js-undefined)) :toString (fn () "function () { [native code] }") :apply (fn (&rest args) :js-undefined) :name ""}})
(define js-function-global {:__callable__ (fn (&rest args) (js-function-ctor args)) :prototype {:call (fn (&rest args) (js-invoke-function-method (js-this) "call" args)) :length 0 :bind (fn (&rest args) (js-invoke-function-method (js-this) "bind" args)) :toString (fn () (js-invoke-function-method (js-this) "toString" (list))) :apply (fn (&rest args) (js-invoke-function-method (js-this) "apply" args)) :name ""}})
(define
js-function-ctor

View File

@@ -158,6 +158,8 @@ Each item: implement → tests → update progress. Mark `[x]` when tests green.
Append-only record of completed iterations. Loop writes one line per iteration: date, what was done, test count delta.
- 2026-05-09 — **`Function.prototype.{call, apply, bind, toString}` delegate to the real implementation when invoked through the proto chain.** Was: stub functions returning `:js-undefined` / a no-op closure. So `Number.bind(null)` resolved through `Number.__proto__ === Function.prototype` to the stub bind, which returned `(fn () :js-undefined)` instead of an actual bound function. Replaced each stub with `(fn (&rest args) (js-invoke-function-method (js-this) "<name>" args))`, so the prototype methods route to the same implementation that `js-invoke-method` uses when calling on a lambda directly. Now `Number.bind(null)(42) === 42`. Result: built-ins/Function/prototype/bind 9/30 → 14/30, call 12/30 → 17/30, apply 16/30 → 18/30. Object 30/30 holds. conformance.sh: 148/148.
- 2026-05-09 — **Functions inherit through their `__proto__` chain in `js-dict-get-walk`; `fn.prototype = X` actually persists.** Two related fixes around the function-as-object semantics: (1) `js-dict-get-walk` was returning undefined the moment it hit any non-dict in the proto chain — but the chain often runs through a function (e.g. `obj.__proto__ === proto` where `proto` is itself a function returned by `Function()`). Now treats lambda/function/component as if they have `__proto__ === Function.prototype` and continues the walk. (2) `js-set-prop` was a no-op when called on a function with key `"prototype"` (returned val without storing) — so `FACTORY.prototype = proto` silently dropped on the floor. Now redirects to `__js_proto_table__` so the next `new FACTORY` picks up the right proto. Result: built-ins/Function/prototype/call 7/30 → 12/30, apply 12/30 → 16/30. Object 30/30, Map 18/30, Array 18/30 unchanged. conformance.sh: 148/148.
- 2026-05-09 — **`Function.prototype.call` / `apply` substitute global as `this` when caller passes null/undefined.** Per non-strict ES, `f.apply(null)` and `f.call(undefined)` should bind `this` to the global object inside `f`. We were passing `null`/`undefined` straight through to `js-call-with-this`, so `this.field = "green"` (the test pattern) silently failed because the function's `this` was still undefined and `this.field` did nothing. Updated both clauses in `js-invoke-function-method` to swap in `js-global-this` when the caller's `this`-arg is null or `:js-undefined`. Result: built-ins/Function/prototype 4/30 → 11/30 (+7), apply 0+ → 12/30, call 0+ → 7/30. Object 30/30 holds. conformance.sh: 148/148.