Permalink
Browse files

Use records to implement IJavaScriptEnv instead of extending to

IPersistentMap

This is just flat out better and will allow one to create Rhino and
Browser evaluation environments within the same process.
  • Loading branch information...
brentonashworth committed Sep 28, 2012
1 parent 953e577 commit 66d43dd1e9fcd1d7e0104478ba64680c702bbccc
Showing with 7 additions and 6 deletions.
  1. +4 −3 src/clj/cljs/repl/browser.clj
  2. +3 −3 src/clj/cljs/repl/rhino.clj
@@ -160,8 +160,8 @@
(browser-eval (slurp url))
(swap! loaded-libs (partial apply conj) missing))))
-(extend-protocol repl/IJavaScriptEnv
- clojure.lang.IPersistentMap
+(defrecord BrowserEnv []
+ repl/IJavaScriptEnv
(-setup [this]
(do (require 'cljs.repl.reflect)
(repl/analyze-source (:src this))
@@ -226,7 +226,8 @@
support reflection. Defaults to \"src/\".
"
[& {:as opts}]
- (let [opts (merge {:port 9000
+ (let [opts (merge (BrowserEnv.)
+ {:port 9000
:optimizations :simple
:working-dir ".repl"
:serve-static true
@@ -110,8 +110,8 @@
"<cljs repl>"
'(set! *print-fn* (fn [x] (.print js/out x))))))
-(extend-protocol repl/IJavaScriptEnv
- clojure.lang.IPersistentMap
+(defrecord RhinoEnv []
+ repl/IJavaScriptEnv
(-setup [this]
(rhino-setup this))
(-evaluate [this filename line js]
@@ -128,7 +128,7 @@
scope (.initStandardObjects cx)
base (io/resource "goog/base.js")
deps (io/resource "goog/deps.js")
- new-repl-env {:cx cx :scope scope}]
+ new-repl-env (merge (RhinoEnv.) {:cx cx :scope scope})]
(assert base "Can't find goog/base.js in classpath")
(assert deps "Can't find goog/deps.js in classpath")
(swap! current-repl-env (fn [old] new-repl-env))

0 comments on commit 66d43dd

Please sign in to comment.