[gjs/wip/ptomato/mozjs31: 23/24] WIP - JS_Init() and JS_ShutDown()



commit 0b11eab24c1056fef477b95480b4447af710bce1
Author: Philip Chimento <philip endlessm com>
Date:   Fri Nov 4 19:02:55 2016 -0700

    WIP - 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.
    
    The one place where this is not working yet is in the case where a
    garbage collection is going on when you call System.exit(). In that case,
    the GC thread crashes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751252

 configure.ac                 |    3 ++-
 gjs/console.cpp              |    4 ++++
 gjs/context.cpp              |   13 +++++++++++++
 gjs/context.h                |    3 +++
 installed-tests/gjs-unit.cpp |    4 ++++
 test/gjs-tests.cpp           |    2 ++
 6 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2ed2240..1cd9500 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,7 @@ common_packages="gthread-2.0 gio-2.0 >= glib_required_version mozjs-31"
 gjs_packages="gobject-introspection-1.0 libffi $common_packages"
 gjs_cairo_packages="cairo cairo-gobject $common_packages"
 gjs_gdbus_packages="$GOBJECT_REQUIREMENT gio-2.0"
+gjs_console_packages="$GOBJECT_REQUIREMENT $common_packages"
 gjs_gtk_packages="gtk+-3.0 >= 3.20"
 # gjs-tests links against everything
 gjstests_packages="gio-unix-2.0 $gjs_packages"
@@ -66,7 +67,7 @@ gjstests_packages="gio-unix-2.0 $gjs_packages"
 AX_PKG_CHECK_MODULES([GJS], [$GOBJECT_REQUIREMENT], [$gjs_packages])
 dnl These don't need to be put in the .pc file so use regular PKG_CHECK_MODULES
 PKG_CHECK_MODULES([GJS_GDBUS], [$gjs_gdbus_packages])
-PKG_CHECK_MODULES([GJS_CONSOLE], [$GOBJECT_REQUIREMENT])
+PKG_CHECK_MODULES([GJS_CONSOLE], [$gjs_console_packages])
 PKG_CHECK_MODULES([GJSTESTS], [$gjstests_packages])
 
 # Optional cairo dep (enabled by default)
diff --git a/gjs/console.cpp b/gjs/console.cpp
index d60840b..ba7f34e 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -29,6 +29,7 @@
 #include <gjs/gjs.h>
 
 #include "coverage.h"
+#include "jsapi-wrapper.h"
 
 static char **include_path = NULL;
 static char **coverage_prefixes = NULL;
@@ -242,6 +243,8 @@ main(int argc, char **argv)
     /* This should be removed after a suitable time has passed */
     check_script_args_for_stray_gjs_args(script_argc, script_argv);
 
+    gjs_init();
+
     js_context = (GjsContext*) g_object_new(GJS_TYPE_CONTEXT,
                                             "search-path", include_path,
                                             "program-name", program_name,
@@ -308,5 +311,6 @@ main(int argc, char **argv)
     g_strfreev(coverage_prefixes);
     g_object_unref(js_context);
     g_free(script);
+    gjs_shutdown();
     exit(code);
 }
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 682d00c..6089de1 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -794,3 +794,16 @@ gjs_get_import_global(JSContext *context)
     GjsContext *gjs_context = (GjsContext *) JS_GetContextPrivate(context);
     return gjs_context->global;
 }
+
+void
+gjs_init(void)
+{
+    if (!JS_Init())
+        g_error("Could not initialize Javascript");
+}
+
+void
+gjs_shutdown(void)
+{
+    JS_ShutDown();
+}
diff --git a/gjs/context.h b/gjs/context.h
index a459e5b..cf6c55d 100644
--- a/gjs/context.h
+++ b/gjs/context.h
@@ -76,6 +76,9 @@ void            gjs_context_maybe_gc              (GjsContext  *context);
 
 void            gjs_context_gc                    (GjsContext  *context);
 
+void gjs_init(void);
+void gjs_shutdown(void);
+
 void            gjs_dumpstack                     (void);
 
 G_END_DECLS
diff --git a/installed-tests/gjs-unit.cpp b/installed-tests/gjs-unit.cpp
index 034273f..29b41ae 100644
--- a/installed-tests/gjs-unit.cpp
+++ b/installed-tests/gjs-unit.cpp
@@ -164,6 +164,8 @@ main(int argc, char **argv)
     setlocale(LC_ALL, "");
     g_test_init(&argc, &argv, NULL);
 
+    gjs_init();
+
     /* Make sure to create the GjsContext class first, so we
      * can override the GjsPrivate lookup path.
      */
@@ -218,5 +220,7 @@ main(int argc, char **argv)
 
     g_type_class_unref (context_class);
 
+    gjs_shutdown();
+
     return retval;
 }
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index 161d0a5..0094f3c 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -242,7 +242,9 @@ main(int    argc,
     gjs_test_add_tests_for_coverage ();
     gjs_test_add_tests_for_parse_call_args();
 
+    gjs_init();
     g_test_run();
+    gjs_shutdown();
 
     return 0;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]