[gjs/wip/ptomato/mozjs31: 2/3] js: Call JS_Init() and JS_ShutDown()
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs31: 2/3] js: Call JS_Init() and JS_ShutDown()
- Date: Tue, 15 Nov 2016 00:56:59 +0000 (UTC)
commit 3146cc13c3cc73f4b1649e89319ce0e2422b929e
Author: Philip Chimento <philip endlessm com>
Date: Fri Nov 4 19:02:55 2016 -0700
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 makes two new public functions in the API which do the necessary
initialization and shutdown, because gnome-shell will need to call them
as well.
https://bugzilla.gnome.org/show_bug.cgi?id=751252
gjs/console.cpp | 3 +++
gjs/context.cpp | 13 +++++++++++++
gjs/context.h | 3 +++
installed-tests/gjs-unit.cpp | 4 ++++
test/gjs-tests.cpp | 2 ++
5 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index d60840b..e2bd3a1 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -242,6 +242,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 +310,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 6ba8124..76a95af 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -819,3 +819,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]