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

Function worker_func

deps/quickjs/quickjs-libc.c:4058–4114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4056};
4057
4058static void worker_func(void *opaque)
4059{
4060 JSRuntime *(*new_runtime_func)(void);
4061 JSContext *(*new_context_func)(JSRuntime *);
4062 WorkerFuncArgs *args = opaque;
4063 JSRuntime *rt;
4064 JSThreadState *ts;
4065 JSContext *ctx;
4066 JSValue val;
4067
4068 new_runtime_func = js_worker_new_runtime_func;
4069 if (!new_runtime_func)
4070 new_runtime_func = JS_NewRuntime;
4071 rt = new_runtime_func();
4072 if (rt == NULL) {
4073 fprintf(stderr, "JS_NewRuntime failure");
4074 exit(1);
4075 }
4076 js_std_init_handlers(rt);
4077
4078 JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader, js_module_check_attributes, NULL);
4079
4080 /* set the pipe to communicate with the parent */
4081 ts = js_get_thread_state(rt);
4082 ts->recv_pipe = args->recv_pipe;
4083 ts->send_pipe = args->send_pipe;
4084
4085 /* function pointer to avoid linking the whole JS_NewContext() if
4086 not needed */
4087 new_context_func = js_worker_new_context_func;
4088 if (!new_context_func)
4089 new_context_func = JS_NewContext;
4090 ctx = new_context_func(rt);
4091 if (ctx == NULL) {
4092 fprintf(stderr, "JS_NewContext failure");
4093 exit(1);
4094 }
4095
4096 JS_SetCanBlock(rt, true);
4097
4098 js_std_add_helpers(ctx, -1, NULL);
4099
4100 val = JS_LoadModule(ctx, args->basename, args->filename);
4101 free(args->filename);
4102 free(args->basename);
4103 free(args);
4104 val = js_std_await(ctx, val);
4105 if (JS_IsException(val))
4106 js_std_dump_error(ctx);
4107 JS_FreeValue(ctx, val);
4108
4109 js_std_loop(ctx);
4110
4111 js_std_free_handlers(rt);
4112 JS_FreeContext(ctx);
4113 JS_FreeRuntime(rt);
4114}
4115

Callers

nothing calls this directly

Calls 9

exitFunction · 0.85
js_std_init_handlersFunction · 0.85
js_get_thread_stateFunction · 0.85
js_std_add_helpersFunction · 0.85
js_std_awaitFunction · 0.85
JS_IsExceptionFunction · 0.85
js_std_dump_errorFunction · 0.85
js_std_loopFunction · 0.85
js_std_free_handlersFunction · 0.85

Tested by

no test coverage detected