[njs] Initialize global variables in njs virtual machines.

Roman Arutyunyan arut at nginx.com
Fri Jan 27 14:38:26 UTC 2017


details:   http://hg.nginx.org/njs/rev/e9c89068140d
branches:  
changeset: 307:e9c89068140d
user:      Roman Arutyunyan <arut at nginx.com>
date:      Fri Jan 27 16:45:34 2017 +0300
description:
Initialize global variables in njs virtual machines.

Previously, global variables in njs code remained uninitialized even if an
initializer existed in njs code.  To fix this, njs_vm_run() function is called
right after a virtual machine is cloned.  This call initializes global
variables.

diffstat:

 nginx/ngx_http_js_module.c   |  4 ++++
 nginx/ngx_stream_js_module.c |  4 ++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diffs (28 lines):

diff -r fb2ec3176a14 -r e9c89068140d nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Fri Jan 27 16:01:31 2017 +0300
+++ b/nginx/ngx_http_js_module.c	Fri Jan 27 16:45:34 2017 +0300
@@ -573,6 +573,10 @@ ngx_http_js_init_vm(ngx_http_request_t *
         return NGX_ERROR;
     }
 
+    if (njs_vm_run(ctx->vm) != NJS_OK) {
+        return NGX_ERROR;
+    }
+
     ctx->args = &jlcf->args[0];
 
     return NGX_OK;
diff -r fb2ec3176a14 -r e9c89068140d nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Fri Jan 27 16:01:31 2017 +0300
+++ b/nginx/ngx_stream_js_module.c	Fri Jan 27 16:45:34 2017 +0300
@@ -668,6 +668,10 @@ ngx_stream_js_init_vm(ngx_stream_session
         return NGX_ERROR;
     }
 
+    if (njs_vm_run(ctx->vm) != NJS_OK) {
+        return NGX_ERROR;
+    }
+
     ctx->arg = &jscf->arg;
 
     return NGX_OK;


More information about the nginx-devel mailing list