From d51ae65bbbc6bcfbf1e241b955de15145590e2ce Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 8 May 2026 12:07:55 +0000 Subject: [PATCH] js-on-sx: fn.toString honours Function.prototype.toString overrides MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two hardcoded paths returned the native marker regardless of user override: js-invoke-function-method and the lambda branch of js-to-string. Both now look up Function.prototype.toString via js-dict-get-walk and invoke it on the function, falling back to the native marker only if no override exists. built-ins/String: 84/99 → 85/99. conformance.sh: 148/148. --- lib/js/runtime.sx | 21 +++++++++++++++++++-- lib/js/test262-scoreboard.json | 18 +++++++++--------- lib/js/test262-scoreboard.md | 12 ++++++------ plans/js-on-sx.md | 2 ++ 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index adaa56e1..e3059754 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -306,7 +306,13 @@ (fn (&rest more) (js-call-with-this this-arg recv (js-list-concat bound more))))) - ((= key "toString") "function () { [native code] }") + ((= key "toString") + (let + ((override (js-dict-get-walk (get js-function-global "prototype") "toString"))) + (if + (= (type-of override) "lambda") + (js-call-with-this recv override args) + "function () { [native code] }"))) ((= key "name") (js-extract-fn-name recv)) ((= key "length") (js-fn-length recv)) (else :js-undefined)))) @@ -1393,7 +1399,18 @@ "[object Object]")) (js-to-string result))) "[object Object]")))) - (if (= (type-of v) "list") (js-list-join v ",") (str v))))))) + (cond + ((= (type-of v) "list") (js-list-join v ",")) + ((js-function? v) + (let + ((tostr-fn (js-dict-get-walk (get js-function-global "prototype") "toString"))) + (if + (= (type-of tostr-fn) "lambda") + (let + ((result (js-call-with-this v tostr-fn ()))) + (if (= (type-of result) "string") result "function () { [native code] }")) + "function () { [native code] }"))) + (else (str v)))))))) (define js-template-concat diff --git a/lib/js/test262-scoreboard.json b/lib/js/test262-scoreboard.json index 6d2404ff..c4378dd5 100644 --- a/lib/js/test262-scoreboard.json +++ b/lib/js/test262-scoreboard.json @@ -1,26 +1,26 @@ { "totals": { - "pass": 84, - "fail": 12, + "pass": 85, + "fail": 11, "skip": 1, "timeout": 3, "total": 100, "runnable": 99, - "pass_rate": 84.8 + "pass_rate": 85.9 }, "categories": [ { "category": "built-ins/String", "total": 100, - "pass": 84, - "fail": 12, + "pass": 85, + "fail": 11, "skip": 1, "timeout": 3, - "pass_rate": 84.8, + "pass_rate": 85.9, "top_failures": [ [ "Test262Error (assertion failed)", - 10 + 9 ], [ "Timeout", @@ -40,7 +40,7 @@ "top_failure_modes": [ [ "Test262Error (assertion failed)", - 10 + 9 ], [ "Timeout", @@ -56,6 +56,6 @@ ] ], "pinned_commit": "d5e73fc8d2c663554fb72e2380a8c2bc1a318a33", - "elapsed_seconds": 192.4, + "elapsed_seconds": 182.4, "workers": 1 } \ No newline at end of file diff --git a/lib/js/test262-scoreboard.md b/lib/js/test262-scoreboard.md index b832b42e..655b86e0 100644 --- a/lib/js/test262-scoreboard.md +++ b/lib/js/test262-scoreboard.md @@ -1,13 +1,13 @@ # test262 scoreboard Pinned commit: `d5e73fc8d2c663554fb72e2380a8c2bc1a318a33` -Wall time: 192.4s +Wall time: 182.4s -**Total:** 84/99 runnable passed (84.8%). Raw: pass=84 fail=12 skip=1 timeout=3 total=100. +**Total:** 85/99 runnable passed (85.9%). Raw: pass=85 fail=11 skip=1 timeout=3 total=100. ## Top failure modes -- **10x** Test262Error (assertion failed) +- **9x** Test262Error (assertion failed) - **3x** Timeout - **1x** ReferenceError (undefined symbol) - **1x** SyntaxError (parse/unsupported syntax) @@ -16,13 +16,13 @@ Wall time: 192.4s | Category | Pass | Fail | Skip | Timeout | Total | Pass % | |---|---:|---:|---:|---:|---:|---:| -| built-ins/String | 84 | 12 | 1 | 3 | 100 | 84.8% | +| built-ins/String | 85 | 11 | 1 | 3 | 100 | 85.9% | ## Per-category top failures (min 10 runnable, worst first) -### built-ins/String (84/99 — 84.8%) +### built-ins/String (85/99 — 85.9%) -- **10x** Test262Error (assertion failed) +- **9x** Test262Error (assertion failed) - **3x** Timeout - **1x** ReferenceError (undefined symbol) - **1x** SyntaxError (parse/unsupported syntax) diff --git a/plans/js-on-sx.md b/plans/js-on-sx.md index 245859eb..7d8e8d85 100644 --- a/plans/js-on-sx.md +++ b/plans/js-on-sx.md @@ -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-08 — **`fn.toString()` and `String(fn)` honour `Function.prototype.toString` overrides.** Two hardcoded paths returned `"function () { [native code] }"` regardless of any user override: the function-method dispatch in `js-invoke-function-method`, and the lambda branch of `js-to-string`. Both now look up `Function.prototype.toString` via `js-dict-get-walk` and invoke it on the function (`recv`/`v`) when available, falling back to the native marker only if no override exists. Now `Function.prototype.toString = ...; (function(){}).toString()` returns the override, and `new String(fn)` stores the override result. built-ins/String: 84/99 → 85/99. conformance.sh: 148/148. + - 2026-05-08 — **Native prototypes carry the wrapped primitive marker.** Per ES, `Boolean.prototype` is a Boolean wrapper around `false`, `Number.prototype` wraps `0`, `String.prototype` wraps `""`. So `Boolean.prototype == false` (loose-eq unwraps), `Object.prototype.toString.call(Number.prototype) === "[object Number]"`, etc. Set `__js_boolean_value__: false` / `__js_number_value__: 0` / `__js_string_value__: ""` on the respective prototypes in the post-init block. built-ins/Boolean: 23/27 → 24/27, String: 80/99 → 84/99. conformance.sh: 148/148. - 2026-05-08 — **`js-to-number` throws TypeError when valueOf+toString both return non-primitive.** Mirrors the earlier `js-to-string` fix. Per spec, `Number(obj)` must throw if `ToPrimitive` cannot extract a primitive. Was returning `NaN` silently. Replaced the inner `(js-nan-value)` fallback with `(raise (js-new-call TypeError ...))`. built-ins/Number: 45/50 → 46/50. conformance.sh: 148/148.