fix sendmessage

This commit is contained in:
2026-02-25 16:24:08 -06:00
parent fc36707b39
commit 01637c49b0
2 changed files with 49 additions and 4 deletions

View File

@@ -648,6 +648,24 @@ JSC_CCALL(socket_getsockopt,
return JS_NewInt32(js, optval);
)
JSC_CCALL(socket_send_self,
if (argc < 1 || !JS_IsText(argv[0]))
return JS_RaiseDisrupt(js, "send_self: expects a text argument");
const char *msg = JS_ToCString(js, argv[0]);
WotaBuffer wb;
wota_buffer_init(&wb, 16);
wota_write_record(&wb, 1);
wota_write_text(&wb, "text");
wota_write_text(&wb, msg);
JS_FreeCString(js, msg);
const char *err = JS_SendMessage(js, &wb);
if (err) {
wota_buffer_free(&wb);
return JS_RaiseDisrupt(js, "send_self failed: %s", err);
}
return JS_NULL;
)
static const JSCFunctionListEntry js_socket_funcs[] = {
MIST_FUNC_DEF(socket, getaddrinfo, 3),
MIST_FUNC_DEF(socket, socket, 3),
@@ -670,6 +688,7 @@ static const JSCFunctionListEntry js_socket_funcs[] = {
MIST_FUNC_DEF(socket, unwatch, 1),
MIST_FUNC_DEF(socket, setnonblock, 1),
MIST_FUNC_DEF(socket, getsockopt, 3),
MIST_FUNC_DEF(socket, send_self, 1),
};
JSValue js_core_socket_use(JSContext *js) {