Permalink
Browse files

* src/clj/cljs/core.clj: general fix for CLJS-330, protocol dispatch …

…should handle undefined by coercing to nil
  • Loading branch information...
1 parent 00712af commit e3c6991ad545d6a7fab7f68bf461ac57b6483d81 David Nolen committed Jul 4, 2012
Showing with 16 additions and 11 deletions.
  1. +8 −6 src/clj/cljs/core.clj
  2. +7 −5 src/cljs/cljs/core.cljs
  3. +1 −0 test/cljs/cljs/core_test.cljs
View
@@ -694,12 +694,14 @@
`(~sig
(if (and ~(first sig) (. ~(first sig) ~(symbol (core/str "-" slot)))) ;; Property access needed here.
(. ~(first sig) ~slot ~@sig)
- ((or
- (aget ~(fqn fname) (goog.typeOf ~(first sig)))
- (aget ~(fqn fname) "_")
- (throw (missing-protocol
- ~(core/str psym "." fname) ~(first sig))))
- ~@sig))))
+ (let [t# ~(first sig)
+ t# (if (nil? t#) nil t#)]
+ ((or
+ (aget ~(fqn fname) (goog.typeOf t#))
+ (aget ~(fqn fname) "_")
+ (throw (missing-protocol
+ ~(core/str psym "." fname) ~(first sig))))
+ ~@sig)))))
method (fn [[fname & sigs]]
(let [sigs (take-while vector? sigs)
slot (symbol (core/str prefix (name fname)))
View
@@ -46,10 +46,12 @@
(defn ^boolean type_satisfies_
"Internal - do not use!"
[p x]
- (cond
- (aget p (goog.typeOf x)) true
- (aget p "_") true
- :else false))
+ (let [t (goog.typeOf x)
+ t (if (nil? t) nil t)]
+ (cond
+ (aget p t) true
+ (aget p "_") true
+ :else false)))
(set! *unchecked-if* false)
(defn is_proto_
@@ -396,7 +398,7 @@
(extend-type default
IHash
(-hash [o]
- (if (nil? o) 0 (goog.getUid o))))
+ (goog.getUid o)))
;;this is primitive because & emits call to array-seq
(defn inc
@@ -184,6 +184,7 @@
(assert (= 2 ({} :a 2)))
(assert (= nil (:a {})))
(assert (= 2 (#{1 2 3} 2)))
+ (assert (zero? (hash (aget (js-obj) "foo"))))
(assert (= 1 (apply :a '[{:a 1 a 2}])))
(assert (= 1 (apply 'a '[{a 1 :b 2}])))

0 comments on commit e3c6991

Please sign in to comment.