js-on-sx: globalThis self-ref, toFixed range + 1e21 fallback
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

This commit is contained in:
2026-05-10 12:01:14 +00:00
parent 0142d69212
commit 1e29bba1be
2 changed files with 36 additions and 27 deletions

View File

@@ -536,36 +536,41 @@
js-number-to-fixed
(fn
(n digits)
(cond
((js-number-is-nan n) "NaN")
((= n (js-infinity-value)) "Infinity")
((= n (- 0 (js-infinity-value))) "-Infinity")
(else
(let
((d (js-math-trunc digits)))
(if
(< d 1)
(js-to-string (js-math-round n))
(let
((scale (js-pow-int 10 d)))
(let
((d (js-math-trunc (js-to-number digits))))
(cond
((or (js-number-is-nan d) (< d 0) (> d 100))
(raise
(js-new-call RangeError
(js-args "toFixed() digits argument must be between 0 and 100"))))
((js-number-is-nan n) "NaN")
((= n (js-infinity-value)) "Infinity")
((= n (- 0 (js-infinity-value))) "-Infinity")
((or (>= n 1e21) (<= n -1e21)) (js-number-to-string n))
(else
(cond
((< d 1) (js-to-string (js-math-round n)))
(else
(let
((scaled (js-math-round (* n scale))))
((scale (js-pow-int 10 d)))
(let
((abs-scaled (if (< scaled 0) (- 0 scaled) scaled))
(sign (if (< scaled 0) "-" "")))
((scaled (js-math-round (* n scale))))
(let
((int-part (js-math-trunc (/ abs-scaled scale)))
(frac-part
(-
abs-scaled
(* (js-math-trunc (/ abs-scaled scale)) scale))))
(str
sign
(js-to-string int-part)
"."
(js-pad-int-str
(js-to-string (js-math-trunc frac-part))
d))))))))))))
((abs-scaled (if (< scaled 0) (- 0 scaled) scaled))
(sign (if (< scaled 0) "-" "")))
(let
((int-part (js-math-trunc (/ abs-scaled scale)))
(frac-part
(-
abs-scaled
(* (js-math-trunc (/ abs-scaled scale)) scale))))
(str
sign
(js-to-string int-part)
"."
(js-pad-int-str
(js-to-string (js-math-trunc frac-part))
d)))))))))))))
(define
js-pow-int
@@ -6803,3 +6808,5 @@
(define js-global {:undefined js-undefined :JSON JSON :parseInt parseInt :Object Object :isNaN js-global-is-nan :Infinity inf :NaN 0 :String String :Boolean Boolean :Array Array :Math Math :parseFloat parseFloat :Number Number :console console :isFinite js-global-is-finite :Map Map :Set Set :Date Date :RegExp RegExp :Function js-function-global :Error Error :TypeError TypeError :RangeError RangeError :SyntaxError SyntaxError :ReferenceError ReferenceError :URIError URIError :EvalError EvalError :encodeURI encodeURI :decodeURI decodeURI :encodeURIComponent encodeURIComponent :decodeURIComponent decodeURIComponent :eval js-global-eval :Promise Promise :Symbol :js-undefined :AggregateError :js-undefined :SuppressedError :js-undefined :globalThis nil})
(set! js-global-this js-global)
(dict-set! js-global "globalThis" js-global)