From: Roman Arutyunyan Date: Fri, 27 Jan 2017 13:45:34 +0000 (+0300) Subject: Initialize global variables in njs virtual machines. X-Git-Tag: 0.1.9~3 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=9c3a4f0bac65da39fe6ec25a95875b059a51585c;p=njs.git 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. --- diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c index 104ca71f..b2e84481 100644 --- a/nginx/ngx_http_js_module.c +++ b/nginx/ngx_http_js_module.c @@ -573,6 +573,10 @@ ngx_http_js_init_vm(ngx_http_request_t *r) return NGX_ERROR; } + if (njs_vm_run(ctx->vm) != NJS_OK) { + return NGX_ERROR; + } + ctx->args = &jlcf->args[0]; return NGX_OK; diff --git a/nginx/ngx_stream_js_module.c b/nginx/ngx_stream_js_module.c index 43fb84df..13597b18 100644 --- a/nginx/ngx_stream_js_module.c +++ b/nginx/ngx_stream_js_module.c @@ -668,6 +668,10 @@ ngx_stream_js_init_vm(ngx_stream_session_t *s) return NGX_ERROR; } + if (njs_vm_run(ctx->vm) != NJS_OK) { + return NGX_ERROR; + } + ctx->arg = &jscf->arg; return NGX_OK;