js-on-sx: getOwnPropertyDescriptor handles arrays + strings
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

This commit is contained in:
2026-05-09 01:32:39 +00:00
parent c8ab505c32
commit b57f40db63
2 changed files with 32 additions and 4 deletions

View File

@@ -4042,10 +4042,36 @@
js-object-get-own-property-descriptor
(fn
(o key)
(if
(and (dict? o) (contains? (keys o) (js-to-string key)))
{:configurable true :enumerable true :value (get o (js-to-string key)) :writable true}
:js-undefined)))
(let
((sk (js-to-string key)))
(cond
((and (dict? o) (contains? (keys o) sk))
{:configurable true :enumerable true :value (get o sk) :writable true})
((list? o)
(cond
((= sk "length")
{:configurable false :enumerable false :value (len o) :writable true})
((js-int-key? sk)
(let
((i (js-num-to-int (js-string-to-number sk))))
(cond
((and (>= i 0) (< i (len o)))
{:configurable true :enumerable true :value (nth o i) :writable true})
(else :js-undefined))))
(else :js-undefined)))
((and (= (type-of o) "string"))
(cond
((= sk "length")
{:configurable false :enumerable false :value (len o) :writable false})
((js-int-key? sk)
(let
((i (js-num-to-int (js-string-to-number sk))))
(cond
((and (>= i 0) (< i (len o)))
{:configurable false :enumerable true :value (char-at o i) :writable false})
(else :js-undefined))))
(else :js-undefined)))
(else :js-undefined)))))
(define
js-object-get-own-property-descriptors