[gjs/wip/ptomato/mozjs31: 16/21] object: Use PersistentRooted in object_init_list



commit a81f5ba027c577fce688734fdae073fd8e8486bf
Author: Philip Chimento <philip endlessm com>
Date:   Wed Nov 2 18:00:47 2016 -0700

    object: Use PersistentRooted in object_init_list
    
    Previously using JS_AddObjectRoot and JS_RemoveObjectRoot to keep objects
    alive from the time that the JS Object is created until the GObject
    instance_init function runs. Now we have JS::PersistentRootedObject which
    accomplishes the same thing but with a cleaner API.
    
    (The API of JS_AddObjectRoot and friends changes in mozjs31 to take only
    JS::Heap-wrapped objects, so it had to change one way or the other.)

 gi/object.cpp |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 4db226d..bf7a176 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1245,10 +1245,8 @@ object_instance_init (JSContext                  *context,
        down.
     */
     if (g_type_get_qdata(gtype, gjs_is_custom_type_quark())) {
-        // COMPAT: Replace with JS::PersistentRootedObject in mozjs31
-        object_init_list = g_slist_prepend(object_init_list, object.get());
-        JS_AddNamedObjectRoot(context, (JSObject **) &object_init_list->data,
-                              "object_init_list");
+        object_init_list = g_slist_prepend(object_init_list,
+            new JS::PersistentRootedObject(context, object));
     }
 
     gobj = (GObject*) g_object_newv(gtype, params.size(), &params[0]);
@@ -2584,7 +2582,8 @@ gjs_object_custom_init(GTypeInstance *instance,
     gjs_context = gjs_context_get_current();
     context = (JSContext*) gjs_context_get_native_context(gjs_context);
 
-    JS::RootedObject object(context, (JSObject*) object_init_list->data);
+    auto list_data = static_cast<JS::PersistentRootedObject *>(object_init_list->data);
+    JS::RootedObject object(context, list_data->get());
     priv = (ObjectInstance*) JS_GetPrivate(object);
 
     if (priv->gtype != G_TYPE_FROM_INSTANCE (instance)) {
@@ -2594,7 +2593,7 @@ gjs_object_custom_init(GTypeInstance *instance,
         return;
     }
 
-    JS_RemoveObjectRoot(context, (JSObject **) &object_init_list->data);
+    delete list_data;
     object_init_list = g_slist_delete_link(object_init_list,
                                            object_init_list);
 


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