From 621a1ad94745031d96dd698f50445e6573f7178f Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 24 Apr 2026 08:07:57 +0000 Subject: [PATCH] js-on-sx: js-iterable-to-list respects length on array-like dicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Array.from({length: 3, 0: 'a', 1: 'b', 2: 'c'}) used to return ['3','a','b','c'] because js-iterable-to-list walked dict keys in insertion order and included the 'length' key as a value. Now the dict branch checks for 'length' key first — if present, delegates to js-arraylike-to-list which reads indices 0..length-1. Otherwise falls back to value-order for plain objects. Fixes Array.from, spread (...dict), and destructure from array-likes. Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/js/runtime.sx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index 669d195f..0f93158f 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -2195,10 +2195,14 @@ ((list? v) v) ((= (type-of v) "string") (js-string-to-list v 0 (list))) ((dict? v) - (let - ((result (list))) - (for-each (fn (k) (append! result (get v k))) (keys v)) - result)) + (cond + ((contains? (keys v) "length") (js-arraylike-to-list v)) + (else + (let + ((result (list))) + (begin + (for-each (fn (k) (append! result (get v k))) (keys v)) + result))))) (else (list))))) (define