Clean up failed callbacks.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3706 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-12-27 21:48:16 +00:00
parent 05b55c849a
commit 2e1b0089ae
3 changed files with 26 additions and 7 deletions

View File

@ -491,7 +491,10 @@ static void _tf_ssb_on_message_added_callback(tf_ssb_t* ssb, const char* id, voi
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
JSValue string = JS_NewString(context, id);
JSValue response = JS_Call(context, callback, JS_UNDEFINED, 1, &string);
tf_util_report_error(context, response);
if (tf_util_report_error(context, response))
{
tf_ssb_remove_message_added_callback(ssb, _tf_ssb_on_message_added_callback, user_data);
}
JS_FreeValue(context, response);
JS_FreeValue(context, string);
}
@ -502,7 +505,10 @@ static void _tf_ssb_on_blob_want_added_callback(tf_ssb_t* ssb, const char* id, v
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
JSValue string = JS_NewString(context, id);
JSValue response = JS_Call(context, callback, JS_UNDEFINED, 1, &string);
tf_util_report_error(context, response);
if (tf_util_report_error(context, response))
{
tf_ssb_remove_blob_want_added_callback(ssb, _tf_ssb_on_blob_want_added_callback, user_data);
}
JS_FreeValue(context, response);
JS_FreeValue(context, string);
}
@ -525,7 +531,10 @@ static void _tf_ssb_on_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change
object,
};
response = JS_Call(context, callback, JS_UNDEFINED, 2, args);
tf_util_report_error(context, response);
if (tf_util_report_error(context, response))
{
tf_ssb_remove_connections_changed_callback(ssb, _tf_ssb_on_connections_changed_callback, user_data);
}
JS_FreeValue(context, args[0]);
JS_FreeValue(context, object);
}
@ -539,7 +548,10 @@ static void _tf_ssb_on_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change
object,
};
response = JS_Call(context, callback, JS_UNDEFINED, 2, args);
tf_util_report_error(context, response);
if (tf_util_report_error(context, response))
{
tf_ssb_remove_connections_changed_callback(ssb, _tf_ssb_on_connections_changed_callback, user_data);
}
JS_FreeValue(context, args[0]);
JS_FreeValue(context, object);
}
@ -554,7 +566,10 @@ static void _tf_ssb_on_broadcasts_changed_callback(tf_ssb_t* ssb, void* user_dat
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
JSValue argv = JS_UNDEFINED;
JSValue response = JS_Call(context, callback, JS_UNDEFINED, 1, &argv);
tf_util_report_error(context, response);
if (tf_util_report_error(context, response))
{
tf_ssb_remove_broadcasts_changed_callback(_tf_ssb_on_connections_changed_callback, user_data);
}
JS_FreeValue(context, response);
}