]> git.kaiwu.me - njs.git/commitdiff
Introduced njs_parser_global_scope().
authorhongzhidao <hongzhidao@gmail.com>
Sat, 16 Feb 2019 15:18:43 +0000 (23:18 +0800)
committerhongzhidao <hongzhidao@gmail.com>
Sat, 16 Feb 2019 15:18:43 +0000 (23:18 +0800)
njs/njs_parser.c
njs/njs_parser.h
njs/njs_variable.c

index caf14ed19a203f24a0eea57e2c985c449ad3e985..8f6a8ee67285275cd1c388c6486b3db053320e10 100644 (file)
@@ -2178,11 +2178,7 @@ njs_parser_builtin(njs_vm_t *vm, njs_parser_t *parser, njs_parser_node_t *node,
     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)) {
index 61079488b169220104fa3df1c44cb4c9f858f81e..4b8f68bd9f300e391c2ea0f2814150830cec66e4 100644 (file)
@@ -360,6 +360,21 @@ njs_parser_node_new(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token)
 }
 
 
+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;
 
 
index 8daca9d732f111d641b639faf02f424937637a6a..536722aa875da702727d720b9897d33be688f2bc 100644 (file)
@@ -356,7 +356,7 @@ njs_variable_reference_resolve(njs_vm_t *vm, njs_variable_reference_t *vr,
     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 *vm, njs_variable_reference_t *vr,
             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 *vm, njs_variable_reference_t *vr,
         }
 
         previous = scope;
-        scope = parent;
+        scope = scope->parent;
     }
 }