quickjs-ng / quickjs

QuickJS, the Next Generation: a mighty JavaScript engine
https://quickjs-ng.github.io/quickjs/
MIT License
998 stars 82 forks source link

qjs/std should report async failures via exit code #340

Closed bnoordhuis closed 1 month ago

bnoordhuis commented 6 months ago

Example: assert triggered from timer callback should exit with a non-zero error but doesn't. quickjs-libc.c calls js_std_dump_error() and trucks on.

$ build/qjs tests/test_std.js
Error: assertion failed: got |false|, expected |true|
    at assert (tests/test_std.js:21:51)
    at d (tests/test_std.js:287:33)

$ echo $?
0

Originally posted by @saghul in https://github.com/quickjs-ng/quickjs/issues/338#issuecomment-2032266845

saghul commented 6 months ago

While I see that there is currently no way to report the exceptions, what's annoying is I cannot reproduce the original issue, at least on macOS. It seems to repro all the time in the CI though. Any chance it's related to the timer source not being accurate enough since it's a virtualized environment?

bnoordhuis commented 6 months ago

quickjs only needs millisecond resolution. It seems sorta unlikely if perhaps not completely impossible that the timer source is too coarse.

Let me add some printf^Wconsole.log statements to see in what order the timeouts actually run.

chqrlie commented 6 months ago

quickjs only needs millisecond resolution. It seems sorta unlikely if perhaps not completely impossible that the timer source is too coarse.

ECMA only specifies millisecond resolution, but precise timings benefit from a finer resolution, at least microsecond if not nanosecond, so we should preserve a simple way to retrieve a precision clock. This however seems unrelated to the current issue.