diff options
author | Philip Chimento <philip@endlessm.com> | 2016-11-04 19:02:55 -0700 |
---|---|---|
committer | Philip Chimento <philip@endlessm.com> | 2016-12-09 19:44:36 -0800 |
commit | 6b25ce3b97b66494b1bba8275a6fe0b0830a94af (patch) | |
tree | db9b13ef6a3ae17fb3096312ab2709cbeee21c11 /gjs/console.cpp | |
parent | bee68349b9079021b6b0b6da6b8d38074b87b375 (diff) | |
download | gjs-6b25ce3b97b66494b1bba8275a6fe0b0830a94af.tar.gz |
js: Call JS_Init() and JS_ShutDown()
Starting with mozjs31, JS_Init() is required. Calling JS_ShutDown() on
exit is not required, but may become so in the future.
This does so in the constructor and destructor of a static object.
Normally this is discouraged because the order in which the constructors
and destructors are called is not guaranteed, but I don't think that is a
problem here since it's unlikely that anyone will try to use GJS API from
a static constructor.
However, API clients still must unref any GjsContext before the program
shuts down. Usually this is not a problem, unless a JS script calls
System.exit(), in which case the code would exit immediately without
unreffing the GjsContext before JS_ShutDown was called. Instead, we make
System.exit() throw an uncatchable exception, which is propagated all the
way up to JS::Evaluate() and turned into a GError with code
GJS_ERROR_SYSTEM_EXIT, thrown from gjs_context_eval().
For this, we need to expose GjsError and its error codes in the public
API. (They should have been exposed already, because gjs_context_eval()
could already throw GJS_ERROR_FAILED.)
Finally, the tests added as part of this patch made the testSystemExit
script obsolete.
https://bugzilla.gnome.org/show_bug.cgi?id=751252
Diffstat (limited to 'gjs/console.cpp')
-rw-r--r-- | gjs/console.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/gjs/console.cpp b/gjs/console.cpp index 1ebfe2ea..d9226655 100644 --- a/gjs/console.cpp +++ b/gjs/console.cpp @@ -286,8 +286,8 @@ main(int argc, char **argv) /* evaluate the script */ if (!gjs_context_eval(js_context, script, len, filename, &code, &error)) { - code = 1; - g_printerr("%s\n", error->message); + if (!g_error_matches(error, GJS_ERROR, GJS_ERROR_SYSTEM_EXIT)) + g_printerr("%s\n", error->message); g_clear_error(&error); goto out; } |