From: Igor Sysoev Date: Sun, 2 Apr 2017 09:36:05 +0000 (+0300) Subject: Variables may be accessed incorrectly by nested functions. X-Git-Tag: 0.1.10~9 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=359388f9075a745032c2dfe779635ef9e8e49ba9;p=njs.git Variables may be accessed incorrectly by nested functions. --- diff --git a/njs/njs_parser.c b/njs/njs_parser.c index c2eca2b5..7fee2a46 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -215,6 +215,11 @@ njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser, njs_scope_t type) if (parent != NULL) { nxt_queue_insert_tail(&parent->nested, &scope->link); + + if (nesting == 0) { + /* Inherit function nesting in blocks. */ + scope->nesting = parent->nesting; + } } return NXT_OK; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 36aa855b..7891ea5a 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -4221,6 +4221,11 @@ static njs_unit_test_t njs_test[] = "var y = f(); y()"), nxt_string("4") }, + { nxt_string("function f() { var x = 4;" + "function g() { if (1) { return 2 + x; } }; return g }" + "var y = f(); y()"), + nxt_string("6") }, + /* Recursive fibonacci. */ { nxt_string("function fibo(n) {"