js-on-sx: Object.keys throws on null/undefined, walks indices on string/array
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 20s

This commit is contained in:
2026-05-09 22:12:05 +00:00
parent 7d575cb1fe
commit dedb82565b
2 changed files with 25 additions and 0 deletions

View File

@@ -3982,6 +3982,18 @@
(fn
(o)
(cond
((or (= o nil) (js-undefined? o))
(raise (js-new-call TypeError (js-args "Object.keys called on null or undefined"))))
((= (type-of o) "string")
(let ((result (list)) (n (len o)))
(begin
(js-string-keys-loop result 0 n)
result)))
((list? o)
(let ((result (list)) (n (len o)))
(begin
(js-string-keys-loop result 0 n)
result)))
((dict? o)
(cond
((contains? (keys o) "__js_order__")
@@ -4002,6 +4014,17 @@
result)))))
(else (list)))))
(define
js-string-keys-loop
(fn
(acc i n)
(cond
((>= i n) nil)
(else
(begin
(append! acc (js-to-string i))
(js-string-keys-loop acc (+ i 1) n))))))
(define
js-object-values
(fn