js-on-sx: callable Number/String/Boolean/Array + Array.sort

Builtin constructors now have :__callable__ slot. js-call-plain
and js-function? detect dicts with __callable__ and dispatch
through it. Number('42')===42, String(true)==='true', Boolean(0)
===false, Array(3) builds length-3 list.

Array.prototype.sort(comparator?): bubble sort via js-list-sort-
outer!/-inner!. Default lex order, custom comparator supported.

Wide scoreboard committed: 259/5354 (4.8%) from earlier runtime.

438/440 unit (+11), 148/148 slice unchanged.
This commit is contained in:
2026-04-23 22:53:13 +00:00
parent d6975d3c79
commit 1459f7a637
5 changed files with 501 additions and 5 deletions

View File

@@ -1103,6 +1103,32 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 2803)
(eval "(js-eval \"var q=42; q??=99; q\")")
;; ── Phase 11.callable: Number()/String()/Boolean()/Array() ─────
(epoch 2900)
(eval "(js-eval \"Number('42')\")")
(epoch 2901)
(eval "(js-eval \"String(123)\")")
(epoch 2902)
(eval "(js-eval \"String(true)\")")
(epoch 2903)
(eval "(js-eval \"Boolean(0)\")")
(epoch 2904)
(eval "(js-eval \"Boolean('hi')\")")
(epoch 2905)
(eval "(js-eval \"Array(3).length\")")
(epoch 2906)
(eval "(js-eval \"Array(1,2,3).length\")")
;; ── Phase 11.sort: Array.prototype.sort ──────────────────────
(epoch 3000)
(eval "(js-eval \"[3,1,2].sort().join(',')\")")
(epoch 3001)
(eval "(js-eval \"[10,5,20].sort().join(',')\")")
(epoch 3002)
(eval "(js-eval \"[3,1,2].sort((a,b)=>a-b).join(',')\")")
(epoch 3003)
(eval "(js-eval \"[3,1,2].sort((a,b)=>b-a).join(',')\")")
EPOCHS
@@ -1699,6 +1725,21 @@ check 2801 "&&= truthy" '7'
check 2802 "??= null" '99'
check 2803 "??= has value" '42'
# ── Phase 11.callable ─────────────────────────────────────────
check 2900 "Number('42')" '42'
check 2901 "String(123)" '"123"'
check 2902 "String(true)" '"true"'
check 2903 "Boolean(0)" 'false'
check 2904 "Boolean('hi')" 'true'
check 2905 "Array(3).length" '3'
check 2906 "Array(1,2,3).length" '3'
# ── Phase 11.sort ────────────────────────────────────────────
check 3000 "sort default" '"1,2,3"'
check 3001 "sort lex (10<5)" '"10,20,5"'
check 3002 "sort numeric" '"1,2,3"'
check 3003 "sort reverse" '"3,2,1"'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "$PASS/$TOTAL JS-on-SX tests passed"