Skip to content
  • Philip Chimento's avatar
    js: Call JS_Init() and JS_ShutDown() · 6b25ce3b
    Philip Chimento authored
    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
    6b25ce3b