Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3654,7 +3654,8 @@ typedef struct {
uint64_t buf[];
} JSSABHeader;

static JSContext *(*js_worker_new_context_func)(JSRuntime *rt);
static JSRuntime *(*js_worker_new_runtime_func)(void) = JS_NewRuntime;
static JSContext *(*js_worker_new_context_func)(JSRuntime *rt) = JS_NewContext;

static int atomic_add_int(int *ptr, int v)
{
Expand Down Expand Up @@ -3783,7 +3784,7 @@ static void worker_func(void *opaque)
JSContext *ctx;
JSValue val;

rt = JS_NewRuntime();
rt = js_worker_new_runtime_func();
if (rt == NULL) {
fprintf(stderr, "JS_NewRuntime failure");
exit(1);
Expand Down Expand Up @@ -4062,6 +4063,13 @@ static const JSCFunctionListEntry js_worker_proto_funcs[] = {

#endif /* USE_WORKER */

void js_std_set_worker_new_runtime_func(JSRuntime *(*func)(void))
{
#ifdef USE_WORKER
js_worker_new_runtime_func = func;
#endif
}

void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt))
{
#ifdef USE_WORKER
Expand Down
5 changes: 5 additions & 0 deletions quickjs-libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ JS_EXTERN void js_std_promise_rejection_tracker(JSContext *ctx,
JSValueConst reason,
bool is_handled,
void *opaque);
// Defaults to JS_NewRuntime, no-op if compiled without worker support.
// Call before creating the first worker thread.
JS_EXTERN void js_std_set_worker_new_runtime_func(JSRuntime *(*func)(void));
// Defaults to JS_NewContext, no-op if compiled without worker support.
// Call before creating the first worker thread.
JS_EXTERN void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt));

#undef JS_EXTERN
Expand Down