On Wed, Sep 3, 2025 at 6:09 AM John Dallman <[email protected]> wrote:

> I'm porting a math library and its test harness to WebAssembly. The test
> harness is allowed to be specific to Node.js, but the library is not. Both
> are compiled from C and C++ code, which is my comfort zone. JavaScript is a
> language I don't know well and haven't done anything difficult in.
>
> I'm aware that WASI doesn't support traditional signals
> <https://github.com/WebAssembly/WASI/issues/166>. At present, when I
> intentionally set off an access violation, I get "RuntimeError: memory
> access out of bounds" and a traceback as Node.js exits.
>
> Is there a way to catch these errors and prevent Node.js exiting? Ideally,
> I'd be able to notify the test harness in some way that this had happened.
> If this involves JavaScript, please explain slowly and gently: I'm from the
> C world and new to web applications.
>

Is the test harness and the library-under-test designed to be compiled into
the same executable?    i.e. on other platforms does it somehow catch and
recover from sefaults?

>From the JS side you basically have two choice:

1. Wrap your calls in a JS try/catch and inspect the exception you caught
and then (somehow?) continue with the test suite.  (This is what Brooke
suggested already)
2. Install a global `onerror` handler that will catch all exceptions (much
like the global signal handler on linux).  See
https://nodejs.org/api/process.html#event-uncaughtexception.

I suppose in either the case the tricky part is going to be continuing the
test suite where you left off.   How does that work in the native case?



>
> The reason I'm asking this is that I will have to provide support to
> customers when the WebAssembly version of the library is released, and
> prefer to have my answers ready ahead of time. My employer wants to
> maintain their good reputation for customer service, and goes as far as
> having tests for deliberately-set-off runtime errors as part of routine
> testing, so that we can document what happens and how to handle them.
>
> Thanks very much,
>
> John
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/emscripten-discuss/CAH1xqgnMY0%2BoOLMs51mo2x%2BBUhWdZq%3DkxFp-En7AX3OsVqcoQQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/emscripten-discuss/CAH1xqgnMY0%2BoOLMs51mo2x%2BBUhWdZq%3DkxFp-En7AX3OsVqcoQQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAL_va294N3hjD7ihiDiUNKx5nHMo%2BRNK4y%3D4nPp4Yh-282DFnA%40mail.gmail.com.

Reply via email to