diff options
Diffstat (limited to 'js/repl.ts')
-rw-r--r-- | js/repl.ts | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/js/repl.ts b/js/repl.ts index 6fb395e1b..6676721fc 100644 --- a/js/repl.ts +++ b/js/repl.ts @@ -7,6 +7,8 @@ import { close } from "./files"; import * as dispatch from "./dispatch"; import { exit } from "./os"; import { globalEval } from "./global_eval"; +import { libdeno } from "./libdeno"; +import { formatError } from "./format_error"; const window = globalEval("this"); @@ -96,14 +98,19 @@ export async function replLoop(): Promise<void> { } function evaluate(code: string): void { - try { - const result = eval.call(window, code); // FIXME use a new scope. + if (code.trim() === "") { + return; + } + const [result, errInfo] = libdeno.evalContext(code); + if (!errInfo) { console.log(result); - } catch (err) { - if (err instanceof Error) { - console.error(`${err.constructor.name}: ${err.message}`); + } else { + if (errInfo.isNativeError) { + const formattedError = formatError( + libdeno.errorToJSON(errInfo.thrown as Error)); + console.error(formattedError); } else { - console.error("Thrown:", err); + console.error("Thrown:", errInfo.thrown); } } } |