Fix catching all exceptions from std.evalScript

In case of a syntax error, the function throws syncrnonously.

I'll admit I wondered when Promise.try would be useful... I guess I know
now!

Fixes: https://github.com/quickjs-ng/quickjs/issues/720#issuecomment-2495961142
This commit is contained in:
Saúl Ibarra Corretgé 2024-11-25 08:57:13 +01:00
parent 61dae5d420
commit 9631492534
2 changed files with 21 additions and 22 deletions

Binary file not shown.

View file

@ -1561,8 +1561,7 @@ import * as bjson from "qjs:bjson";
expr = '"use strict"; void 0;' + expr;
eval_start_time = os.now();
/* eval as a script */
result = std.evalScript(expr, { backtrace_barrier: true, async: true });
/* result is a promise */
result = Promise.try(std.evalScript, expr, { backtrace_barrier: true, async: true });
result.then(print_eval_result, print_eval_error);
}