[gjs/wip/ptomato/mozjs52: 7/12] js: Replace JSRuntime APIs that now take JSContext



commit 6454ff147a0ec44f345fb6ac6455e95a86b71337
Author: Philip Chimento <philip chimento gmail com>
Date:   Tue May 2 22:00:03 2017 -0700

    js: Replace JSRuntime APIs that now take JSContext
    
    Many APIs that adapted to the removal of JSRuntime can be trivially
    replaced with JSContext without any other code changes.
    
    JS_AbortIfWrongThread() also takes JSContext instead of JSRuntime, but
    we only called it to check that we were creating a JSContext on the
    correct thread. Before creating the JSContext, there is no point in
    calling it, so remove it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784196

 gi/gtype.cpp              |    5 ++---
 gi/object.cpp             |    4 ++--
 gjs/context.cpp           |   14 +++++++-------
 gjs/coverage.cpp          |    7 ++-----
 gjs/jsapi-util.cpp        |    2 +-
 modules/system.cpp        |    2 +-
 test/gjs-test-rooting.cpp |    6 +++---
 7 files changed, 18 insertions(+), 22 deletions(-)
---
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index fe365fe..ac024b8 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -58,7 +58,7 @@ gjs_get_gtype_wrapper_quark(void)
 }
 
 static void
-update_gtype_weak_pointers(JSRuntime     *rt,
+update_gtype_weak_pointers(JSContext     *cx,
                            JSCompartment *compartment,
                            void          *data)
 {
@@ -76,8 +76,7 @@ static void
 ensure_weak_pointer_callback(JSContext *cx)
 {
     if (!weak_pointer_callback) {
-        JS_AddWeakPointerCompartmentCallback(JS_GetRuntime(cx),
-                                             update_gtype_weak_pointers,
+        JS_AddWeakPointerCompartmentCallback(cx, update_gtype_weak_pointers,
                                              nullptr);
         weak_pointer_callback = true;
     }
diff --git a/gi/object.cpp b/gi/object.cpp
index c6c98af..1a1762d 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1128,7 +1128,7 @@ init_object_private (JSContext       *context,
 }
 
 static void
-update_heap_wrapper_weak_pointers(JSRuntime     *rt,
+update_heap_wrapper_weak_pointers(JSContext     *cx,
                                   JSCompartment *compartment,
                                   gpointer       data)
 {
@@ -1158,7 +1158,7 @@ static void
 ensure_weak_pointer_callback(JSContext *cx)
 {
     if (!weak_pointer_callback) {
-        JS_AddWeakPointerCompartmentCallback(JS_GetRuntime(cx),
+        JS_AddWeakPointerCompartmentCallback(cx,
                                              update_heap_wrapper_weak_pointers,
                                              nullptr);
         weak_pointer_callback = true;
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 899d58e..569b902 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -114,7 +114,7 @@ static GMutex contexts_lock;
 static GList *all_contexts = NULL;
 
 static void
-on_garbage_collect(JSRuntime *rt,
+on_garbage_collect(JSContext *cx,
                    JSGCStatus status,
                    void      *data)
 {
@@ -217,7 +217,7 @@ gjs_context_dispose(GObject *object)
          * that we may not have the JS_GetPrivate() to access the
          * context
          */
-        JS_GC(js_context->runtime);
+        JS_GC(js_context->context);
         JS_EndRequest(js_context->context);
 
         js_context->destroying = true;
@@ -233,7 +233,7 @@ gjs_context_dispose(GObject *object)
             js_context->auto_gc_id = 0;
         }
 
-        JS_RemoveExtraGCRootsTracer(js_context->runtime, gjs_context_tracer,
+        JS_RemoveExtraGCRootsTracer(js_context->context, gjs_context_tracer,
                                     js_context);
         js_context->global = NULL;
 
@@ -285,7 +285,6 @@ gjs_context_constructed(GObject *object)
 
     js_context->runtime = gjs_runtime_ref();
 
-    JS_AbortIfWrongThread(js_context->runtime);
     js_context->owner_thread = g_thread_self();
 
     js_context->context = JS_NewContext(js_context->runtime, 8192 /* stack chunk size */);
@@ -300,7 +299,7 @@ gjs_context_constructed(GObject *object)
 
     JS_BeginRequest(js_context->context);
 
-    JS_SetGCCallback(js_context->runtime, on_garbage_collect, js_context);
+    JS_SetGCCallback(js_context->context, on_garbage_collect, js_context);
 
     /* set ourselves as the private data */
     JS_SetContextPrivate(js_context->context, js_context);
@@ -329,7 +328,8 @@ gjs_context_constructed(GObject *object)
     JSAutoCompartment ac(js_context->context, global);
 
     new (&js_context->global) JS::Heap<JSObject *>(global);
-    JS_AddExtraGCRootsTracer(js_context->runtime, gjs_context_tracer, js_context);
+    JS_AddExtraGCRootsTracer(js_context->context, gjs_context_tracer,
+                             js_context);
 
     JS::RootedObject importer(js_context->context,
         gjs_create_root_importer(js_context->context, js_context->search_path ?
@@ -509,7 +509,7 @@ gjs_context_maybe_gc (GjsContext  *context)
 void
 gjs_context_gc (GjsContext  *context)
 {
-    JS_GC(context->runtime);
+    JS_GC(context->context);
 }
 
 /**
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index b5d1324..41fb681 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -1630,9 +1630,7 @@ bootstrap_coverage(GjsCoverage *coverage)
         }
 
         /* Add a tracer, as suggested by jdm on #jsapi */
-        JS_AddExtraGCRootsTracer(JS_GetRuntime(context),
-                                 coverage_statistics_tracer,
-                                 coverage);
+        JS_AddExtraGCRootsTracer(context, coverage_statistics_tracer, coverage);
 
         priv->coverage_statistics = coverage_statistics;
     }
@@ -1711,8 +1709,7 @@ gjs_clear_js_side_statistics_from_coverage_object(GjsCoverage *coverage)
 
         /* Remove GC roots trace after we've decomissioned the object
          * and no longer need it to be traced here. */
-        JS_RemoveExtraGCRootsTracer(JS_GetRuntime(js_context),
-                                    coverage_statistics_tracer,
+        JS_RemoveExtraGCRootsTracer(js_context, coverage_statistics_tracer,
                                     coverage);
 
         priv->coverage_statistics = NULL;
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 465b04f..48f71f4 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -709,7 +709,7 @@ gjs_gc_if_needed (JSContext *context)
          */
         if (rss_size > linux_rss_trigger) {
             linux_rss_trigger = (gulong) MIN(G_MAXULONG, rss_size * 1.25);
-            JS_GC(JS_GetRuntime(context));
+            JS_GC(context);
             last_gc_time = now;
         } else if (rss_size < (0.75 * linux_rss_trigger)) {
             /* If we've shrunk by 75%, lower the trigger */
diff --git a/modules/system.cpp b/modules/system.cpp
index 137b49c..d499758 100644
--- a/modules/system.cpp
+++ b/modules/system.cpp
@@ -131,7 +131,7 @@ gjs_gc(JSContext *context,
     JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
     if (!gjs_parse_call_args(context, "gc", argv, ""))
         return false;
-    JS_GC(JS_GetRuntime(context));
+    JS_GC(context);
     argv.rval().setUndefined();
     return true;
 }
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index 2ad199c..4e51f4a 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -52,7 +52,7 @@ test_obj_new(GjsRootingFixture *fx)
 }
 
 static void
-on_gc(JSRuntime *rt,
+on_gc(JSContext *cx,
       JSGCStatus status,
       void      *data)
 {
@@ -70,7 +70,7 @@ setup(GjsRootingFixture *fx,
       gconstpointer      unused)
 {
     gjs_unit_test_fixture_setup(PARENT(fx), unused);
-    JS_SetGCCallback(JS_GetRuntime(PARENT(fx)->cx), on_gc, fx);
+    JS_SetGCCallback(PARENT(fx)->cx, on_gc, fx);
 }
 
 static void
@@ -85,7 +85,7 @@ wait_for_gc(GjsRootingFixture *fx)
 {
     int count = g_atomic_int_get(&gc_counter);
 
-    JS_GC(JS_GetRuntime(PARENT(fx)->cx));
+    JS_GC(PARENT(fx)->cx);
 
     g_mutex_lock(&gc_lock);
     while (count == g_atomic_int_get(&gc_counter)) {


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