            [org.mozilla.javascript Context ScriptableObject]))
 
 (def current-repl-env (atom nil))
-(def loaded-libs (atom #{}))
 
 ;;todo - move to core.cljs, using js
 (def ^String bootjs (str "goog.require = function(rule){"
                          "Packages.clojure.lang.RT[\"var\"](\"cljs.repl.rhino\",\"goog-require\")"
-                         ".invoke(rule);}"))
+                         ".invoke(___repl_env, rule);}"))
 
 (defprotocol IEval
   (-eval [this env filename line]))

;; You must not remove this notice, or any other, from this software.

(ns cljs.repl.rhino
  (:refer-clojure :exclude [loaded-libs])
  (:require [clojure.string :as string]
            [clojure.java.io :as io]
            [cljs.compiler :as comp]

        scope (.initStandardObjects cx)
        base (io/resource "goog/base.js")
        deps (io/resource "goog/deps.js")
        new-repl-env (merge (RhinoEnv. (atom #{})) {: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))
    (ScriptableObject/putProperty scope
                                  "___repl_env"
                                  (Context/javaToJS new-repl-env scope))
    (with-open [r (io/reader base)]
      (-eval r new-repl-env "goog/base.js" 1))
    (-eval bootjs new-repl-env "bootjs" 1)
