Skip to content

Commit d270939

Browse files
committed
cljs.proxy doesn't handle for .. in correctly
- check for Symbol.iterator case in vec and map handler - need to bind iterator to target for it to work - fixes trivial vector case [1 2 3 4], but not nested case * will need to map over the results of the iterator * this true for the map case too where entries are 2-element arrays
1 parent 5bb9912 commit d270939

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/main/cljs/cljs/proxy.cljs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns cljs.proxy
2-
(:refer-global :only [Proxy isNaN])
2+
(:refer-global :only [isNaN Proxy Symbol])
33
(:require [cljs.proxy.impl :refer [SimpleCache]]))
44

55
(defn- write-through [f]
@@ -45,16 +45,26 @@
4545
(js* "var __ctor")
4646
(let [cache-key-fn (write-through key-fn)
4747
vec-handler #js {:get (fn [^cljs.core/IIndexed target prop receiver]
48-
(if (identical? prop "length")
48+
(cond
49+
(identical? "length" prop)
4950
(-count ^cljs.core/ICounted target)
51+
52+
(identical? (. Symbol -iterator) prop)
53+
(.bind (unchecked-get target prop) target)
54+
55+
(string? prop)
5056
(let [n (js* "+~{}" prop)]
5157
(when (and (number? n)
5258
(not (isNaN n)))
5359
(js/__ctor (-nth target n nil))))))
5460

5561
:has (fn [^cljs.core/IAssociative target prop]
56-
(if (identical? prop "length")
57-
true
62+
(cond
63+
(identical? prop "length") true
64+
65+
(identical? (. Symbol -iterator) prop) true
66+
67+
(string? prop)
5868
(let [n (js* "+~{}" prop)]
5969
(and (number? n)
6070
(not (isNaN n))
@@ -70,10 +80,16 @@
7080
:getOwnPropertyDescriptor
7181
(fn [target prop] desc)}
7282
map-handler #js {:get (fn [^cljs.core/ILookup target prop receiver]
73-
(js/__ctor (-lookup target (cache-key-fn prop))))
83+
(cond
84+
(identical? (. Symbol -iterator) prop)
85+
(unchecked-get target prop)
86+
87+
:else (js/__ctor (-lookup target (cache-key-fn prop)))))
7488

7589
:has (fn [^cljs.core/IAssociative target prop]
76-
(-contains-key? target (cache-key-fn prop)))
90+
(cond
91+
(identical? (. Symbol -iterator) prop) true
92+
:else (-contains-key? target (cache-key-fn prop))))
7793

7894
:getPrototypeOf
7995
(fn [target] nil)
@@ -150,5 +166,7 @@
150166

151167
(def proxied-deep (proxy [{:foo "Hello"}]))
152168
(-> proxied-deep (aget 0) (unchecked-get "foo"))
169+
170+
(aget ((cljs.proxy/builder) [{}]) 0)
153171

154172
)

0 commit comments

Comments
 (0)