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



commit e9c3e6793f1d74d68ae99fa978009140e0fa8086
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 ++-----
 modules/system.cpp |    2 +-
 5 files changed, 14 insertions(+), 18 deletions(-)
---
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 3b832da..189a855 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -57,7 +57,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)
 {
@@ -75,8 +75,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/modules/system.cpp b/modules/system.cpp
index 4b52b2c..cea6ea3 100644
--- a/modules/system.cpp
+++ b/modules/system.cpp
@@ -107,7 +107,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;
 }


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