js-on-sx: arrays accept numeric-string property keys
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 40s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 40s
JS arrays must treat string indices that look like numbers ("0",
"42") as the corresponding integer slot. js-get-prop and js-list-set!
only handled numeric key, falling through to undefined / no-op for
string keys. Added a (and (string-typed key) (numeric? key)) clause
that converts via js-string-to-number and recurses with the integer
key. built-ins/Array: 13/45 → 14/45. conformance.sh: 148/148.
This commit is contained in:
@@ -2639,6 +2639,13 @@
|
||||
(and (>= key 0) (< key (len obj)))
|
||||
(nth obj (js-num-to-int key))
|
||||
js-undefined))
|
||||
((and (= (type-of key) "string") (js-is-numeric-string? key))
|
||||
(let
|
||||
((idx (js-num-to-int (js-string-to-number key))))
|
||||
(if
|
||||
(and (>= idx 0) (< idx (len obj)))
|
||||
(nth obj idx)
|
||||
js-undefined)))
|
||||
((= key "push") (js-array-method obj "push"))
|
||||
((= key "pop") (js-array-method obj "pop"))
|
||||
((= key "shift") (js-array-method obj "shift"))
|
||||
@@ -2791,6 +2798,8 @@
|
||||
((< i n) (set-nth! lst i val))
|
||||
((= i n) (append! lst val))
|
||||
(else (do (js-pad-list! lst n i) (append! lst val))))))
|
||||
((and (= (type-of key) "string") (js-is-numeric-string? key))
|
||||
(js-list-set! lst (js-string-to-number key) val))
|
||||
((= key "length") nil)
|
||||
(else nil))))
|
||||
(define
|
||||
|
||||
Reference in New Issue
Block a user