|
6 | 6 | ;; the terms of this license. |
7 | 7 | ;; You must not remove this notice, or any other, from this software. |
8 | 8 |
|
9 | | -(ns cljs.repl.nashorn |
| 9 | +;; cljs repl nashorn update to support the openjdk nashorn package in |
| 10 | +;; JDK versions greater than 15. |
| 11 | +;; |
| 12 | +;; Adapted from |
| 13 | +;; https://raw.githubusercontent.com/clojure/clojurescript/r1.10.439/src/main/clojure/cljs/repl/nashorn.clj. |
| 14 | + |
| 15 | +(ns clojure.data.xml.cljs-repl-nashorn |
10 | 16 | (:require [clojure.java.io :as io] |
11 | 17 | [clojure.string :as string] |
12 | 18 | [clojure.stacktrace] |
|
21 | 27 | [cljs.stacktrace :as st]) |
22 | 28 | (:import [javax.script ScriptEngine ScriptEngineManager ScriptException ScriptEngineFactory])) |
23 | 29 |
|
24 | | -(util/compile-if (Class/forName "jdk.nashorn.api.scripting.NashornException") |
| 30 | +(def engine-name |
| 31 | + (util/compile-if (Class/forName "org.openjdk.nashorn.api.scripting.NashornException") |
| 32 | + (do |
| 33 | + (import 'org.openjdk.nashorn.api.scripting.NashornException) |
| 34 | + "OpenJDK Nashorn") |
| 35 | + (do |
| 36 | + (import 'jdk.nashorn.api.scripting.NashornException) |
| 37 | + "Oracle Nashorn"))) |
| 38 | + |
| 39 | +(do |
25 | 40 | (do |
26 | | - (import 'jdk.nashorn.api.scripting.NashornException) |
27 | 41 | ;; Implementation |
28 | 42 |
|
29 | 43 | (defn create-engine |
30 | 44 | ([] (create-engine nil)) |
31 | 45 | ([{:keys [code-cache] :or {code-cache true}}] |
32 | 46 | (let [args (when code-cache ["-pcc"]) |
33 | 47 | factories (.getEngineFactories (ScriptEngineManager.)) |
34 | | - factory (get (zipmap (map #(.getEngineName %) factories) factories) "Oracle Nashorn")] |
| 48 | + factory (get (zipmap (map #(.getEngineName %) factories) factories) engine-name)] |
35 | 49 | (if-let [engine (if-not (empty? args) |
36 | 50 | (.getScriptEngine ^ScriptEngineFactory factory (into-array args)) |
37 | 51 | (.getScriptEngine ^ScriptEngineFactory factory))] |
|
180 | 194 | (defn -main [& args] |
181 | 195 | (apply cli/main repl-env args))) |
182 | 196 |
|
183 | | - (do |
184 | | - (defn repl-env* [{:keys [debug] :as opts}] |
185 | | - (throw (ex-info "Nashorn not supported" {:type :repl-error}))) |
186 | | - |
187 | | - (defn repl-env |
188 | | - "Create a Nashorn repl-env for use with the repl/repl* method in Clojurescript." |
189 | | - [& {:as opts}] |
190 | | - (throw (ex-info "Nashorn not available under this Java runtime" {:type :repl-error}))) |
191 | | - |
192 | | - (defn -main [] |
193 | | - (throw (ex-info "Nashorn not available under this Java runtime" {:type :repl-error}))))) |
| 197 | +) |
0 commit comments