Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions nginx/ngx_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,17 @@ ngx_engine_njs_init(ngx_engine_t *engine, ngx_engine_opts_t *opts)
vm_options.backtrace = 1;
vm_options.addons = opts->u.njs.addons;
vm_options.metas = opts->u.njs.metas;
vm_options.file = opts->file;
vm_options.argv = ngx_argv;
vm_options.argc = ngx_argc;
vm_options.init = 1;

vm_options.file.start = njs_mp_alloc(engine->pool, opts->file.length);
if (vm_options.file.start == NULL) {
return NGX_ERROR;
}

ngx_memcpy(vm_options.file.start, opts->file.start, opts->file.length);

vm = njs_vm_create(&vm_options);
if (vm == NULL) {
return NGX_ERROR;
Expand All @@ -571,14 +577,15 @@ ngx_engine_njs_init(ngx_engine_t *engine, ngx_engine_opts_t *opts)

rc = ngx_js_set_cwd(njs_vm_memory_pool(vm), opts->conf, &vm_options.file);
if (rc != NGX_OK) {
njs_vm_destroy(vm);
return NGX_ERROR;
}

njs_vm_set_module_loader(vm, ngx_js_module_loader, opts->conf);

engine->u.njs.vm = vm;

return NJS_OK;
return NGX_OK;
}


Expand Down Expand Up @@ -665,6 +672,7 @@ ngx_njs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf, void *external)

engine = njs_mp_alloc(njs_vm_memory_pool(vm), sizeof(ngx_engine_t));
if (engine == NULL) {
njs_vm_destroy(vm);
return NULL;
}

Expand All @@ -677,6 +685,8 @@ ngx_njs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf, void *external)

ngx_log_error(NGX_LOG_ERR, ctx->log, 0, "js exception: %V", &exception);

njs_vm_destroy(vm);

return NULL;
}

Expand Down
14 changes: 13 additions & 1 deletion nginx/t/js_import2.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ http {
js_content fun;
}
location /test_exception {
js_import exception.js;
js_content exception.nonexistent;
}
location /test_var {
return 200 $test;
}
Expand Down Expand Up @@ -105,6 +110,11 @@ $t->write_file('fun.js', <<EOF);
EOF

$t->write_file('exception.js', <<EOF);
export default {nonexistent};
EOF

$t->write_file('main.js', <<EOF);
function version(r) {
r.return(200, njs.version);
Expand All @@ -127,11 +137,13 @@ like(http_get('/test_lib'), qr/LIB-TEST/s, 'lib.test');
like(http_get('/test_fun'), qr/FUN-TEST/s, 'fun');
like(http_get('/proxy/test_fun'), qr/FUN-TEST/s, 'proxy fun');
like(http_get('/test_var'), qr/P-TEST/s, 'foo.bar.p');
http_get('/test_exception');
http_get('/test_exception');

$t->stop();

my $content = $t->read_file('error.log');
my $count = () = $content =~ m/js vm init/g;
ok($count == 4, 'uniq js vm contexts');
ok($count == 5, 'uniq js vm contexts');

###############################################################################
4 changes: 2 additions & 2 deletions src/njs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include <njs_auto_config.h>

#define NJS_VERSION "0.9.2"
#define NJS_VERSION_NUMBER 0x000902
#define NJS_VERSION "0.9.3"
#define NJS_VERSION_NUMBER 0x000903


#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion src/njs_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ njs_vm_compile_module(njs_vm_t *vm, njs_str_t *name, u_char **start,
return NULL;
}

ret = njs_parser_init(vm, &parser, NULL, name, *start, end);
ret = njs_parser_init(vm, &parser, NULL, &module->name, *start, end);
if (njs_slow_path(ret != NJS_OK)) {
return NULL;
}
Expand Down