core: Add a helper for getting a property by string as a string. I've typed this too much.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 9m15s

This commit is contained in:
2025-12-06 14:04:27 -05:00
parent 3a3b889196
commit d84b06f814
5 changed files with 81 additions and 46 deletions

View File

@@ -125,9 +125,7 @@ static void _tf_ssb_rpc_blobs_get(tf_ssb_connection_t* connection, uint8_t flags
}
else
{
JSValue key = JS_GetPropertyStr(context, arg, "key");
id = JS_ToCString(context, key);
JS_FreeValue(context, key);
id = tf_util_get_property_as_string(context, arg, "key");
}
blobs_get_work_t* work = tf_malloc(sizeof(blobs_get_work_t));
@@ -313,25 +311,20 @@ static void _tf_ssb_rpc_tunnel_callback(tf_ssb_connection_t* connection, uint8_t
tf_ssb_connection_remove_request(connection, request_number);
JSContext* context = tf_ssb_connection_get_context(connection);
JSValue message_val = JS_GetPropertyStr(context, args, "message");
JSValue stack_val = JS_GetPropertyStr(context, args, "stack");
const char* message_string = tf_util_get_property_as_string(context, args, "message");
const char* stack_string = tf_util_get_property_as_string(context, args, "stack");
char buffer[1024];
if (!JS_IsUndefined(message_val))
if (message_string)
{
const char* message_string = JS_ToCString(context, message_val);
const char* stack_string = JS_ToCString(context, stack_val);
snprintf(buffer, sizeof(buffer), "Error from tunnel: %s\n%s", message_string, stack_string);
JS_FreeCString(context, message_string);
JS_FreeCString(context, stack_string);
}
else
{
snprintf(buffer, sizeof(buffer), "Error from tunnel: %.*s", (int)size, message);
}
JS_FreeValue(context, stack_val);
JS_FreeValue(context, message_val);
JS_FreeCString(context, message_string);
JS_FreeCString(context, stack_string);
}
else
{
@@ -762,8 +755,7 @@ static void _tf_ssb_rpc_connection_room_attendants_callback(
{
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
JSContext* context = tf_ssb_get_context(ssb);
JSValue type = JS_GetPropertyStr(context, args, "type");
const char* type_string = JS_ToCString(context, type);
const char* type_string = tf_util_get_property_as_string(context, args, "type");
if (!type_string)
{
tf_ssb_connection_rpc_send_error(connection, flags, -request_number, "Missing type.");
@@ -788,25 +780,21 @@ static void _tf_ssb_rpc_connection_room_attendants_callback(
}
else if (strcmp(type_string, "joined") == 0)
{
JSValue id = JS_GetPropertyStr(context, args, "id");
const char* id_string = JS_ToCString(context, id);
const char* id_string = tf_util_get_property_as_string(context, args, "id");
if (id_string)
{
tf_ssb_connection_add_room_attendant(connection, id_string);
}
JS_FreeCString(context, id_string);
JS_FreeValue(context, id);
}
else if (strcmp(type_string, "left") == 0)
{
JSValue id = JS_GetPropertyStr(context, args, "id");
const char* id_string = JS_ToCString(context, id);
const char* id_string = tf_util_get_property_as_string(context, args, "id");
if (id_string)
{
tf_ssb_connection_remove_room_attendant(connection, id_string);
}
JS_FreeCString(context, id_string);
JS_FreeValue(context, id);
}
else
{
@@ -815,20 +803,17 @@ static void _tf_ssb_rpc_connection_room_attendants_callback(
tf_ssb_connection_rpc_send_error(connection, flags, -request_number, buffer);
}
JS_FreeCString(context, type_string);
JS_FreeValue(context, type);
}
static bool _is_error(JSContext* context, JSValue message)
{
JSValue name = JS_GetPropertyStr(context, message, "name");
const char* name_string = JS_ToCString(context, name);
const char* name_string = tf_util_get_property_as_string(context, message, "name");
bool is_error = false;
if (name_string && strcmp(name_string, "Error") == 0)
{
is_error = true;
}
JS_FreeCString(context, name_string);
JS_FreeValue(context, name);
return is_error;
}
@@ -1937,12 +1922,10 @@ static void _tf_ssb_rpc_invite_use(tf_ssb_connection_t* connection, uint8_t flag
JSContext* context = tf_ssb_connection_get_context(connection);
JSValue array = JS_GetPropertyStr(context, args, "args");
JSValue object = JS_GetPropertyUint32(context, array, 0);
JSValue feed = JS_GetPropertyStr(context, object, "feed");
tf_ssb_connection_get_id(connection, work->invite_public_key, sizeof(work->invite_public_key));
const char* id = JS_ToCString(context, feed);
const char* id = tf_util_get_property_as_string(context, object, "feed");
tf_string_set(work->id, sizeof(work->id), id);
JS_FreeCString(context, id);
JS_FreeValue(context, feed);
JS_FreeValue(context, object);
JS_FreeValue(context, array);
tf_ssb_connection_run_work(connection, _tf_ssb_rpc_invite_use_work, _tf_ssb_rpc_invite_use_after_work, work);