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



commit 9359e0c9d71e7f407810bcdaec3dc858b826f056
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.

 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 0f27ad9..f746f5b 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1150,7 +1150,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)
 {
@@ -1180,7 +1180,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 f802361..699b65d 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -268,7 +268,7 @@ gjs_printerr(JSContext *context,
 }
 
 static void
-on_garbage_collect(JSRuntime *rt,
+on_garbage_collect(JSContext *cx,
                    JSGCStatus status,
                    void      *data)
 {
@@ -410,7 +410,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;
@@ -426,7 +426,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;
 
@@ -486,7 +486,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 */);
@@ -501,7 +500,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);
@@ -520,7 +519,8 @@ gjs_context_constructed(GObject *object)
         g_error("Failed to define properties on the global object");
 
     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);
 
     gjs_define_constructor_proxy_factory(js_context->context);
 
@@ -706,7 +706,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 ccfd6c8..85777bb 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -1697,9 +1697,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;
     }
@@ -1778,8 +1776,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 a8461a0..dca61c9 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -815,7 +815,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 1f3b5dc..c8e616a 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -50,7 +50,7 @@ test_obj_new(GjsRootingFixture *fx)
 }
 
 static void
-on_gc(JSRuntime *rt,
+on_gc(JSContext *cx,
       JSGCStatus status,
       void      *data)
 {
@@ -68,7 +68,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
@@ -83,7 +83,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]