Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/main/cljs/cljs/proxy.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cljs.proxy
(:refer-global :only [Proxy isNaN])
(:require [cljs.proxy.impl :refer [SimpleCache]]))
(:refer-global :only [isNaN Proxy Symbol])
(:require [cljs.proxy.impl :refer [SimpleCache MapIterator]]))

(defn- write-through [f]
(let [cache (SimpleCache. #js {} 0)]
Expand Down Expand Up @@ -45,16 +45,28 @@
(js* "var __ctor")
(let [cache-key-fn (write-through key-fn)
vec-handler #js {:get (fn [^cljs.core/IIndexed target prop receiver]
(if (identical? prop "length")
(cond
(identical? "length" prop)
(-count ^cljs.core/ICounted target)

(identical? (. Symbol -iterator) prop)
(fn []
(MapIterator.
((.bind (unchecked-get target prop) target)) js/__ctor))

:else
(let [n (js* "+~{}" prop)]
(when (and (number? n)
(not (isNaN n)))
(js/__ctor (-nth target n nil))))))

:has (fn [^cljs.core/IAssociative target prop]
(if (identical? prop "length")
true
(cond
(identical? prop "length") true

(identical? (. Symbol -iterator) prop) true

:else
(let [n (js* "+~{}" prop)]
(and (number? n)
(not (isNaN n))
Expand Down Expand Up @@ -150,5 +162,7 @@

(def proxied-deep (proxy [{:foo "Hello"}]))
(-> proxied-deep (aget 0) (unchecked-get "foo"))

(aget ((cljs.proxy/builder) [{}]) 0)

)
9 changes: 9 additions & 0 deletions src/main/cljs/cljs/proxy/impl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@
(clear [this]
(set! obj #js {})
(set! cnt 0)))

(deftype MapIterator [^:mutable iter f]
Object
(next [_]
(let [x (.next iter)]
(if-not ^boolean (. x -done)
#js {:value (f (. x -value))
:done false}
x))))
Loading