[njs] Added njs_vm_value().
Dmitry Volyntsev
xeioex at nginx.com
Wed Mar 27 18:11:01 UTC 2019
details: https://hg.nginx.org/njs/rev/ab2264c8f37f
branches:
changeset: 850:ab2264c8f37f
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon Apr 16 19:28:07 2018 +0300
description:
Added njs_vm_value().
diffstat:
njs/njs.h | 3 ++-
njs/njs_variable.c | 27 +++++++++++++++++++--------
2 files changed, 21 insertions(+), 9 deletions(-)
diffs (60 lines):
diff -r 5ef3dbe30d2d -r ab2264c8f37f njs/njs.h
--- a/njs/njs.h Tue Mar 26 08:04:02 2019 +0300
+++ b/njs/njs.h Mon Apr 16 19:28:07 2018 +0300
@@ -229,7 +229,8 @@ NXT_EXPORT njs_external_ptr_t njs_vm_ext
NXT_EXPORT void njs_disassembler(njs_vm_t *vm);
NXT_EXPORT nxt_array_t *njs_vm_completions(njs_vm_t *vm, nxt_str_t *expression);
-NXT_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, nxt_str_t *name);
+NXT_EXPORT const njs_value_t *njs_vm_value(njs_vm_t *vm, const nxt_str_t *name);
+NXT_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, const nxt_str_t *name);
NXT_EXPORT njs_value_t *njs_vm_retval(njs_vm_t *vm);
NXT_EXPORT void njs_vm_retval_set(njs_vm_t *vm, const njs_value_t *value);
diff -r 5ef3dbe30d2d -r ab2264c8f37f njs/njs_variable.c
--- a/njs/njs_variable.c Tue Mar 26 08:04:02 2019 +0300
+++ b/njs/njs_variable.c Mon Apr 16 19:28:07 2018 +0300
@@ -598,24 +598,35 @@ njs_name_copy(njs_vm_t *vm, nxt_str_t *d
}
-njs_function_t *
-njs_vm_function(njs_vm_t *vm, nxt_str_t *name)
+const njs_value_t *
+njs_vm_value(njs_vm_t *vm, const nxt_str_t *name)
{
- njs_value_t *value;
- njs_variable_t *var;
nxt_lvlhsh_query_t lhq;
lhq.key_hash = nxt_djb_hash(name->start, name->length);
lhq.key = *name;
lhq.proto = &njs_variables_hash_proto;
- if (nxt_slow_path(nxt_lvlhsh_find(&vm->variables_hash, &lhq) != NXT_OK)) {
- return NULL;
+ if (nxt_lvlhsh_find(&vm->variables_hash, &lhq) == NXT_OK) {
+ return njs_vmcode_operand(vm, ((njs_variable_t *) lhq.value)->index);
+ }
+
+ lhq.proto = &njs_extern_value_hash_proto;
+
+ if (nxt_lvlhsh_find(&vm->externals_hash, &lhq) == NXT_OK) {
+ return &((njs_extern_value_t *) lhq.value)->value;
}
- var = lhq.value;
+ return &njs_value_undefined;
+}
+
- value = njs_global_variable_value(vm, var);
+njs_function_t *
+njs_vm_function(njs_vm_t *vm, const nxt_str_t *name)
+{
+ const njs_value_t *value;
+
+ value = njs_vm_value(vm, name);
if (njs_is_function(value)) {
return value->data.u.function;
More information about the nginx-devel
mailing list