Skip to content

Commit dab61a6

Browse files
committed
CLJS-2859: Graal.JS: Enable high-res timers by default, allow user-configuration
1 parent f13c08c commit dab61a6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/main/clojure/cljs/repl/graaljs.clj

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@
2121
[cljs.stacktrace :as st])
2222
(:import [javax.script ScriptEngine ScriptException]))
2323

24-
(defn create-engine []
24+
(defn- js-opt-key? [k]
25+
(and (string? k)
26+
(string/starts-with? k "js.")))
27+
28+
(defn- form-js-opts [opts]
29+
(for [[k v] opts
30+
:when (js-opt-key? k)]
31+
`(.option ~k ~v)))
32+
33+
(defn create-engine [opts]
2534
;; In order to support AOT compilation by JVMs that don't have
2635
;; GraalVM available, we load and execute engine creation code
2736
;; here at runtime.
2837
(import '(com.oracle.truffle.js.scriptengine GraalJSScriptEngine))
2938
(import '(org.graalvm.polyglot Context))
30-
(let [engine (eval '(GraalJSScriptEngine/create nil
39+
(let [engine (eval `(GraalJSScriptEngine/create nil
3140
(-> (Context/newBuilder (make-array String 0))
41+
~@(form-js-opts opts)
3242
(.allowHostAccess true)
3343
(.allowCreateThread true)
3444
(.allowNativeAccess true))))
@@ -172,8 +182,12 @@
172182
(fn [st]
173183
(string/join "\n" (drop 1 (string/split st #"\n")))))))
174184

185+
(def ^:private default-js-opts
186+
{"js.precise-time" "true"})
187+
175188
(defn repl-env* [{:keys [debug] :as opts}]
176-
(let [engine (create-engine)]
189+
(let [opts (merge default-js-opts opts)
190+
engine (create-engine opts)]
177191
(merge
178192
(GraalJSEnv. engine debug)
179193
opts)))

0 commit comments

Comments
 (0)