MCPcopy Create free account
hub / github.com/buke/quickjs-go / js_worker_set_onmessage

Function js_worker_set_onmessage

deps/quickjs/quickjs-libc.c:4296–4329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4294}
4295
4296static JSValue js_worker_set_onmessage(JSContext *ctx, JSValueConst this_val,
4297 JSValueConst func)
4298{
4299 JSRuntime *rt = JS_GetRuntime(ctx);
4300 JSThreadState *ts = js_get_thread_state(rt);
4301 JSWorkerData *worker = JS_GetOpaque2(ctx, this_val, ts->worker_class_id);
4302 JSWorkerMessageHandler *port;
4303
4304 if (!worker)
4305 return JS_EXCEPTION;
4306
4307 port = worker->msg_handler;
4308 if (JS_IsNull(func)) {
4309 if (port) {
4310 js_free_port(rt, port);
4311 worker->msg_handler = NULL;
4312 }
4313 } else {
4314 if (!JS_IsFunction(ctx, func))
4315 return JS_ThrowTypeError(ctx, "not a function");
4316 if (!port) {
4317 port = js_mallocz(ctx, sizeof(*port));
4318 if (!port)
4319 return JS_EXCEPTION;
4320 port->recv_pipe = js_dup_message_pipe(worker->recv_pipe);
4321 port->on_message_func = JS_NULL;
4322 list_add_tail(&port->link, &ts->port_list);
4323 worker->msg_handler = port;
4324 }
4325 JS_FreeValue(ctx, port->on_message_func);
4326 port->on_message_func = JS_DupValue(ctx, func);
4327 }
4328 return JS_UNDEFINED;
4329}
4330
4331static JSValue js_worker_get_onmessage(JSContext *ctx, JSValueConst this_val)
4332{

Callers

nothing calls this directly

Calls 5

js_get_thread_stateFunction · 0.85
JS_IsNullFunction · 0.85
js_free_portFunction · 0.85
js_dup_message_pipeFunction · 0.85
list_add_tailFunction · 0.85

Tested by

no test coverage detected