Add a helper for getting array length: tf_util_get_length.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3925 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-07-09 15:13:35 +00:00
parent 982b5817a2
commit 7f350a3d87
8 changed files with 86 additions and 102 deletions

View File

@ -4,6 +4,7 @@
#include "ssb.connections.h"
#include "ssb.db.h"
#include "trace.h"
#include "util.js.h"
#include <assert.h>
#include <base64c.h>
@ -1045,33 +1046,28 @@ static bool _tf_ssb_name_equals(JSContext* context, JSValue object, const char**
if (JS_IsArray(context, name))
{
int length;
JSValue lengthval = JS_GetPropertyStr(context, name, "length");
if (JS_ToInt32(context, &length, lengthval) == 0)
int length = tf_util_get_length(context, name);
for (int i = 0; i < length; i++)
{
for (int i = 0; i < length; i++)
if (!match[i])
{
if (!match[i])
{
result = false;
break;
}
JSValue element = JS_GetPropertyUint32(context, name, i);
const char* str = JS_ToCString(context, element);
if (!str || strcmp(str, match[i]) != 0)
{
result = false;
}
JS_FreeCString(context, str);
JS_FreeValue(context, element);
result = false;
break;
}
if (result && match[length])
JSValue element = JS_GetPropertyUint32(context, name, i);
const char* str = JS_ToCString(context, element);
if (!str || strcmp(str, match[i]) != 0)
{
result = false;
}
JS_FreeCString(context, str);
JS_FreeValue(context, element);
}
if (result && match[length])
{
result = false;
}
JS_FreeValue(context, lengthval);
}
else
{