From 2af31248f284ab40f1b4e7b53425477d04824081 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 24 Apr 2026 13:14:23 +0000 Subject: [PATCH] =?UTF-8?q?js-on-sx:=20js-num-to-int=20guards=20NaN/Infini?= =?UTF-8?q?ty=20=E2=86=92=200=20(+2=20String)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spec ToUint16 (String.fromCharCode argument coercion) maps non-finite values to 0. We had bare (floor v) which left inf/-inf/nan through, breaking: String.fromCharCode(Infinity).charCodeAt(0) === 0 // was "" → err String.fromCharCode(NaN).charCodeAt(0) === 0 // was "" → err Add NaN/inf/-inf guards returning 0 before the floor+signed-flip path. Unit 521/522, slice 148/148 unchanged. String 38/100 → 40/100 (+2: fromCharCode/S9.7_A1, S9.7_A2.1). --- lib/js/runtime.sx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index d4f44c36..ecfd6c87 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -2291,8 +2291,13 @@ (fn (v) (let - ((n (if (number? v) v (js-to-number v)))) - (if (>= n 0) (floor n) (- 0 (floor (- 0 n))))))) + ((n (js-to-number v))) + (cond + ((js-number-is-nan n) 0) + ((= n (js-infinity-value)) 0) + ((= n (- 0 (js-infinity-value))) 0) + ((>= n 0) (floor n)) + (else (- 0 (floor (- 0 n)))))))) (define dict-has? (fn (d k) (contains? (keys d) k)))