Skip to content

Commit 3789897

Browse files
committed
- add cljs.proxu.impl/MapIterator
- remove string cases - remove iterator cases from map-handler, no for..of for raw Objects
1 parent 7c4c3f3 commit 3789897

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/main/cljs/cljs/proxy.cljs

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

55
(defn- write-through [f]
66
(let [cache (SimpleCache. #js {} 0)]
@@ -50,9 +50,11 @@
5050
(-count ^cljs.core/ICounted target)
5151

5252
(identical? (. Symbol -iterator) prop)
53-
(.bind (unchecked-get target prop) target)
53+
(fn []
54+
(MapIterator.
55+
((.bind (unchecked-get target prop) target)) js/__ctor))
5456

55-
(string? prop)
57+
:else
5658
(let [n (js* "+~{}" prop)]
5759
(when (and (number? n)
5860
(not (isNaN n)))
@@ -64,7 +66,7 @@
6466

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

67-
(string? prop)
69+
:else
6870
(let [n (js* "+~{}" prop)]
6971
(and (number? n)
7072
(not (isNaN n))
@@ -80,16 +82,10 @@
8082
:getOwnPropertyDescriptor
8183
(fn [target prop] desc)}
8284
map-handler #js {:get (fn [^cljs.core/ILookup target prop receiver]
83-
(cond
84-
(identical? (. Symbol -iterator) prop)
85-
(.bind (unchecked-get target prop) target)
86-
87-
:else (js/__ctor (-lookup target (cache-key-fn prop)))))
85+
(js/__ctor (-lookup target (cache-key-fn prop))))
8886

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

9490
:getPrototypeOf
9591
(fn [target] nil)

src/main/cljs/cljs/proxy/impl.cljs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@
1313
(clear [this]
1414
(set! obj #js {})
1515
(set! cnt 0)))
16+
17+
(deftype MapIterator [^:mutable iter f]
18+
Object
19+
(next [_]
20+
(let [x (.next iter)]
21+
(if-not ^boolean (. x -done)
22+
#js {:value (f (. x -value))
23+
:done false}
24+
x))))

0 commit comments

Comments
 (0)