[gjs] arg: Use JS_Enumerate to find hash table props
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] arg: Use JS_Enumerate to find hash table props
- Date: Tue, 1 Nov 2016 23:08:26 +0000 (UTC)
commit c631351eb66260b4ad373442917f624f53dc7641
Author: Philip Chimento <philip endlessm com>
Date: Mon Oct 31 18:27:37 2016 -0700
arg: Use JS_Enumerate to find hash table props
As mentioned in a Mozilla bug [1], JS_NewPropertyIterator does not work
correctly on indexed properties. Indeed, during the tests that are
currently commented out, the 0 value would cause the iterator to return
JSID_VOID and stop.
The recommended replacement is JS_Enumerate, which correctly includes
indexed properties.
Unfortunately this does not fix any of the broken tests by itself, but it
is a prerequisite.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1081660
https://bugzilla.gnome.org/show_bug.cgi?id=773763
gi/arg.cpp | 19 ++++++-------------
1 files changed, 6 insertions(+), 13 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index bc46a13..87e68f8 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -336,6 +336,7 @@ gjs_object_to_g_hash(JSContext *context,
GHashTable **hash_p)
{
GHashTable *result = NULL;
+ size_t id_ix, id_len;
g_assert(hash_value.isObjectOrNull());
JS::RootedObject props(context, hash_value.toObjectOrNull());
@@ -355,12 +356,8 @@ gjs_object_to_g_hash(JSContext *context,
transfer = GI_TRANSFER_NOTHING;
}
- JS::RootedObject iter(context, JS_NewPropertyIterator(context, props));
- if (iter == NULL)
- return false;
-
- JS::RootedId prop_id(context);
- if (!JS_NextProperty(context, iter, prop_id.address()))
+ JS::AutoIdArray ids(context, JS_Enumerate(context, props));
+ if (!ids)
return false;
/* Don't use key/value destructor functions here, because we can't
@@ -369,10 +366,10 @@ gjs_object_to_g_hash(JSContext *context,
result = g_hash_table_new(g_str_hash, g_str_equal);
JS::RootedValue key_js(context), val_js(context);
- while (!JSID_IS_VOID(prop_id)) {
+ for (id_ix = 0, id_len = ids.length(); id_ix < id_len; id_ix++) {
GArgument key_arg = { 0 }, val_arg = { 0 };
- if (!JS_IdToValue(context, prop_id, key_js.address()))
+ if (!JS_IdToValue(context, ids[id_ix], key_js.address()))
goto free_hash_and_fail;
/* Type check key type. */
@@ -383,7 +380,7 @@ gjs_object_to_g_hash(JSContext *context,
&key_arg))
goto free_hash_and_fail;
- if (!JS_GetPropertyById(context, props, prop_id, val_js.address()))
+ if (!JS_GetPropertyById(context, props, ids[id_ix], val_js.address()))
goto free_hash_and_fail;
/* Type check and convert value to a c type */
@@ -395,10 +392,6 @@ gjs_object_to_g_hash(JSContext *context,
goto free_hash_and_fail;
g_hash_table_insert(result, key_arg.v_pointer, val_arg.v_pointer);
-
- prop_id = JSID_VOID;
- if (!JS_NextProperty(context, iter, prop_id.address()))
- goto free_hash_and_fail;
}
*hash_p = result;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]