[gjs: 7/8] boxed: Remove unnecessary roots



commit 268aa33ecb47116c8d15848a2cde674daa20207b
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat May 26 18:52:14 2018 -0700

    boxed: Remove unnecessary roots

 gi/boxed.cpp | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 05f60dc1..228ff23c 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -268,7 +268,6 @@ boxed_init_from_props(JSContext   *context,
         priv->field_map = get_field_map(priv->info);
 
     JS::RootedValue value(context);
-    JS::RootedId prop_id(context);
     for (ix = 0, length = ids.length(); ix < length; ix++) {
         GIFieldInfo *field_info;
         GjsAutoJSChar name;
@@ -285,9 +284,9 @@ boxed_init_from_props(JSContext   *context,
 
         /* ids[ix] is reachable because props is rooted, but require_property
          * doesn't know that */
-        prop_id = ids[ix];
         if (!gjs_object_require_property(context, props, "property list",
-                                         prop_id, &value))
+                                         JS::HandleId::fromMarkedLocation(ids[ix].address()),
+                                         &value))
             return false;
 
         if (!boxed_set_field_from_value(context, priv, field_info, value))
@@ -366,15 +365,14 @@ boxed_new(JSContext             *context,
     } else if (priv->can_allocate_directly) {
         boxed_new_direct(priv);
     } else if (priv->default_constructor >= 0) {
-        bool retval;
-
-        /* for simplicity, we simply delegate all the work to the actual JS constructor
-           function (which we retrieve from the JS constructor, that is, Namespace.BoxedType,
-           or object.constructor, given that object was created with the right prototype */
-        JS::RootedId default_constructor_name(context, priv->default_constructor_name);
-        retval = boxed_invoke_constructor(context, obj,
-                                          default_constructor_name, args);
-        return retval;
+        /* for simplicity, we simply delegate all the work to the actual JS
+         * constructor function (which we retrieve from the JS constructor,
+         * that is, Namespace.BoxedType, or object.constructor, given that
+         * object was created with the right prototype. The ID is traced from
+         * the object, so it's OK to create a handle from it. */
+        return boxed_invoke_constructor(context, obj,
+            JS::HandleId::fromMarkedLocation(priv->default_constructor_name.address()),
+            args);
     } else {
         gjs_throw(context, "Unable to construct struct type %s since it has no default constructor and 
cannot be allocated directly",
                   g_base_info_get_name((GIBaseInfo*) priv->info));


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