Skip to content

Commit

Permalink
Merge pull request #237 from brandonstubbs/issue-230
Browse files Browse the repository at this point in the history
reflection warning in epsilon util, fixes #230
  • Loading branch information
noprompt committed Jun 10, 2023
2 parents 454bf46 + 25e440d commit 74de6b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ pom.xml.asc
cljs-test-runner-out/
nashorn_code_cache/
/bin/release/
.cache
.calva
54 changes: 22 additions & 32 deletions src/meander/util/epsilon.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
(:require-macros [meander.util.epsilon
:refer [__disj
__dissoc
__nth]])))
__nth]]))
(:import #?(:bb ()
:clj (cljs.tagged_literals JSValue))))

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

(defn cljs-env?
"true if compiling ClojureScript or in a ClojureScript setting,
Expand Down Expand Up @@ -717,40 +721,26 @@
(symbol (name (:name cljs-ns)) (name sym)))))
sym)))

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

#?(: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)))
#?(:bb
(defn make-js-value [x] x)
:clj
(defn make-js-value [x] (new JSValue x))
:cljs
(defn make-js-value [x] x))

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

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

0 comments on commit 74de6b1

Please sign in to comment.