[njs] Introduced njs_parser_global_scope().
Dmitry Volyntsev
xeioex at nginx.com
Wed Feb 20 14:26:00 UTC 2019
details: https://hg.nginx.org/njs/rev/64278ad1e14c
branches:
changeset: 783:64278ad1e14c
user: hongzhidao <hongzhidao at gmail.com>
date: Sat Feb 16 23:18:43 2019 +0800
description:
Introduced njs_parser_global_scope().
diffstat:
njs/njs_parser.c | 6 +-----
njs/njs_parser.h | 15 +++++++++++++++
njs/njs_variable.c | 8 +++-----
3 files changed, 19 insertions(+), 10 deletions(-)
diffs (73 lines):
diff -r 8250061df72a -r 64278ad1e14c njs/njs_parser.c
--- a/njs/njs_parser.c Wed Feb 20 16:16:30 2019 +0300
+++ b/njs/njs_parser.c Sat Feb 16 23:18:43 2019 +0800
@@ -2178,11 +2178,7 @@ njs_parser_builtin(njs_vm_t *vm, njs_par
njs_variable_t *var;
njs_parser_scope_t *scope;
- scope = parser->scope;
-
- while (scope->type != NJS_SCOPE_GLOBAL) {
- scope = scope->parent;
- }
+ scope = njs_parser_global_scope(vm);
var = njs_variable_add(vm, scope, name, hash, NJS_VARIABLE_VAR);
if (nxt_slow_path(var == NULL)) {
diff -r 8250061df72a -r 64278ad1e14c njs/njs_parser.h
--- a/njs/njs_parser.h Wed Feb 20 16:16:30 2019 +0300
+++ b/njs/njs_parser.h Sat Feb 16 23:18:43 2019 +0800
@@ -360,6 +360,21 @@ njs_parser_node_new(njs_vm_t *vm, njs_pa
}
+nxt_inline njs_parser_scope_t *
+njs_parser_global_scope(njs_vm_t *vm)
+{
+ njs_parser_scope_t *scope;
+
+ scope = vm->parser->scope;
+
+ while (scope->type != NJS_SCOPE_GLOBAL) {
+ scope = scope->parent;
+ }
+
+ return scope;
+}
+
+
extern const nxt_lvlhsh_proto_t njs_keyword_hash_proto;
diff -r 8250061df72a -r 64278ad1e14c njs/njs_variable.c
--- a/njs/njs_variable.c Wed Feb 20 16:16:30 2019 +0300
+++ b/njs/njs_variable.c Sat Feb 16 23:18:43 2019 +0800
@@ -356,7 +356,7 @@ njs_variable_reference_resolve(njs_vm_t
njs_parser_scope_t *node_scope)
{
nxt_lvlhsh_query_t lhq;
- njs_parser_scope_t *scope, *parent, *previous;
+ njs_parser_scope_t *scope, *previous;
lhq.key_hash = vr->hash;
lhq.key = vr->name;
@@ -395,9 +395,7 @@ njs_variable_reference_resolve(njs_vm_t
return NXT_OK;
}
- parent = scope->parent;
-
- if (parent == NULL) {
+ if (scope->parent == NULL) {
/* A global scope. */
vr->scope = scope;
@@ -405,7 +403,7 @@ njs_variable_reference_resolve(njs_vm_t
}
previous = scope;
- scope = parent;
+ scope = scope->parent;
}
}
More information about the nginx-devel
mailing list