Mercurial > njs
changeset 783:64278ad1e14c
Introduced njs_parser_global_scope().
| author | hongzhidao <hongzhidao@gmail.com> |
|---|---|
| date | Sat, 16 Feb 2019 23:18:43 +0800 |
| parents | 8250061df72a |
| children | b23c0a90e37f |
| files | njs/njs_parser.c njs/njs_parser.h njs/njs_variable.c |
| diffstat | 3 files changed, 19 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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_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)) {
--- 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 @@ } +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;
--- 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_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 @@ return NXT_OK; } - parent = scope->parent; - - if (parent == NULL) { + if (scope->parent == NULL) { /* A global scope. */ vr->scope = scope; @@ -405,7 +403,7 @@ } previous = scope; - scope = parent; + scope = scope->parent; } }
