Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ nashorn_code_cache/
/bin/release/
.cache
.calva
.idea/
*.iml
52 changes: 32 additions & 20 deletions src/meander/util/epsilon.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
(:require-macros [meander.util.epsilon
:refer [__disj
__dissoc
__nth]]))
(:import #?(:bb ()
:clj (cljs.tagged_literals JSValue))))
__nth]])))

#?(:clj (set! *warn-on-reflection* true))

Expand Down Expand Up @@ -721,26 +719,40 @@
(symbol (name (:name cljs-ns)) (name sym)))))
sym)))

#?(:bb
(defn js-value? [_x] false)
:clj
(defn js-value? [x] (instance? JSValue x))
#?(:clj
(try
(let [c (Class/forName "cljs.tagged_literals.JSValue")]
(defn js-value? [x]
(instance? c x)))
(catch ClassNotFoundException _
(defn js-value? [x]
false)))
:cljs
(defn js-value? [_x] false))
(defn js-value? [x]
false))

#?(:bb
(defn make-js-value [x] x)
:clj
(defn make-js-value [x] (new JSValue x))
#?(:clj
(try
(let [c (Class/forName "cljs.tagged_literals.JSValue")
s 'cljs.tagged_literals.JSValue]
(defn make-js-value [x]
(eval `(new ~s ~x))))
(catch ClassNotFoundException _
(defn make-js-value [x]
x)))
:cljs
(defn make-js-value [x] x))

#?(:bb
(defn val-of-js-value [x] x)
:clj
#?(:clj
(defmacro val-op
{:private true}
[x]
(try
(Class/forName "cljs.tagged_literals.JSValue")
`(.val ^"cljs.tagged_literals.JSValue" ~x)
(catch ClassNotFoundException _
nil))))

#?(:clj
(defn val-of-js-value [x]
(if (js-value? x)
(.-val ^JSValue x)
x))
:cljs
(defn val-of-js-value [x] x))
(if (js-value? x) (val-op x) x)))