diff options
author | Zhidao HONG <z.hong@f5.com> | 2023-07-11 09:30:50 +0800 |
---|---|---|
committer | Zhidao HONG <z.hong@f5.com> | 2023-07-11 09:30:50 +0800 |
commit | 18d3637e4bffd5fff09091a536dca3fdecc931d7 (patch) | |
tree | 814c14a275c1d748940de2065d6a9f09bdd7ee8d | |
parent | 075c6a7038c9a4b2d5a9e6279bf406c83ccc8d27 (diff) | |
download | unit-18d3637e4bffd5fff09091a536dca3fdecc931d7.tar.gz unit-18d3637e4bffd5fff09091a536dca3fdecc931d7.tar.bz2 |
NJS: supported 0.8.0.
-rw-r--r-- | docs/changes.xml | 6 | ||||
-rw-r--r-- | src/nxt_js.c | 30 |
2 files changed, 21 insertions, 15 deletions
diff --git a/docs/changes.xml b/docs/changes.xml index 29c5c995..2522b823 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -32,6 +32,12 @@ NGINX Unit updated to 1.31.0. date="" time="" packager="Nginx Packaging <nginx-packaging@f5.com>"> +<change type="change"> +<para> +njs updated to 0.8.0. +</para> +</change> + <change type="bugfix"> <para> ensure that $uri variable is not cached. diff --git a/src/nxt_js.c b/src/nxt_js.c index df945db6..066d08f6 100644 --- a/src/nxt_js.c +++ b/src/nxt_js.c @@ -386,11 +386,11 @@ nxt_js_call(nxt_task_t *task, nxt_js_conf_t *jcf, nxt_js_cache_t *cache, nxt_js_t *js, nxt_str_t *str, void *ctx) { njs_vm_t *vm; - njs_int_t rc, ret; + njs_int_t ret; njs_str_t res; - njs_value_t *array, *value; + njs_value_t *value; njs_function_t *func; - njs_opaque_value_t opaque_value, arguments[6]; + njs_opaque_value_t retval, opaque_value, arguments[6]; static const njs_str_t uri_str = njs_str("uri"); static const njs_str_t host_str = njs_str("host"); @@ -407,15 +407,13 @@ nxt_js_call(nxt_task_t *task, nxt_js_conf_t *jcf, nxt_js_cache_t *cache, return NXT_ERROR; } - ret = njs_vm_start(vm); + ret = njs_vm_start(vm, njs_value_arg(&retval)); if (ret != NJS_OK) { return NXT_ERROR; } - array = njs_vm_retval(vm); - cache->vm = vm; - cache->array = *array; + cache->array = *njs_value_arg(&retval); } value = njs_vm_array_prop(vm, &cache->array, js->index, &opaque_value); @@ -463,18 +461,20 @@ nxt_js_call(nxt_task_t *task, nxt_js_conf_t *jcf, nxt_js_cache_t *cache, return NXT_ERROR; } - ret = njs_vm_call(vm, func, njs_value_arg(&arguments), 6); - - rc = njs_vm_retval_string(vm, &res); - if (rc != NJS_OK) { - return NXT_ERROR; - } + ret = njs_vm_invoke(vm, func, njs_value_arg(&arguments), 6, + njs_value_arg(&retval)); if (ret != NJS_OK) { - nxt_alert(task, "js exception: %V", &res); + ret = njs_vm_exception_string(vm, &res); + if (ret == NJS_OK) { + nxt_alert(task, "js exception: %V", &res); + } + return NXT_ERROR; } + ret = njs_vm_value_string(vm, &res, njs_value_arg(&retval)); + str->length = res.length; str->start = res.start; @@ -498,7 +498,7 @@ nxt_js_error(njs_vm_t *vm, u_char *error) njs_str_t res; nxt_str_t err; - ret = njs_vm_retval_string(vm, &res); + ret = njs_vm_exception_string(vm, &res); if (nxt_slow_path(ret != NJS_OK)) { return NXT_ERROR; } |