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

@ -423,22 +423,17 @@ JSValue _task_invokeExport_internal(tf_taskstub_t* from, tf_task_t* to, exportid
JSValue arguments = tf_serialize_load(to, from, buffer, size);
JSValue* argument_array = NULL;
JSValue length_val = JS_GetPropertyStr(to->_context, arguments, "length");
int length;
JSValue this_val = JS_NULL;
if (JS_ToInt32(to->_context, &length, length_val) == 0)
int length = tf_util_get_length(to->_context, arguments);
if (length > 0)
{
if (length > 0)
{
this_val = JS_GetPropertyUint32(to->_context, arguments, 0);
argument_array = alloca(sizeof(JSValue) * (length - 1));
}
for (int i = 1; i < length; ++i)
{
argument_array[i - 1] = JS_GetPropertyUint32(to->_context, arguments, i);
}
this_val = JS_GetPropertyUint32(to->_context, arguments, 0);
argument_array = alloca(sizeof(JSValue) * (length - 1));
}
for (int i = 1; i < length; ++i)
{
argument_array[i - 1] = JS_GetPropertyUint32(to->_context, arguments, i);
}
JS_FreeValue(to->_context, length_val);
JSValue function = export->_function;
JSPropertyDescriptor desc = { 0 };