From 6cc1a9054a65985492a9c576bfaf34e85466000b Mon Sep 17 00:00:00 2001 From: Brandon Bloom Date: Mon, 4 Jun 2012 18:45:00 -0700 Subject: [PATCH] Inline instance? --- src/clj/cljs/core.clj | 11 ++++++++--- src/cljs/cljs/core.cljs | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/clj/cljs/core.clj b/src/clj/cljs/core.clj index 1220ce1..7f7d3db 100644 --- a/src/clj/cljs/core.clj +++ b/src/clj/cljs/core.clj @@ -15,7 +15,7 @@ memfn ns or proxy proxy-super pvalues refer-clojure reify sync time when when-first when-let when-not while with-bindings with-in-str with-loading-context with-local-vars with-open with-out-str with-precision with-redefs - satisfies? identical? true? false? nil? str get + satisfies? instance? identical? true? false? nil? str get aget aset + - * / < <= > >= == zero? pos? neg? inc dec max min mod @@ -100,6 +100,11 @@ (defmacro undefined? [x] (bool-expr (list 'js* "(void 0 === ~{})" x))) +(defmacro instance? [t o] + (bool-expr (if (symbol? t) + (list 'js* "(~{} instanceof ~{})" o t) + `(let [t# ~t] (~'js* "(~{} instanceof ~{})" ~o t#))))) + (defmacro identical? [a b] (bool-expr (list 'js* "(~{} === ~{})" a b))) @@ -740,7 +745,7 @@ (cond ~@(mapcat (fn [[_ type name & cb]] - `[(instance? ~type ~e) (let [~name ~e] ~@cb)]) + `[(core/instance? ~type ~e) (let [~name ~e] ~@cb)]) catches) :else (throw ~e))) ~@fin) @@ -1029,4 +1034,4 @@ (if (zero? ~'argc) (~'f) ~(gen-apply-to-helper)))) - (set! ~'*unchecked-if* false))) \ No newline at end of file + (set! ~'*unchecked-if* false))) diff --git a/src/cljs/cljs/core.cljs b/src/cljs/cljs/core.cljs index 2f13165..e68027b 100644 --- a/src/cljs/cljs/core.cljs +++ b/src/cljs/cljs/core.cljs @@ -953,7 +953,7 @@ reduces them without incurring seq initialization" (cljs.core/undefined? x)) (defn ^boolean instance? [t o] - (js* "(~{o} instanceof ~{t})")) + (cljs.core/instance? t o)) (defn ^boolean seq? "Return true if s satisfies ISeq" @@ -6029,7 +6029,7 @@ reduces them without incurring seq initialization" ;;;;;;;;;;;;;;;;;;;;;;;;; Regular Expressions ;;;;;;;;;; (defn regexp? [o] - (js* "~{o} instanceof RegExp")) + (instance? js/RegExp o)) (defn re-matches "Returns the result of (re-find re s) if re fully matches s." -- 1.7.9.1