mmomtchev / swig

This is SWIG JavaScript Evolution, a fork of the SWIG project with modern JavaScript/TypeScript support including WASM and async
http://www.swig.org
Other
7 stars 0 forks source link

Throwing in `out` typemaps results in uncatchable exceptions when using async mode #17

Closed mmomtchev closed 5 months ago

mmomtchev commented 5 months ago

The following out typemap throws an uncatchable exception in async mode - it is executed from the event loop with no javascript on the stack.

%typemap(out) Foo* trigger_internal_swig_exception
{
  TYPEMAP_OUT_INIT
  if ($1 == NULL) {
    SWIG_exception(SWIG_RuntimeError, "Let's see how the bindings manage this exception!");
#ifdef SWIG_fail
    SWIG_fail;
#endif
  }
  $1 = NULL;
  $result = VOID_Object;
}

The correct behavior would be to reject the promise.