Implement the rest of the endpoints that were already mostly C in C.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4727 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-02 23:26:42 +00:00
parent 549d7ffec8
commit 7516524d69
5 changed files with 104 additions and 24 deletions

View File

@ -862,14 +862,13 @@ static void _tf_backtrace_error(void* data, const char* message, int error)
JS_SetPropertyUint32(bt->context, bt->array, bt->count++, entry);
}
static JSValue _tf_task_getDebug(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
char* tf_task_get_debug(tf_task_t* task)
{
tf_task_t* task = JS_GetContextOpaque(context);
tf_trace_begin(task->_trace, __func__);
JSValue result = JS_NewObject(context);
JSContext* context = task->_context;
JSValue object = JS_NewObject(context);
JSValue promises = JS_NewArray(context);
JS_SetPropertyStr(context, result, "promises", promises);
JS_SetPropertyStr(context, object, "promises", promises);
int j = 0;
for (int i = 0; i < task->_promise_stack_count; i++)
{
@ -901,35 +900,56 @@ static JSValue _tf_task_getDebug(JSContext* context, JSValueConst this_val, int
JS_SetPropertyUint32(context, promises, j++, entry);
}
}
JSValue json = JS_JSONStringify(context, object, JS_NULL, JS_NewInt32(context, 2));
const char* string = JS_ToCString(context, json);
char* result = tf_strdup(string);
JS_FreeCString(context, string);
JS_FreeValue(context, json);
JS_FreeValue(context, object);
tf_trace_end(task->_trace);
return result;
}
static JSValue _tf_task_getHitches(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
char* tf_task_get_hitches(tf_task_t* task)
{
tf_task_t* task = JS_GetContextOpaque(context);
JSContext* context = task->_context;
tf_trace_begin(task->_trace, __func__);
JSValue result = JS_NewObject(context);
JSValue object = JS_NewObject(context);
for (int i = 0; i < (int)_countof(task->hitches); i++)
{
if (*task->hitches[i].name)
{
JS_SetPropertyStr(context, result, task->hitches[i].name, JS_NewFloat64(context, task->hitches[i].duration_ns / 1e9));
JS_SetPropertyStr(context, object, task->hitches[i].name, JS_NewFloat64(context, task->hitches[i].duration_ns / 1e9));
}
}
JSValue json = JS_JSONStringify(context, object, JS_NULL, JS_NewInt32(context, 2));
const char* string = JS_ToCString(context, json);
char* result = tf_strdup(string);
JS_FreeCString(context, string);
JS_FreeValue(context, json);
JS_FreeValue(context, object);
tf_trace_end(task->_trace);
return result;
}
static JSValue _tf_task_disconnectionsDebug(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
char* tf_task_get_disconnections(tf_task_t* task)
{
tf_task_t* task = JS_GetContextOpaque(context);
JSContext* context = task->_context;
tf_trace_begin(task->_trace, __func__);
JSValue result = tf_ssb_get_disconnection_debug(task->_ssb, context);
JSValue object = tf_ssb_get_disconnection_debug(task->_ssb, context);
JSValue json = JS_JSONStringify(context, object, JS_NULL, JS_NewInt32(context, 2));
const char* string = JS_ToCString(context, json);
char* result = tf_strdup(string);
JS_FreeCString(context, string);
JS_FreeValue(context, json);
JS_FreeValue(context, object);
tf_trace_end(task->_trace);
return result;
}
char* tf_task_get_debug(tf_task_t* task);
char* tf_task_get_hitches(tf_task_t* task);
static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{
tf_task_t* task = JS_GetContextOpaque(context);
@ -1704,10 +1724,6 @@ void tf_task_activate(tf_task_t* task)
}
JS_SetPropertyStr(context, global, "getStats", JS_NewCFunction(context, _tf_task_getStats, "getStats", 0));
JS_SetPropertyStr(context, global, "getDebug", JS_NewCFunction(context, _tf_task_getDebug, "getDebug", 0));
JS_SetPropertyStr(context, global, "getHitches", JS_NewCFunction(context, _tf_task_getHitches, "getHitches", 0));
JS_SetPropertyStr(context, global, "disconnectionsDebug", JS_NewCFunction(context, _tf_task_disconnectionsDebug, "disconnectionsDebug", 0));
}
else
{