Skip to content

Commit

Permalink
CLJS-2859: Graal.JS: Enable high-res timers by default, allow user-co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
mfikes committed Aug 10, 2018
1 parent f13c08c commit dab61a6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/clojure/cljs/repl/graaljs.clj
Expand Up @@ -21,14 +21,24 @@
[cljs.stacktrace :as st])
(:import [javax.script ScriptEngine ScriptException]))

(defn create-engine []
(defn- js-opt-key? [k]
(and (string? k)
(string/starts-with? k "js.")))

(defn- form-js-opts [opts]
(for [[k v] opts
:when (js-opt-key? k)]
`(.option ~k ~v)))

(defn create-engine [opts]
;; In order to support AOT compilation by JVMs that don't have
;; GraalVM available, we load and execute engine creation code
;; here at runtime.
(import '(com.oracle.truffle.js.scriptengine GraalJSScriptEngine))
(import '(org.graalvm.polyglot Context))
(let [engine (eval '(GraalJSScriptEngine/create nil
(let [engine (eval `(GraalJSScriptEngine/create nil
(-> (Context/newBuilder (make-array String 0))
~@(form-js-opts opts)
(.allowHostAccess true)
(.allowCreateThread true)
(.allowNativeAccess true))))
Expand Down Expand Up @@ -172,8 +182,12 @@
(fn [st]
(string/join "\n" (drop 1 (string/split st #"\n")))))))

(def ^:private default-js-opts
{"js.precise-time" "true"})

(defn repl-env* [{:keys [debug] :as opts}]
(let [engine (create-engine)]
(let [opts (merge default-js-opts opts)
engine (create-engine opts)]
(merge
(GraalJSEnv. engine debug)
opts)))
Expand Down

0 comments on commit dab61a6

Please sign in to comment.