From: Dmitry Volyntsev Date: Wed, 24 Jul 2024 05:55:01 +0000 (-0700) Subject: QuickJS: qjs_new_context() accepts now additional modules. X-Git-Tag: 0.8.6~12 X-Git-Url: http://git.kaiwu.me/sitemap.xml?a=commitdiff_plain;h=cb8296fa4e2c976b78f07a73263bb0cd5dfb29ab;p=njs.git QuickJS: qjs_new_context() accepts now additional modules. --- diff --git a/external/njs_shell.c b/external/njs_shell.c index addf5a34..80693634 100644 --- a/external/njs_shell.c +++ b/external/njs_shell.c @@ -2731,7 +2731,7 @@ njs_engine_qjs_init(njs_engine_t *engine, njs_opts_t *opts) return NJS_ERROR; } - engine->u.qjs.ctx = qjs_new_context(engine->u.qjs.rt, 1); + engine->u.qjs.ctx = qjs_new_context(engine->u.qjs.rt, NULL, 1); if (engine->u.qjs.ctx == NULL) { njs_stderror("JS_NewContext() failed\n"); return NJS_ERROR; diff --git a/src/qjs.c b/src/qjs.c index de6bf17b..b8c53486 100644 --- a/src/qjs.c +++ b/src/qjs.c @@ -17,7 +17,7 @@ static const JSCFunctionListEntry qjs_global_proto[] = { JSContext * -qjs_new_context(JSRuntime *rt, _Bool eval) +qjs_new_context(JSRuntime *rt, qjs_module_t **addons, _Bool eval) { JSValue global_obj; JSContext *ctx; @@ -48,6 +48,14 @@ qjs_new_context(JSRuntime *rt, _Bool eval) } } + if (addons != NULL) { + for (module = addons; *module != NULL; module++) { + if ((*module)->init(ctx, (*module)->name) == NULL) { + return NULL; + } + } + } + global_obj = JS_GetGlobalObject(ctx); JS_SetPropertyFunctionList(ctx, global_obj, qjs_global_proto, diff --git a/src/qjs.h b/src/qjs.h index 563a5b15..531940ea 100644 --- a/src/qjs.h +++ b/src/qjs.h @@ -41,7 +41,7 @@ typedef struct { } qjs_module_t; -JSContext *qjs_new_context(JSRuntime *rt, _Bool eval); +JSContext *qjs_new_context(JSRuntime *rt, qjs_module_t **addons, _Bool eval); JSValue qjs_buffer_alloc(JSContext *ctx, size_t size);