mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Simplify eval_and_print code in REPL
We always use async eval. Also clean up some console.log usage since we use std.puts all across.
This commit is contained in:
parent
b1dc19c4f7
commit
06175d1e0c
2 changed files with 14 additions and 20 deletions
BIN
gen/repl.c
BIN
gen/repl.c
Binary file not shown.
34
repl.js
34
repl.js
|
@ -1549,29 +1549,21 @@ import * as bjson from "bjson";
|
||||||
}
|
}
|
||||||
mexpr = "";
|
mexpr = "";
|
||||||
|
|
||||||
eval_and_print_start(expr, true);
|
eval_and_print(expr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function eval_and_print_start(expr, is_async) {
|
function eval_and_print(expr) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
try {
|
if (use_strict)
|
||||||
if (use_strict)
|
expr = '"use strict"; void 0;' + expr;
|
||||||
expr = '"use strict"; void 0;' + expr;
|
eval_start_time = os.now();
|
||||||
eval_start_time = os.now();
|
/* eval as a script */
|
||||||
/* eval as a script */
|
result = std.evalScript(expr, { backtrace_barrier: true, async: true });
|
||||||
result = std.evalScript(expr, { backtrace_barrier: true, async: is_async });
|
/* result is a promise */
|
||||||
if (is_async) {
|
result.then(print_eval_result, print_eval_error);
|
||||||
/* result is a promise */
|
|
||||||
result.then(print_eval_result, print_eval_error);
|
|
||||||
} else {
|
|
||||||
print_eval_result({ value: result });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
print_eval_error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_eval_result(result) {
|
function print_eval_result(result) {
|
||||||
|
@ -1587,13 +1579,15 @@ import * as bjson from "bjson";
|
||||||
function print_eval_error(error) {
|
function print_eval_error(error) {
|
||||||
std.puts(colors[styles.error]);
|
std.puts(colors[styles.error]);
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
console.log(error);
|
std.puts(error);
|
||||||
|
std.puts('\n');
|
||||||
if (error.stack) {
|
if (error.stack) {
|
||||||
std.puts(error.stack);
|
std.puts(error.stack);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std.puts("Throw: ");
|
std.puts("Throw: ");
|
||||||
console.log(error);
|
std.puts(error);
|
||||||
|
std.puts('\n');
|
||||||
}
|
}
|
||||||
std.puts(colors.none);
|
std.puts(colors.none);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue