-
Notifications
You must be signed in to change notification settings - Fork 222
Closed
Description
In worker_func the runtime is created using the default allocation functions (JS_NewRuntime does that)
In the same vein as js_worker_new_context_func we should have a js_worker_new_runtime_func which would allowto pass whatever allocation function we want.
Bonus point: we should also be able to provide freeing callbacks for worker's runtime and context as in the current state, we are unable to release any resource we would have allocated and stored in user_opaque for context (and runtime as well once we have a callback for allocation)
Proposed changes in quickjs-libc.c
Add a user pointer
static void * js_worker_user_opaque = NULL;
Modify existing callback to take user opaque:
static JSContext *(*js_worker_new_context_func)(JSRuntime *rt, void *);
Add a 3 static callbacks:
static JSRuntime *(*js_worker_new_runtime_func)(void *);static void(*js_worker_free_runtime_func)(JSRuntime *, void *);static void(*js_worker_free_context_func)(JSContext *, void *);
Add setters for the user opaque and the new callbacks
- Adapt signature of
js_std_set_worker_new_context_functo take an additionalvoid * - Add
void js_std_set_worker_new_runtime_func(JSRuntime *(*func)(void * user_opaque)) - Add
void js_std_set_worker_free_context_func(void(*func)(JSContext *ctx, void * user_opaque)) - Add
void js_std_set_worker_free_runtime_func(void(*func)(JSRuntime *rt, void * user_opaque))
In worker_func:
- Replace
rt = JS_NewRuntime();byrt = js_worker_new_runtime_func(js_worker_user_opaque ); - Replace
ctx = js_worker_new_context_func(rt);byctx = js_worker_new_context_func(rt, js_worker_user_opaque); - Replace
JS_FreeContext(ctx);byjs_worker_free_context_func(ctx, js_worker_user_opaque); - Replace
JS_FreeRuntime(rt);byjs_worker_free_runtime_func(rt, js_worker_user_opaque);
Metadata
Metadata
Assignees
Labels
No labels