[gjs/wip/ptomato/mozjs31: 2/3] WIP - destroy runtime



commit f580f645abba5d4b6001de6d7121f20f970238d8
Author: Philip Chimento <philip endlessm com>
Date:   Tue Nov 8 16:35:37 2016 -0800

    WIP - destroy runtime

 gjs/console.cpp              |    2 ++
 gjs/runtime.cpp              |    8 +++++++-
 gjs/runtime.h                |    2 ++
 installed-tests/gjs-unit.cpp |    2 ++
 test/gjs-tests.cpp           |    4 ++++
 5 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 0b4eef6..34cfe31 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -30,6 +30,7 @@
 
 #include "coverage.h"
 #include "jsapi-wrapper.h"
+#include "runtime.h"
 
 static char **include_path = NULL;
 static char **coverage_prefixes = NULL;
@@ -312,6 +313,7 @@ main(int argc, char **argv)
     g_strfreev(coverage_prefixes);
     g_object_unref(js_context);
     g_free(script);
+    gjs_destroy_runtime_for_current_thread();
     JS_ShutDown();
     exit(code);
 }
diff --git a/gjs/runtime.cpp b/gjs/runtime.cpp
index 6fd9467..05e51db 100644
--- a/gjs/runtime.cpp
+++ b/gjs/runtime.cpp
@@ -151,8 +151,8 @@ destroy_runtime(gpointer data)
     JSRuntime *runtime = (JSRuntime *) data;
     RuntimeData *rtdata = (RuntimeData *) JS_GetRuntimePrivate(runtime);
 
-    g_free(rtdata);
     JS_DestroyRuntime(runtime);
+    g_free(rtdata);
 }
 
 static GPrivate thread_runtime = G_PRIVATE_INIT(destroy_runtime);
@@ -246,3 +246,9 @@ gjs_runtime_for_current_thread(void)
 
     return runtime;
 }
+
+void
+gjs_destroy_runtime_for_current_thread(void)
+{
+    g_private_replace(&thread_runtime, NULL);
+}
diff --git a/gjs/runtime.h b/gjs/runtime.h
index 0900e28..914fdee 100644
--- a/gjs/runtime.h
+++ b/gjs/runtime.h
@@ -28,6 +28,8 @@
 
 JSRuntime * gjs_runtime_for_current_thread (void);
 
+void gjs_destroy_runtime_for_current_thread(void);
+
 bool        gjs_runtime_is_sweeping        (JSRuntime *runtime);
 
 #endif /* __GJS_RUNTIME_H__ */
diff --git a/installed-tests/gjs-unit.cpp b/installed-tests/gjs-unit.cpp
index 7f85cff..8251662 100644
--- a/installed-tests/gjs-unit.cpp
+++ b/installed-tests/gjs-unit.cpp
@@ -34,6 +34,7 @@
 
 #include "gjs/coverage.h"
 #include "gjs/mem.h"
+#include "gjs/runtime.h"
 
 typedef struct {
     const char *coverage_prefix;
@@ -105,6 +106,7 @@ teardown(GjsTestJSFixture *fix,
 
     gjs_memory_report("before destroying context", false);
     g_object_unref(fix->context);
+    gjs_destroy_runtime_for_current_thread();
     gjs_memory_report("after destroying context", true);
 }
 
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index cb96318..355fd52 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -29,6 +29,7 @@
 #include <gjs/context.h>
 #include "gjs/jsapi-util.h"
 #include "gjs/jsapi-wrapper.h"
+#include "gjs/runtime.h"
 #include "gjs-test-utils.h"
 
 static void
@@ -44,6 +45,8 @@ gjstest_test_func_gjs_context_construct_destroy(void)
 
     context = gjs_context_new ();
     g_object_unref (context);
+
+    gjs_destroy_runtime_for_current_thread();
 }
 
 static void
@@ -245,6 +248,7 @@ main(int    argc,
     if (!JS_Init())
         g_error("Could not initialize Javascript");
     g_test_run();
+    gjs_destroy_runtime_for_current_thread();
     JS_ShutDown();
 
     return 0;


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