From c8f9b8be06446c1e6fadcc846d57abb3842f6416 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 8 May 2026 00:28:36 +0000 Subject: [PATCH] js-on-sx: arrays accept numeric-string property keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JS arrays must treat string indices that look like numbers ("0", "42") as the corresponding integer slot. js-get-prop and js-list-set! only handled numeric key, falling through to undefined / no-op for string keys. Added a (and (string-typed key) (numeric? key)) clause that converts via js-string-to-number and recurses with the integer key. built-ins/Array: 13/45 → 14/45. conformance.sh: 148/148. --- lib/js/runtime.sx | 9 ++++++ lib/js/test262-scoreboard.json | 54 +++++++++++++++++++--------------- lib/js/test262-scoreboard.md | 26 ++++++++-------- plans/js-on-sx.md | 2 ++ 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index 927d574d..97ed2235 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -2639,6 +2639,13 @@ (and (>= key 0) (< key (len obj))) (nth obj (js-num-to-int key)) js-undefined)) + ((and (= (type-of key) "string") (js-is-numeric-string? key)) + (let + ((idx (js-num-to-int (js-string-to-number key)))) + (if + (and (>= idx 0) (< idx (len obj))) + (nth obj idx) + js-undefined))) ((= key "push") (js-array-method obj "push")) ((= key "pop") (js-array-method obj "pop")) ((= key "shift") (js-array-method obj "shift")) @@ -2791,6 +2798,8 @@ ((< i n) (set-nth! lst i val)) ((= i n) (append! lst val)) (else (do (js-pad-list! lst n i) (append! lst val)))))) + ((and (= (type-of key) "string") (js-is-numeric-string? key)) + (js-list-set! lst (js-string-to-number key) val)) ((= key "length") nil) (else nil)))) (define diff --git a/lib/js/test262-scoreboard.json b/lib/js/test262-scoreboard.json index c4177b33..6ed6dba6 100644 --- a/lib/js/test262-scoreboard.json +++ b/lib/js/test262-scoreboard.json @@ -1,37 +1,41 @@ { "totals": { - "pass": 77, - "fail": 15, - "skip": 1, - "timeout": 7, - "total": 100, - "runnable": 99, - "pass_rate": 77.8 + "pass": 14, + "fail": 25, + "skip": 5, + "timeout": 6, + "total": 50, + "runnable": 45, + "pass_rate": 31.1 }, "categories": [ { - "category": "built-ins/String", - "total": 100, - "pass": 77, - "fail": 15, - "skip": 1, - "timeout": 7, - "pass_rate": 77.8, + "category": "built-ins/Array", + "total": 50, + "pass": 14, + "fail": 25, + "skip": 5, + "timeout": 6, + "pass_rate": 31.1, "top_failures": [ [ "Test262Error (assertion failed)", - 13 + 20 ], [ "Timeout", - 7 + 6 + ], + [ + "TypeError: not a function", + 2 ], [ "ReferenceError (undefined symbol)", - 1 + 2 ], [ - "SyntaxError (parse/unsupported syntax)", + "Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\\", 1 ] ] @@ -40,22 +44,26 @@ "top_failure_modes": [ [ "Test262Error (assertion failed)", - 13 + 20 ], [ "Timeout", - 7 + 6 + ], + [ + "TypeError: not a function", + 2 ], [ "ReferenceError (undefined symbol)", - 1 + 2 ], [ - "SyntaxError (parse/unsupported syntax)", + "Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\\", 1 ] ], "pinned_commit": "d5e73fc8d2c663554fb72e2380a8c2bc1a318a33", - "elapsed_seconds": 486.8, + "elapsed_seconds": 132.0, "workers": 1 } \ No newline at end of file diff --git a/lib/js/test262-scoreboard.md b/lib/js/test262-scoreboard.md index 4f86e370..82017c8a 100644 --- a/lib/js/test262-scoreboard.md +++ b/lib/js/test262-scoreboard.md @@ -1,28 +1,30 @@ # test262 scoreboard Pinned commit: `d5e73fc8d2c663554fb72e2380a8c2bc1a318a33` -Wall time: 486.8s +Wall time: 132.0s -**Total:** 77/99 runnable passed (77.8%). Raw: pass=77 fail=15 skip=1 timeout=7 total=100. +**Total:** 14/45 runnable passed (31.1%). Raw: pass=14 fail=25 skip=5 timeout=6 total=50. ## Top failure modes -- **13x** Test262Error (assertion failed) -- **7x** Timeout -- **1x** ReferenceError (undefined symbol) -- **1x** SyntaxError (parse/unsupported syntax) +- **20x** Test262Error (assertion failed) +- **6x** Timeout +- **2x** TypeError: not a function +- **2x** ReferenceError (undefined symbol) +- **1x** Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\ ## Categories (worst pass-rate first, min 10 runnable) | Category | Pass | Fail | Skip | Timeout | Total | Pass % | |---|---:|---:|---:|---:|---:|---:| -| built-ins/String | 77 | 15 | 1 | 7 | 100 | 77.8% | +| built-ins/Array | 14 | 25 | 5 | 6 | 50 | 31.1% | ## Per-category top failures (min 10 runnable, worst first) -### built-ins/String (77/99 — 77.8%) +### built-ins/Array (14/45 — 31.1%) -- **13x** Test262Error (assertion failed) -- **7x** Timeout -- **1x** ReferenceError (undefined symbol) -- **1x** SyntaxError (parse/unsupported syntax) +- **20x** Test262Error (assertion failed) +- **6x** Timeout +- **2x** TypeError: not a function +- **2x** ReferenceError (undefined symbol) +- **1x** Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\ diff --git a/plans/js-on-sx.md b/plans/js-on-sx.md index 636109d1..f00188c6 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 — **Arrays accept numeric-string property keys (`arr["0"]`).** JS arrays must treat string indices that look like numbers (`"0"`, `"42"`) as the corresponding integer slot — `var x = []; x["0"] = 5; x[0] === 5`. `js-get-prop` and `js-list-set!` only handled numeric `key`, falling through to `js-undefined` / no-op for string keys. Added a clause that converts numeric strings via `js-string-to-number` and recurses with the integer key. built-ins/Array: 13/45 → 14/45. conformance.sh: 148/148. + - 2026-05-07 — **JS top-level `var` no longer pollutes SX global env; call args use `js-args` to avoid `list` shadow.** `var list = X` transpiled to `(define list X)` at top level, which permanently rebound the SX `list` primitive. Then any later code (including the runtime itself) calling `(list ...)` got "Not callable: ". Two-part fix: (1) wrap the whole transpiled program in `(let () ...)` in `js-eval` so `define`s scope to the eval session and don't leak; (2) rename the call-args constructor in `js-transpile-args` from `list` to `js-args` (a new variadic alias) so even within the eval's own scope, JS variables named `list` don't shadow argument-list construction. Array-literal transpile keeps `list` (lists must be mutable). built-ins/Object: 41/50 → 42/50; Array.from on array-likes now works. conformance.sh: 148/148. - 2026-05-07 — **`Object.__callable__` returns `this` for `new Object()` no-args path.** `js-new-call Object` had `obj.__proto__ = Object.prototype` already set, but then Object.__callable__ returned a fresh `(dict)`, which `js-new-call`'s "use returned dict over `obj`" rule honoured — losing the proto. Added a `is-new` check (`this.__proto__ === Object.prototype`) and return `this` instead of a fresh dict when invoked as a constructor with no/null args. Now `new Object().__proto__ === Object.prototype`, `Object.prototype.isPrototypeOf(new Object())`, and `.constructor === Object` all work. built-ins/Object: 37/50 → 41/50. conformance.sh: 148/148.