From 16df723e08c367e052742797c4373ca48089c629 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 24 Apr 2026 06:32:44 +0000 Subject: [PATCH] js-on-sx: numeric keys in object literals stringify on parse {0: 41, 1: 42} was raising 'dict-set!: dict key val' because the parser kept numeric keys as numbers in the entry dict, but SX dicts require string keys. Now we str-coerce number-type tokens during jp-parse-object-entry. Unblocks a huge chunk of test262 array-like-receiver tests that build {length: N, 0: v, 1: v, ...} literals. 3 new tests, 453/455 total. Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/js/parser.sx | 2 +- lib/js/test.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/js/parser.sx b/lib/js/parser.sx index 91e9f3c7..a3cc71ce 100644 --- a/lib/js/parser.sx +++ b/lib/js/parser.sx @@ -552,7 +552,7 @@ (do (jp-advance! st) (jp-expect! st "punct" ":") - (append! kvs {:value (jp-parse-assignment st) :key (get t :value)}))) + (append! kvs {:value (jp-parse-assignment st) :key (str (get t :value))}))) ((= (get t :type) "keyword") (do (jp-advance! st) diff --git a/lib/js/test.sh b/lib/js/test.sh index c33b666f..fb266335 100755 --- a/lib/js/test.sh +++ b/lib/js/test.sh @@ -1147,6 +1147,14 @@ cat > "$TMPFILE" << 'EPOCHS' (epoch 3301) (eval "(js-eval \"var o = {a:1, b:2}; delete o.a; o.b\")") +;; ── Phase 11.numkey: numeric object-literal keys ───────────── +(epoch 3350) +(eval "(js-eval \"var a = {0: 41, 1: 42, 2: 43}; a[0]\")") +(epoch 3351) +(eval "(js-eval \"var a = {length: 3, 0: 10, 1: 20, 2: 30}; a.length\")") +(epoch 3352) +(eval "(js-eval \"var a = {0: 'x'}; a['0']\")") + ;; ── Phase 11.fnmethod: Function.prototype.call/apply/bind ───── (epoch 3400) (eval "(js-eval \"function greet3(n) { return 'hi ' + n; } greet3.call(null, 'ada')\")") @@ -1784,6 +1792,11 @@ check 3201 "obj multi rename" '3' check 3300 "delete obj.x" 'true' check 3301 "delete obj.a keeps b" '2' +# ── Phase 11.numkey: numeric object-literal keys ───────────── +check 3350 "numeric key [0]" '41' +check 3351 "numkey with length" '3' +check 3352 "numeric key ['0']" '"x"' + # ── Phase 11.fnmethod: call/apply/bind ──────────────────────── check 3400 "fn.call basic" '"hi ada"' check 3401 "fn.apply basic" '"hi bob"'