diff options
author | Dmitry Volyntsev <xeioex@nginx.com> | 2022-11-15 18:38:49 -0800 |
---|---|---|
committer | Dmitry Volyntsev <xeioex@nginx.com> | 2022-11-15 18:38:49 -0800 |
commit | d4b87eeb486818b9a00733ffcf3ec80f91d97bab (patch) | |
tree | 83d902e477895f477acc30296454af12fed50f22 /nginx/ngx_js.c | |
parent | 171af3961ff3f50105595d0764a1ad24e07cfa1f (diff) | |
download | njs-d4b87eeb486818b9a00733ffcf3ec80f91d97bab.tar.gz njs-d4b87eeb486818b9a00733ffcf3ec80f91d97bab.zip |
Modules: fixed Fetch Response prototype reinitialization.
Previously, since 446a1cb64a6a (0.7.7), when at least one js_import directive
was declared in both HTTP and Stream, ngx.fetch() returned inapproriate
response in Stream.
The prototype for Response object was created two times for HTTP and STREAM,
but the second initialization of global variable with the index of the
Response() prototype overwrites the first value with a different value. This
caused a problem in Stream code which manifested itself as a `Stream flags`
object returned as a result of ngx.fetch() call instead of a Response instance.
The fix is to ensure that shared prototypes like a Response prototype
have indentical index value in all the modules.
This fixes #596 issue on Github.
Diffstat (limited to 'nginx/ngx_js.c')
-rw-r--r-- | nginx/ngx_js.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index 831593da..7a816498 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -953,16 +953,21 @@ ngx_js_init_conf_vm(ngx_conf_t *cf, ngx_js_conf_t *conf, } } - rc = externals_init(cf, conf); - if (rc != NGX_OK) { - return NGX_ERROR; - } + /* + * Core prototypes must be inited before externals_init() because + * the core prototype ids have to be identical in all the modules. + */ rc = ngx_js_core_init(conf->vm, cf->log); if (njs_slow_path(rc != NJS_OK)) { return NGX_ERROR; } + rc = externals_init(cf, conf); + if (rc != NGX_OK) { + return NGX_ERROR; + } + end = start + size; rc = njs_vm_compile(conf->vm, &start, end); |