js-on-sx: String.fromCharCode + parseInt + parseFloat
String global with fromCharCode (variadic). parseInt truncates via js-math-trunc; parseFloat delegates to js-to-number. Wired into js-global. 381/383 unit (+5), 148/148 slice unchanged.
This commit is contained in:
@@ -1608,6 +1608,34 @@
|
||||
|
||||
(define Array {:isArray js-array-is-array :of js-array-of})
|
||||
|
||||
(define
|
||||
js-string-from-char-code
|
||||
(fn (&rest args) (js-string-from-char-code-loop args 0 "")))
|
||||
|
||||
(define
|
||||
js-string-from-char-code-loop
|
||||
(fn
|
||||
(args i acc)
|
||||
(if
|
||||
(>= i (len args))
|
||||
acc
|
||||
(js-string-from-char-code-loop
|
||||
args
|
||||
(+ i 1)
|
||||
(str acc (js-code-to-char (js-num-to-int (nth args i))))))))
|
||||
|
||||
(define String {:fromCharCode js-string-from-char-code})
|
||||
|
||||
(define
|
||||
parseInt
|
||||
(fn
|
||||
(&rest args)
|
||||
(if (= (len args) 0) 0 (js-math-trunc (js-to-number (nth args 0))))))
|
||||
|
||||
(define
|
||||
parseFloat
|
||||
(fn (&rest args) (if (= (len args) 0) 0 (js-to-number (nth args 0)))))
|
||||
|
||||
(define
|
||||
js-promise-flush-callbacks!
|
||||
(fn
|
||||
@@ -2022,4 +2050,4 @@
|
||||
(str "/" (get rx "source") "/" (get rx "flags")))
|
||||
(else js-undefined))))
|
||||
|
||||
(define js-global {:isFinite js-global-is-finite :console console :Number Number :Math Math :Array Array :NaN 0 :Infinity inf :isNaN js-global-is-nan :Object Object :undefined js-undefined})
|
||||
(define js-global {:isFinite js-global-is-finite :console console :Number Number :Math Math :Array Array :String String :NaN 0 :Infinity inf :isNaN js-global-is-nan :Object Object :undefined js-undefined})
|
||||
|
||||
@@ -981,8 +981,21 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1803)
|
||||
(eval "(js-eval \"({x:1}).valueOf().x\")")
|
||||
|
||||
;; ── Phase 11.fromCharCode: String/parseInt/parseFloat ──────────
|
||||
(epoch 1900)
|
||||
(eval "(js-eval \"String.fromCharCode(65)\")")
|
||||
(epoch 1901)
|
||||
(eval "(js-eval \"String.fromCharCode(72, 105)\")")
|
||||
(epoch 1902)
|
||||
(eval "(js-eval \"parseInt('42')\")")
|
||||
(epoch 1903)
|
||||
(eval "(js-eval \"parseInt(3.7)\")")
|
||||
(epoch 1904)
|
||||
(eval "(js-eval \"parseFloat('3.14')\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
|
||||
check() {
|
||||
@@ -1505,6 +1518,13 @@ check 1801 "hasOwnProperty no" 'false'
|
||||
check 1802 "({}).toString()" '"[object Object]"'
|
||||
check 1803 "obj.valueOf().x" '1'
|
||||
|
||||
# ── Phase 11.fromCharCode / parseInt / parseFloat ──────────────
|
||||
check 1900 "String.fromCharCode(65)" '"A"'
|
||||
check 1901 "String.fromCharCode(72,105)" '"Hi"'
|
||||
check 1902 "parseInt('42')" '42'
|
||||
check 1903 "parseInt(3.7)" '3'
|
||||
check 1904 "parseFloat('3.14')" '3.14'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user