Skip to content

Commit

Permalink
Set the default print function for Rhino evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
brentonashworth committed Sep 28, 2011
1 parent 0082d8f commit 545aad2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/clj/cljs/repl/rhino.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[cljs.compiler :as comp]
[cljs.repl :as repl])
(:import cljs.repl.IJavaScriptEnv
[org.mozilla.javascript Context]))
[org.mozilla.javascript Context ScriptableObject]))

(def current-repl-env (atom nil))
(def loaded-libs (atom #{}))
Expand Down Expand Up @@ -93,13 +93,21 @@
(swap! loaded-libs (partial apply conj) missing)))))

(defn rhino-setup [repl-env]
(let [env {:context :statement :locals {}}]
(let [env {:context :statement :locals {} :ns (@comp/namespaces comp/*cljs-ns*)}
scope (:scope repl-env)]
(repl/load-file repl-env "cljs/core.cljs")
(swap! loaded-libs conj "cljs.core")
(repl/evaluate-form repl-env
(assoc env :ns (@comp/namespaces comp/*cljs-ns*))
env
"<cljs repl>"
'(ns cljs.user))))
'(ns cljs.user))
(ScriptableObject/putProperty scope
"out"
(Context/javaToJS System/out scope))
(repl/evaluate-form repl-env
env
"<cljs repl>"
'(set! *print-fn* (fn [x] (.print js/out x))))))

(extend-protocol repl/IJavaScriptEnv
clojure.lang.IPersistentMap
Expand Down Expand Up @@ -143,6 +151,7 @@
(:a {:a "hello"})
(:a {:a :b})
(reduce + [1 2 3 4 5])
(time (reduce + [1 2 3 4 5]))
(even? :a)
(throw (js/Error. "There was an error"))
(load-file "clojure/string.cljs")
Expand Down

0 comments on commit 545aad2

Please sign in to comment.