js-on-sx: Object.values/entries throw on null/undefined, walk strings
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 42s

This commit is contained in:
2026-05-09 22:42:24 +00:00
parent dedb82565b
commit b4f7f814be
2 changed files with 54 additions and 7 deletions

View File

@@ -4030,33 +4030,78 @@
(fn
(o)
(cond
((or (= o nil) (js-undefined? o))
(raise (js-new-call TypeError (js-args "Object.values called on null or undefined"))))
((= (type-of o) "string")
(let ((result (list)) (n (len o)))
(begin
(js-string-values-loop result o 0 n)
result)))
((dict? o)
(let
((result (list)))
(for-each (fn (k) (append! result (get o k))) (keys o))
(for-each
(fn (k) (if (js-key-internal? k) nil (append! result (get o k))))
(js-object-keys o))
result))
(else (list)))))
(define
js-string-values-loop
(fn
(acc s i n)
(cond
((>= i n) nil)
(else
(begin
(append! acc (char-at s i))
(js-string-values-loop acc s (+ i 1) n))))))
(define
js-object-entries
(fn
(o)
(cond
((or (= o nil) (js-undefined? o))
(raise (js-new-call TypeError (js-args "Object.entries called on null or undefined"))))
((= (type-of o) "string")
(let ((result (list)) (n (len o)))
(begin
(js-string-entries-loop result o 0 n)
result)))
((dict? o)
(let
((result (list)))
(for-each
(fn
(k)
(let
((pair (list)))
(append! pair k)
(append! pair (get o k))
(append! result pair)))
(keys o))
(if
(js-key-internal? k)
nil
(let
((pair (list)))
(begin
(append! pair k)
(append! pair (get o k))
(append! result pair)))))
(js-object-keys o))
result))
(else (list)))))
(define
js-string-entries-loop
(fn
(acc s i n)
(cond
((>= i n) nil)
(else
(let ((pair (list)))
(begin
(append! pair (js-to-string i))
(append! pair (char-at s i))
(append! acc pair)
(js-string-entries-loop acc s (+ i 1) n)))))))
(define
js-object-assign
(fn