Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix r1798 regression on seq, get, reduce for extend-type on natives.

  • Loading branch information...
commit 009db3c7dc45d2a99afd5d89720bca7d2047219d 1 parent 1b78c82
@swannodette swannodette authored
Showing with 35 additions and 0 deletions.
  1. +15 −0 src/cljs/cljs/core.cljs
  2. +20 −0 test/cljs/cljs/core_test.cljs
View
15 src/cljs/cljs/core.cljs
@@ -402,6 +402,9 @@
(string? coll)
(IndexedSeq. coll 0)
+ (type_satisfies_ ILookup coll)
+ (-seq coll)
+
:else (throw (js/Error. (str coll "is not ISeqable"))))))
(defn first
@@ -870,6 +873,9 @@ reduces them without incurring seq initialization"
(string? o)
(when (< k (.-length o))
(aget o k))
+
+ (type_satisfies_ ILookup o)
+ (-lookup o k)
:else nil)))
([o k not-found]
@@ -888,6 +894,9 @@ reduces them without incurring seq initialization"
(aget o k)
not-found)
+ (type_satisfies_ ILookup o)
+ (-lookup o k not-found)
+
:else not-found)
not-found)))
@@ -1276,6 +1285,9 @@ reduces them without incurring seq initialization"
(string? coll)
(array-reduce coll f)
+ (type_satisfies_ IReduce coll)
+ (-reduce coll f)
+
:else
(seq-reduce f coll)))
([f val coll]
@@ -1289,6 +1301,9 @@ reduces them without incurring seq initialization"
(string? coll)
(array-reduce coll f val)
+ (type_satisfies_ IReduce coll)
+ (-reduce coll f val)
+
:else
(seq-reduce f val coll))))
View
20 test/cljs/cljs/core_test.cljs
@@ -1866,5 +1866,25 @@
(assert (= (lazy-cat [1] [2] [3]) '(1 2 3)))
+ ;; r1798 core fn protocol regression
+ (extend-type object
+ ISeqable
+ (-seq [coll]
+ (map #(vector % (aget coll %)) (js-keys coll)))
+
+ ILookup
+ (-lookup
+ ([coll k]
+ (-lookup coll k nil))
+ ([coll k not-found]
+ (if-let [v (aget coll k)]
+ v
+ not-found))))
+
+ (assert (= (seq (js-obj "foo" 1 "bar" 2)) '(["foo" 1] ["bar" 2])))
+ (assert (= (get (js-obj "foo" 1) "foo") 1))
+ (assert (= (get (js-obj "foo" 1) "bar" ::not-found) ::not-found))
+ (assert (= (reduce (fn [s [k v]] (+ s v)) 0 (js-obj "foo" 1 "bar" 2)) 3))
+
:ok
)
Please sign in to comment.
Something went wrong with that request. Please try again.