run-test: Always use returned status code if possible
gjs_context_eval_module_file() is a convenience method for - register the module (load and parse) - evaluate the module (run) The first can fail, but has no notion of status code; the second will always set a valid code if provided (either as returned by the module, or set by gjs itself). Doing those two steps separately allows us to explicitly handle failures to register the module, so that we can then return the original status code from evaluating the module. That means that if evaluating the module "fails" with a `GJS_ERROR_SYSTEM_EXIT` error (because it was terminated with `System.exit()`), we now return the correct status code instead of `EXIT_FAILURE`. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3599>
This commit is contained in:
parent
d192fc984f
commit
546f3d65f7
@ -41,10 +41,20 @@ eval_module (GjsContext *js_context,
|
||||
const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (GFile) file = NULL;
|
||||
g_autofree char *uri = NULL;
|
||||
uint8_t code;
|
||||
bool success = gjs_context_eval_module_file (js_context, filename, &code, error);
|
||||
if (!success)
|
||||
code = 1;
|
||||
|
||||
file = g_file_new_for_commandline_arg (filename);
|
||||
uri = g_file_get_uri (file);
|
||||
|
||||
if (!gjs_context_register_module (js_context, uri, uri, error))
|
||||
return 1;
|
||||
|
||||
if (!gjs_context_eval_module (js_context, uri, &code, error))
|
||||
{
|
||||
/* nothing, but avoid G_GNUC_WARN_UNUSED_RESULT compiler warnings */
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user