| 4294 | } |
| 4295 | |
| 4296 | static 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 | |
| 4331 | static JSValue js_worker_get_onmessage(JSContext *ctx, JSValueConst this_val) |
| 4332 | { |
nothing calls this directly
no test coverage detected