forked from cory/tildefriends
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:
36
src/ssb.c
36
src/ssb.c
@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user