details: https://github.com/nginx/njs/commit/cb8296fa4e2c976b78f07a73263bb0cd5dfb29ab
branches: master
commit: cb8296fa4e2c976b78f07a73263bb0cd5dfb29ab
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue, 23 Jul 2024 22:55:01 -0700
description:
QuickJS: qjs_new_context() accepts now additional modules.
---
external/njs_shell.c | 2 +-
src/qjs.c | 10 +++++++++-
src/qjs.h | 2 +-
3 files changed, 11 insertions(+), 3 deletions(-)
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);
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel