Minor cleanup.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3847 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-02-26 21:25:40 +00:00
parent 95f0b91a0e
commit 1bfa18b8d7

View File

@ -159,7 +159,6 @@ static JSValue _tf_task_trace(JSContext* context, JSValueConst this_val, int arg
static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static void _tf_task_sendPromiseMessage(tf_task_t* from, tf_taskstub_t* to, tf_task_message_t messageType, promiseid_t promise, JSValue result);
static void _tf_task_sendPromiseResolve(tf_task_t* from, tf_taskstub_t* to, promiseid_t promise, JSValue result); static void _tf_task_sendPromiseResolve(tf_task_t* from, tf_taskstub_t* to, promiseid_t promise, JSValue result);
static void _tf_task_sendPromiseReject(tf_task_t* from, tf_taskstub_t* to, promiseid_t promise, JSValue result); static void _tf_task_sendPromiseReject(tf_task_t* from, tf_taskstub_t* to, promiseid_t promise, JSValue result);
@ -498,7 +497,7 @@ static JSValue _invokeThen(JSContext* context, JSValueConst this_val, int argc,
tf_taskstub_t* to = _tf_task_get_stub(from, taskid); tf_taskstub_t* to = _tf_task_get_stub(from, taskid);
promiseid_t promiseid = 0; promiseid_t promiseid = 0;
JS_ToInt32(context, &promiseid, func_data[1]); JS_ToInt32(context, &promiseid, func_data[1]);
_tf_task_sendPromiseMessage(from, to, kResolvePromise, promiseid, argv[0]); tf_task_send_promise_message(from, to, kResolvePromise, promiseid, argv[0]);
return JS_DupValue(context, this_val); return JS_DupValue(context, this_val);
} }
@ -510,7 +509,7 @@ static JSValue _invokeCatch(JSContext* context, JSValueConst this_val, int argc,
tf_taskstub_t* to = _tf_task_get_stub(from, taskid); tf_taskstub_t* to = _tf_task_get_stub(from, taskid);
promiseid_t promiseid = 0; promiseid_t promiseid = 0;
JS_ToInt32(context, &promiseid, func_data[1]); JS_ToInt32(context, &promiseid, func_data[1]);
_tf_task_sendPromiseMessage(from, to, kRejectPromise, promiseid, argv[0]); tf_task_send_promise_message(from, to, kRejectPromise, promiseid, argv[0]);
return JS_DupValue(context, this_val); return JS_DupValue(context, this_val);
} }
@ -552,7 +551,7 @@ static void _tf_task_sendPromiseResolve(tf_task_t* from, tf_taskstub_t* to, prom
} }
else else
{ {
_tf_task_sendPromiseMessage(from, to, kResolvePromise, promise, result); tf_task_send_promise_message(from, to, kResolvePromise, promise, result);
} }
JS_FreeValue(from->_context, promiseType); JS_FreeValue(from->_context, promiseType);
} }
@ -568,23 +567,23 @@ static void _tf_task_sendPromiseReject(tf_task_t* from, tf_taskstub_t* to, promi
} }
else else
{ {
_tf_task_sendPromiseMessage(from, to, kRejectPromise, promise, result); tf_task_send_promise_message(from, to, kRejectPromise, promise, result);
} }
JS_FreeValue(from->_context, promiseType); JS_FreeValue(from->_context, promiseType);
} }
static void _tf_task_sendPromiseMessage(tf_task_t* from, tf_taskstub_t* to, tf_task_message_t messageType, promiseid_t promise, JSValue result) void tf_task_send_promise_message(tf_task_t* from, tf_taskstub_t* to, tf_task_message_t type, promiseid_t promise, JSValue payload)
{ {
if (to) if (to)
{ {
void* buffer; void* buffer;
size_t size; size_t size;
tf_serialize_store(from, to, &buffer, &size, result); tf_serialize_store(from, to, &buffer, &size, payload);
char* copy = (char*)malloc(sizeof(promise) + size); char* copy = (char*)malloc(sizeof(promise) + size);
memcpy(copy, &promise, sizeof(promise)); memcpy(copy, &promise, sizeof(promise));
memcpy(copy + sizeof(promise), buffer, size); memcpy(copy + sizeof(promise), buffer, size);
tf_packetstream_send(tf_taskstub_get_stream(to), messageType, copy, size + sizeof(promise)); tf_packetstream_send(tf_taskstub_get_stream(to), type, copy, size + sizeof(promise));
free(buffer); free(buffer);
free(copy); free(copy);
} }
@ -1686,11 +1685,6 @@ tf_task_t* tf_task_get(JSContext* context)
return JS_GetContextOpaque(context); return JS_GetContextOpaque(context);
} }
void tf_task_send_promise_message(tf_task_t* from, tf_taskstub_t* to, tf_task_message_t type, promiseid_t promise, JSValue payload)
{
_tf_task_sendPromiseMessage(from, to, type, promise, payload);
}
void tf_task_set_ssb_port(tf_task_t* task, int port) void tf_task_set_ssb_port(tf_task_t* task, int port)
{ {
task->_ssb_port = port; task->_ssb_port = port;