diff options
Diffstat (limited to 'src/nxt_js.c')
| -rw-r--r-- | src/nxt_js.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/nxt_js.c b/src/nxt_js.c index 6885afb7..d46231bd 100644 --- a/src/nxt_js.c +++ b/src/nxt_js.c @@ -69,14 +69,6 @@ nxt_js_module_loader(njs_vm_t *vm, njs_external_ptr_t external, njs_str_t *name) } -static njs_vm_ops_t nxt_js_ops = { - NULL, - NULL, - nxt_js_module_loader, - NULL, -}; - - njs_int_t nxt_js_proto_id; @@ -127,13 +119,14 @@ nxt_js_vm_create(nxt_js_conf_t *jcf) { u_char *p; size_t size; + njs_vm_t *vm; nxt_uint_t i; njs_vm_opt_t opts; nxt_js_module_t *module, *mod; - static nxt_str_t import_str = nxt_string("import"); - static nxt_str_t from_str = nxt_string("from"); - static nxt_str_t global_str = nxt_string("globalThis"); + static const nxt_str_t import_str = nxt_string("import"); + static const nxt_str_t from_str = nxt_string("from"); + static const nxt_str_t global_str = nxt_string("globalThis"); njs_vm_opt_init(&opts); @@ -146,7 +139,6 @@ nxt_js_vm_create(nxt_js_conf_t *jcf) goto done; } - opts.ops = &nxt_js_ops; opts.external = jcf; size = 0; @@ -203,7 +195,13 @@ nxt_js_vm_create(nxt_js_conf_t *jcf) done: - return njs_vm_create(&opts); + vm = njs_vm_create(&opts); + + if (nxt_fast_path(vm != NULL)) { + njs_vm_set_module_loader(vm, nxt_js_module_loader, jcf); + } + + return vm; } @@ -239,14 +237,15 @@ nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz) nxt_js_t *js; nxt_str_t *func; - static nxt_str_t func_str = nxt_string("function(uri, host, remoteAddr, " - "args, headers, cookies, vars) {" - " return "); + static const nxt_str_t func_str = + nxt_string("function(uri, host, remoteAddr, " + "args, headers, cookies, vars) {" + " return "); /* * Appending a terminating null character if strz is true. */ - static nxt_str_t strz_str = nxt_string(" + '\\x00'"); + static const nxt_str_t strz_str = nxt_string(" + '\\x00'"); size = func_str.length + str->length + 1; |
