Skip to content
Commit c7bdcaab authored by Philip Chimento's avatar Philip Chimento Committed by Philip Chimento
Browse files

function: Perform dirty exit at FFI boundary

If an "uncatchable" (SpiderMonkey term) exception is thrown (that is,
return false from a JSAPI call without an exception pending on the
JSContext), then we have to deal with the condition when returning back
to C code. We use the uncatchable exception mechanism to implement
System.exit(), and so gjs_context_eval() checks for this and exits if
appropriate.

However, when calling System.exit() inside a callback marshalled by FFI,
the uncatchable exception propagates up to gjs_callback_closure() and
stopes there. There is nothing that can propagate the exception after
that point. There may be one or more main loops running, and until they
exit, we don't even get back to our JSAPI code that will propagate the
exception up to gjs_context_eval().

Therefore, we do a "dirty exit" (our term) if an FFI callback throws an
uncatchable exception. This will, unfortunately, trip an assertion if
SpiderMonkey is compiled in debug mode, because we haven't cleaned up the
JSContext by the time the JSRuntime is destroyed when the thread exits.
We can't clean up the JSContext, either, because the caller of
gjs_context_eval() is still holding a request on the JSContext so if we
did that we would trip a different assertion.

This SpiderMonkey limitation is reflected in the added test, whereby the
test will still pass if the script exits with any nonzero code, which
covers the debug-mode case where we fail the assertion.

https://bugzilla.gnome.org/show_bug.cgi?id=779692
parent 63c9c5c4
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment