js-on-sx: fix js-string-repeat arity collision, repeat() raises RangeError on neg/inf
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
This commit is contained in:
@@ -3238,12 +3238,18 @@
|
||||
|
||||
(define
|
||||
js-string-repeat
|
||||
(fn
|
||||
(s n)
|
||||
(js-string-repeat-loop s n "")))
|
||||
|
||||
(define
|
||||
js-string-repeat-loop
|
||||
(fn
|
||||
(s n acc)
|
||||
(if
|
||||
(<= n 0)
|
||||
acc
|
||||
(js-string-repeat s (- n 1) (str acc s)))))
|
||||
(js-string-repeat-loop s (- n 1) (str acc s)))))
|
||||
|
||||
(define
|
||||
js-string-pad
|
||||
@@ -3383,7 +3389,16 @@
|
||||
((= name "trimStart") (fn () (js-trim-left s)))
|
||||
((= name "trimEnd") (fn () (js-trim-right s)))
|
||||
((= name "repeat")
|
||||
(fn (n) (js-string-repeat s (js-num-to-int n) "")))
|
||||
(fn
|
||||
(n)
|
||||
(let
|
||||
((nn (js-to-number n)))
|
||||
(cond
|
||||
((or (< nn 0) (= nn (js-infinity-value)))
|
||||
(raise
|
||||
(js-new-call RangeError
|
||||
(js-args "Invalid count value"))))
|
||||
(else (js-string-repeat-loop s (js-num-to-int nn) ""))))))
|
||||
((= name "padStart")
|
||||
(fn
|
||||
(&rest args)
|
||||
@@ -5732,12 +5747,6 @@
|
||||
(if (> (len sp) 10) (js-string-slice sp 0 10) sp))
|
||||
(else ""))))
|
||||
|
||||
(define
|
||||
js-string-repeat
|
||||
(fn
|
||||
(s n)
|
||||
(if (<= n 0) "" (str s (js-string-repeat s (- n 1))))))
|
||||
|
||||
(define
|
||||
js-json-unwrap-primitive
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user