[gjs: 2/18] arg: Only accept object in gjs_object_to_g_hash()




commit f2776afd3bc75cc40379ba2c69229cb740e3f1ef
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Nov 23 11:07:50 2020 -0800

    arg: Only accept object in gjs_object_to_g_hash()
    
    Since we already know the input must be an object, there's no need to pass
    it around as a JS::Value.

 gi/arg.cpp | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 59d231b4..229cc663 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -613,18 +613,13 @@ template <typename T>
 }
 
 GJS_JSAPI_RETURN_CONVENTION
-static bool
-gjs_object_to_g_hash(JSContext   *context,
-                     JS::Value    hash_value,
-                     GITypeInfo  *key_param_info,
-                     GITypeInfo  *val_param_info,
-                     GITransfer   transfer,
-                     GHashTable **hash_p)
-{
+static bool gjs_object_to_g_hash(JSContext* context, JS::HandleObject props,
+                                 GITypeInfo* key_param_info,
+                                 GITypeInfo* val_param_info,
+                                 GITransfer transfer, GHashTable** hash_p) {
     size_t id_ix, id_len;
 
-    g_assert(hash_value.isObjectOrNull());
-    JS::RootedObject props(context, hash_value.toObjectOrNull());
+    g_assert(props && "Property bag cannot be null");
 
     if (transfer == GI_TRANSFER_CONTAINER) {
         if (type_needs_release (key_param_info, g_type_info_get_tag(key_param_info)) ||
@@ -1784,12 +1779,9 @@ bool gjs_value_to_g_argument(JSContext* context, JS::HandleValue value,
             g_assert(key_param_info != nullptr);
             g_assert(val_param_info != nullptr);
 
-            if (!gjs_object_to_g_hash(context,
-                                      value,
-                                      key_param_info,
-                                      val_param_info,
-                                      transfer,
-                                      &ghash)) {
+            JS::RootedObject props(context, &value.toObject());
+            if (!gjs_object_to_g_hash(context, props, key_param_info,
+                                      val_param_info, transfer, &ghash)) {
                 return false;
             }
 


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