[njs] njs_vm_function() and njs_vm_external() functions name and
Igor Sysoev
igor at sysoev.ru
Fri Jul 15 12:50:49 UTC 2016
details: http://hg.nginx.org/njs/rev/a3e7ebdf9fa7
branches:
changeset: 122:a3e7ebdf9fa7
user: Igor Sysoev <igor at sysoev.ru>
date: Fri Jul 15 15:50:13 2016 +0300
description:
njs_vm_function() and njs_vm_external() functions name and
behavior unification. The function can be used with both
original compiled VM and its clones.
diffstat:
nginx/ngx_http_js_module.c | 8 ++++----
njs/njs_extern.c | 6 +++---
njs/njs_variable.c | 4 ++--
njs/njscript.c | 1 +
njs/njscript.h | 4 ++--
njs/test/njs_unit_test.c | 6 +++---
6 files changed, 15 insertions(+), 14 deletions(-)
diffs (126 lines):
diff -r 74246210aa9d -r a3e7ebdf9fa7 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Thu Jul 14 19:24:51 2016 +0300
+++ b/nginx/ngx_http_js_module.c Fri Jul 15 15:50:13 2016 +0300
@@ -1152,8 +1152,8 @@ ngx_http_js_compile(ngx_conf_t *cf, ngx_
nxt_lvlhsh_init(&externals);
- if (njs_add_external(&externals, mcp, 0, ngx_http_js_externals,
- nxt_nitems(ngx_http_js_externals))
+ if (njs_vm_external_add(&externals, mcp, 0, ngx_http_js_externals,
+ nxt_nitems(ngx_http_js_externals))
!= NJS_OK)
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "could not add js externals");
@@ -1191,7 +1191,7 @@ ngx_http_js_compile(ngx_conf_t *cf, ngx_
if (function) {
ngx_str_set(&name, "$r");
- rc = njs_external_get(vm, NULL, &name, &js->args[0]);
+ rc = njs_vm_external(vm, NULL, &name, &js->args[0]);
if (rc != NXT_OK) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"could not get $r external");
@@ -1200,7 +1200,7 @@ ngx_http_js_compile(ngx_conf_t *cf, ngx_
ngx_str_set(&name, "response");
- rc = njs_external_get(vm, &js->args[0], &name, &js->args[1]);
+ rc = njs_vm_external(vm, &js->args[0], &name, &js->args[1]);
if (rc != NXT_OK) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"could not get $r.response external");
diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njs_extern.c
--- a/njs/njs_extern.c Thu Jul 14 19:24:51 2016 +0300
+++ b/njs/njs_extern.c Fri Jul 15 15:50:13 2016 +0300
@@ -51,7 +51,7 @@ const nxt_lvlhsh_proto_t njs_extern_has
nxt_int_t
-njs_add_external(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp,
+njs_vm_external_add(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp,
uintptr_t object, njs_external_t *external, nxt_uint_t n)
{
nxt_int_t ret;
@@ -111,7 +111,7 @@ njs_add_external(nxt_lvlhsh_t *hash, nxt
}
if (external->properties != NULL) {
- ret = njs_add_external(&ext->hash, mcp, object,
+ ret = njs_vm_external_add(&ext->hash, mcp, object,
external->properties, external->nproperties);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
@@ -128,7 +128,7 @@ njs_add_external(nxt_lvlhsh_t *hash, nxt
nxt_int_t
-njs_external_get(njs_vm_t *vm, njs_opaque_value_t *obj, nxt_str_t *property,
+njs_vm_external(njs_vm_t *vm, njs_opaque_value_t *obj, nxt_str_t *property,
njs_opaque_value_t *value)
{
uint32_t (*key_hash)(const void *, size_t);
diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njs_variable.c
--- a/njs/njs_variable.c Thu Jul 14 19:24:51 2016 +0300
+++ b/njs/njs_variable.c Fri Jul 15 15:50:13 2016 +0300
@@ -136,8 +136,8 @@ njs_vm_function(njs_vm_t *vm, nxt_str_t
var = lhq.value;
- value = (njs_value_t *) ((u_char *) vm->scopes[NJS_SCOPE_GLOBAL]
- + njs_offset(var->index));
+ value = (njs_value_t *) ((u_char *) vm->global_scope
+ + njs_offset(var->index) - NJS_INDEX_GLOBAL_OFFSET);
return value->data.u.function;
}
diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njscript.c
--- a/njs/njscript.c Thu Jul 14 19:24:51 2016 +0300
+++ b/njs/njscript.c Fri Jul 15 15:50:13 2016 +0300
@@ -280,6 +280,7 @@ njs_vm_clone(njs_vm_t *vm, nxt_mem_cache
nvm->variables_hash = vm->variables_hash;
nvm->values_hash = vm->values_hash;
+ nvm->externals_hash = vm->externals_hash;
nvm->retval = njs_value_void;
nvm->current = vm->current;
diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njscript.h
--- a/njs/njscript.h Thu Jul 14 19:24:51 2016 +0300
+++ b/njs/njscript.h Fri Jul 15 15:50:13 2016 +0300
@@ -73,10 +73,10 @@ struct njs_external_s {
#define NJS_DONE NXT_DONE
-NXT_EXPORT nxt_int_t njs_add_external(nxt_lvlhsh_t *hash,
+NXT_EXPORT nxt_int_t njs_vm_external_add(nxt_lvlhsh_t *hash,
nxt_mem_cache_pool_t *mcp, uintptr_t object, njs_external_t *external,
nxt_uint_t n);
-NXT_EXPORT nxt_int_t njs_external_get(njs_vm_t *vm, njs_opaque_value_t *object,
+NXT_EXPORT nxt_int_t njs_vm_external(njs_vm_t *vm, njs_opaque_value_t *object,
nxt_str_t *property, njs_opaque_value_t *value);
NXT_EXPORT njs_vm_t *njs_vm_create(nxt_mem_cache_pool_t *mcp,
diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Jul 14 19:24:51 2016 +0300
+++ b/njs/test/njs_unit_test.c Fri Jul 15 15:50:13 2016 +0300
@@ -4811,8 +4811,8 @@ njs_unit_test_externals(nxt_lvlhsh_t *ex
{
nxt_lvlhsh_init(externals);
- return njs_add_external(externals, mcp, 0, nxt_test_external,
- nxt_nitems(nxt_test_external));
+ return njs_vm_external_add(externals, mcp, 0, nxt_test_external,
+ nxt_nitems(nxt_test_external));
}
@@ -4937,7 +4937,7 @@ njs_unit_test(nxt_bool_t disassemble)
r_name.len = 2;
r_name.data = (u_char *) "$r";
- ret = njs_external_get(vm, NULL, &r_name, &value);
+ ret = njs_vm_external(nvm, NULL, &r_name, &value);
if (ret != NXT_OK) {
return NXT_ERROR;
}
More information about the nginx-devel
mailing list