[njs] Allowing to pass arbitrary number of arguments in ngx_js_call().

Dmitry Volyntsev xeioex at nginx.com
Thu Feb 11 15:05:37 UTC 2021


details:   https://hg.nginx.org/njs/rev/9631d5c88caf
branches:  
changeset: 1601:9631d5c88caf
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Feb 11 14:30:59 2021 +0000
description:
Allowing to pass arbitrary number of arguments in ngx_js_call().

diffstat:

 nginx/ngx_http_js_module.c   |  10 +++++-----
 nginx/ngx_js.c               |   6 +++---
 nginx/ngx_js.h               |   4 ++--
 nginx/ngx_stream_js_module.c |   8 +++++---
 4 files changed, 15 insertions(+), 13 deletions(-)

diffs (103 lines):

diff -r 0d15daffba9e -r 9631d5c88caf nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Wed Feb 10 14:03:11 2021 +0000
+++ b/nginx/ngx_http_js_module.c	Thu Feb 11 14:30:59 2021 +0000
@@ -660,8 +660,8 @@ ngx_http_js_content_event_handler(ngx_ht
 
     ctx->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
 
-    rc = ngx_js_call(ctx->vm, &jlcf->content, &ctx->request,
-                     r->connection->log);
+    rc = ngx_js_call(ctx->vm, &jlcf->content, r->connection->log,
+                     &ctx->request, 1);
 
     if (rc == NGX_ERROR) {
         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -773,8 +773,8 @@ ngx_http_js_header_filter(ngx_http_reque
 
     pending = njs_vm_pending(ctx->vm);
 
-    rc = ngx_js_call(ctx->vm, &jlcf->header_filter, &ctx->request,
-                     r->connection->log);
+    rc = ngx_js_call(ctx->vm, &jlcf->header_filter, r->connection->log,
+                     &ctx->request, 1);
 
     if (rc == NGX_ERROR) {
         return NGX_ERROR;
@@ -820,7 +820,7 @@ ngx_http_js_variable(ngx_http_request_t 
 
     pending = njs_vm_pending(ctx->vm);
 
-    rc = ngx_js_call(ctx->vm, fname, &ctx->request, r->connection->log);
+    rc = ngx_js_call(ctx->vm, fname, r->connection->log, &ctx->request, 1);
 
     if (rc == NGX_ERROR) {
         v->not_found = 1;
diff -r 0d15daffba9e -r 9631d5c88caf nginx/ngx_js.c
--- a/nginx/ngx_js.c	Wed Feb 10 14:03:11 2021 +0000
+++ b/nginx/ngx_js.c	Thu Feb 11 14:30:59 2021 +0000
@@ -66,8 +66,8 @@ static njs_external_t  ngx_js_ext_core[]
 
 
 ngx_int_t
-ngx_js_call(njs_vm_t *vm, ngx_str_t *fname, njs_opaque_value_t *value,
-    ngx_log_t *log)
+ngx_js_call(njs_vm_t *vm, ngx_str_t *fname, ngx_log_t *log,
+    njs_opaque_value_t *args, njs_uint_t nargs)
 {
     njs_str_t        name, exception;
     njs_function_t  *func;
@@ -82,7 +82,7 @@ ngx_js_call(njs_vm_t *vm, ngx_str_t *fna
         return NGX_ERROR;
     }
 
-    if (njs_vm_call(vm, func, njs_value_arg(value), 1) != NJS_OK) {
+    if (njs_vm_call(vm, func, njs_value_arg(args), nargs) != NJS_OK) {
         njs_vm_retval_string(vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, log, 0,
diff -r 0d15daffba9e -r 9631d5c88caf nginx/ngx_js.h
--- a/nginx/ngx_js.h	Wed Feb 10 14:03:11 2021 +0000
+++ b/nginx/ngx_js.h	Thu Feb 11 14:30:59 2021 +0000
@@ -49,8 +49,8 @@ typedef ngx_msec_t (*ngx_external_resolv
                              : njs_vm_value_buffer_set(vm, value, start, len))
 
 
-ngx_int_t ngx_js_call(njs_vm_t *vm, ngx_str_t *s, njs_opaque_value_t *value,
-    ngx_log_t *log);
+ngx_int_t ngx_js_call(njs_vm_t *vm, ngx_str_t *fname, ngx_log_t *log,
+    njs_opaque_value_t *args, njs_uint_t nargs);
 
 njs_int_t ngx_js_ext_log(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t level);
diff -r 0d15daffba9e -r 9631d5c88caf nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Wed Feb 10 14:03:11 2021 +0000
+++ b/nginx/ngx_stream_js_module.c	Thu Feb 11 14:30:59 2021 +0000
@@ -461,7 +461,8 @@ ngx_stream_js_phase_handler(ngx_stream_s
 
         ctx->status = NGX_ERROR;
 
-        rc = ngx_js_call(ctx->vm, name, &ctx->args[0], c->log);
+        rc = ngx_js_call(ctx->vm, name, c->log, &ctx->args[0], 1);
+
         if (rc == NGX_ERROR) {
             return rc;
         }
@@ -534,7 +535,8 @@ ngx_stream_js_body_filter(ngx_stream_ses
     ctx = ngx_stream_get_module_ctx(s, ngx_stream_js_module);
 
     if (!ctx->filter) {
-        rc = ngx_js_call(ctx->vm, &jscf->filter, &ctx->args[0], c->log);
+        rc = ngx_js_call(ctx->vm, &jscf->filter, c->log, &ctx->args[0], 1);
+
         if (rc == NGX_ERROR) {
             return rc;
         }
@@ -630,7 +632,7 @@ ngx_stream_js_variable(ngx_stream_sessio
 
     pending = njs_vm_pending(ctx->vm);
 
-    rc = ngx_js_call(ctx->vm, fname, &ctx->args[0], s->connection->log);
+    rc = ngx_js_call(ctx->vm, fname, s->connection->log, &ctx->args[0], 1);
 
     if (rc == NGX_ERROR) {
         v->not_found = 1;


More information about the nginx-devel mailing list