js-on-sx: .toString()/.toFixed()/.valueOf() on numbers and booleans

js-invoke-method now branches on (number? recv) and (boolean? recv) before
falling through to the generic dict/fn path. js-invoke-number-method handles
toString (incl. radix 2-36), toFixed, valueOf, toLocaleString, toPrecision,
toExponential. js-invoke-boolean-method handles toString and valueOf.

Numbers had no .toString() on bare values before — (5).toString() crashed
with 'TypeError: toString is not a function'. This is one of the bigger
scoreboard misses on built-ins/Number category.

10 new unit tests, 469/471 total.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 06:51:58 +00:00
parent 00bb21ca13
commit baa5cd9341
2 changed files with 202 additions and 54 deletions

View File

@@ -1169,6 +1169,28 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 3405)
(eval "(js-eval \"var arr2 = [1,2]; Array.prototype.push.call(arr2, 10, 20); arr2.length\")")
;; ── Phase 11.nummethod: .toString(), .toFixed() on numbers ───
(epoch 3600)
(eval "(js-eval \"(5).toString()\")")
(epoch 3601)
(eval "(js-eval \"(16).toString(16)\")")
(epoch 3602)
(eval "(js-eval \"(10).toString(2)\")")
(epoch 3603)
(eval "(js-eval \"(3.14).toFixed(1)\")")
(epoch 3604)
(eval "(js-eval \"(3.14).toFixed(2)\")")
(epoch 3605)
(eval "(js-eval \"(0).toFixed(3)\")")
(epoch 3606)
(eval "(js-eval \"(7).valueOf()\")")
(epoch 3607)
(eval "(js-eval \"true.toString()\")")
(epoch 3608)
(eval "(js-eval \"false.toString()\")")
(epoch 3609)
(eval "(js-eval \"(true).valueOf()\")")
;; ── Phase 11.arrlike: Array.prototype.* on {length, 0:..., 1:...} ──
(epoch 3500)
(eval "(js-eval \"var a = {length: 3, 0: 41, 1: 42, 2: 43}; Array.prototype.slice.call(a).length\")")
@@ -1819,6 +1841,18 @@ check 3403 "fn.call this-binding" '42'
check 3404 "fn.apply arg-unpack" '7'
check 3405 "Array.prototype.push.call arr" '4'
# ── Phase 11.nummethod: number/boolean methods ────────────────
check 3600 "(5).toString()" '"5"'
check 3601 "(16).toString(16)" '"10"'
check 3602 "(10).toString(2)" '"1010"'
check 3603 "(3.14).toFixed(1)" '"3.1"'
check 3604 "(3.14).toFixed(2)" '"3.14"'
check 3605 "(0).toFixed(3)" '"0.000"'
check 3606 "(7).valueOf()" '7'
check 3607 "true.toString()" '"true"'
check 3608 "false.toString()" '"false"'
check 3609 "(true).valueOf()" 'true'
# ── Phase 11.arrlike: array-like receivers on Array.prototype ─
check 3500 "slice.call arrLike length" '3'
check 3501 "slice.call arrLike join" '"41,42,43"'