[gjs/wip/ptomato/mozjs31: 19/25] object: Use PersistentRooted in object_init_list



commit d6d91a8b3011131c3964096882a923c09a9cfa70
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 |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 8e02283..0af0977 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1247,10 +1247,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]);
@@ -2597,7 +2595,7 @@ gjs_object_custom_init(GTypeInstance *instance,
         return;
     }
 
-    JS_RemoveObjectRoot(context, (JSObject **) &object_init_list->data);
+    delete (JS::PersistentRootedObject *) object_init_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]