js-on-sx: js-num-to-int coerces strings via js-to-number
This commit is contained in:
@@ -1392,7 +1392,11 @@
|
|||||||
|
|
||||||
(define
|
(define
|
||||||
js-num-to-int
|
js-num-to-int
|
||||||
(fn (n) (if (>= n 0) (floor n) (- 0 (floor (- 0 n))))))
|
(fn
|
||||||
|
(v)
|
||||||
|
(let
|
||||||
|
((n (if (number? v) v (js-to-number v))))
|
||||||
|
(if (>= n 0) (floor n) (- 0 (floor (- 0 n)))))))
|
||||||
|
|
||||||
(define dict-has? (fn (d k) (contains? (keys d) k)))
|
(define dict-has? (fn (d k) (contains? (keys d) k)))
|
||||||
|
|
||||||
|
|||||||
@@ -1053,6 +1053,12 @@ cat > "$TMPFILE" << 'EPOCHS'
|
|||||||
(epoch 2307)
|
(epoch 2307)
|
||||||
(eval "(js-eval \"Array.from([1,2,3], (x)=>x*2).join(',')\")")
|
(eval "(js-eval \"Array.from([1,2,3], (x)=>x*2).join(',')\")")
|
||||||
|
|
||||||
|
;; ── Phase 11.coerce: string-to-number coercion in int params ──
|
||||||
|
(epoch 2400)
|
||||||
|
(eval "(js-eval \"'abcd'.charAt('2')\")")
|
||||||
|
(epoch 2401)
|
||||||
|
(eval "(js-eval \"'abcd'.slice('1', '3')\")")
|
||||||
|
|
||||||
EPOCHS
|
EPOCHS
|
||||||
|
|
||||||
|
|
||||||
@@ -1619,6 +1625,10 @@ check 2305 "Array.from array" '3'
|
|||||||
check 2306 "Array.from string" '3'
|
check 2306 "Array.from string" '3'
|
||||||
check 2307 "Array.from w/ map" '"2,4,6"'
|
check 2307 "Array.from w/ map" '"2,4,6"'
|
||||||
|
|
||||||
|
# ── Phase 11.coerce ───────────────────────────────────────────
|
||||||
|
check 2400 "charAt coerces string" '"c"'
|
||||||
|
check 2401 "slice coerces strings" '"bc"'
|
||||||
|
|
||||||
TOTAL=$((PASS + FAIL))
|
TOTAL=$((PASS + FAIL))
|
||||||
if [ $FAIL -eq 0 ]; then
|
if [ $FAIL -eq 0 ]; then
|
||||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||||
|
|||||||
Reference in New Issue
Block a user