|
15 | 15 | [cljs.repl :as repl]
|
16 | 16 | [cljs.compiler :as comp]
|
17 | 17 | [cljs.closure :as closure])
|
18 |
| - (:import [javax.script ScriptEngine ScriptEngineManager ScriptException ScriptEngineFactory] |
| 18 | + (:import [java.io File] |
| 19 | + [javax.script ScriptEngine ScriptEngineManager ScriptException ScriptEngineFactory] |
19 | 20 | [jdk.nashorn.api.scripting NashornException]))
|
20 | 21 |
|
21 | 22 | ;; Nashorn Clojurescript repl binding.
|
|
141 | 142 | (string/replace-first file-name with-slash "")
|
142 | 143 | file-name)))
|
143 | 144 |
|
144 |
| -(defn- convert-stacktrace-element [^StackTraceElement el] |
145 |
| - {:function (.getMethodName el) |
146 |
| - :file (.getFileName el) |
147 |
| - :line (.getLineNumber el) |
148 |
| - :column 0}) |
149 |
| - |
150 | 145 | (def repl-filename "<cljs repl>")
|
151 | 146 |
|
152 | 147 | (defrecord NashornEnv [engine debug]
|
|
183 | 178 | (try
|
184 | 179 | {:status :success
|
185 | 180 | :value (if-let [r (eval-str engine js)] (.toString r) "")}
|
186 |
| - |
187 |
| - ;; Stringify the stacktrace to edn for easy parsing in -parse-stacktrace |
188 | 181 | (catch ScriptException e
|
189 | 182 | (let [^Throwable root-cause (clojure.stacktrace/root-cause e)]
|
190 | 183 | {:status :exception
|
191 | 184 | :value (.getMessage root-cause)
|
192 |
| - :stacktrace (pr-str (map convert-stacktrace-element |
193 |
| - (NashornException/getScriptFrames root-cause)))})) |
| 185 | + :stacktrace (NashornException/getScriptStackString root-cause)})) |
194 | 186 | (catch Throwable e
|
195 | 187 | (let [^Throwable root-cause (clojure.stacktrace/root-cause e)]
|
196 | 188 | {:status :exception
|
197 | 189 | :value (.getMessage root-cause)
|
198 |
| - :stacktrace (pr-str (map convert-stacktrace-element (.getStackTrace root-cause)))})))) |
| 190 | + :stacktrace |
| 191 | + (apply str |
| 192 | + (interpose "\n" |
| 193 | + (map str |
| 194 | + (.getStackTrace root-cause))))})))) |
199 | 195 | (-load [{engine :engine :as this} ns url]
|
200 | 196 | (load-ns engine ns))
|
201 | 197 | (-tear-down [this])
|
202 | 198 | repl/IParseStacktrace
|
203 | 199 | (-parse-stacktrace [this frames-str ret {output-dir :output-dir}]
|
204 |
| - (when-let [frames (read-string frames-str)] |
205 |
| - (vec (map #(update-in %1 [:file] (fn [s] (strip-file-name s output-dir))) frames))))) |
| 200 | + (vec |
| 201 | + (map |
| 202 | + (fn [frame-str] |
| 203 | + (let [frame-str (string/replace frame-str #"\s+at\s+" "") |
| 204 | + [function file-and-line] (string/split frame-str #"\s+") |
| 205 | + [file-part line-part] (string/split file-and-line #":")] |
| 206 | + {:file (string/replace (.substring file-part 1) |
| 207 | + (str output-dir File/separator) "") |
| 208 | + :function function |
| 209 | + :line (Integer/parseInt |
| 210 | + (.substring line-part 0 (dec (.length line-part)))) |
| 211 | + :column 0})) |
| 212 | + (string/split frames-str #"\n")))) |
| 213 | + repl/IParseError |
| 214 | + (-parse-error [_ err _] |
| 215 | + (update-in err [:stacktrace] |
| 216 | + (fn [st] |
| 217 | + (string/join "\n" (drop 1 (string/split st #"\n"))))))) |
206 | 218 |
|
207 | 219 | (defn repl-env* [{:keys [debug] :as opts}]
|
208 | 220 | (let [engine (create-engine opts)]
|
|
0 commit comments