Welcome! Log In Create A New Profile

Advanced

[njs] Fixed function declaration with the same name as a variable.

Dmitry Volyntsev
April 15, 2019 09:38AM
details: https://hg.nginx.org/njs/rev/d3743d248ade
branches:
changeset: 892:d3743d248ade
user: hongzhidao <hongzhidao@gmail.com>
date: Sat Apr 13 23:38:53 2019 +0800
description:
Fixed function declaration with the same name as a variable.

This closes #126 issue on Github.

diffstat:

njs/njs_variable.c | 5 +++++
njs/test/njs_unit_test.c | 10 ++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r ace6f73dff8d -r d3743d248ade njs/njs_variable.c
--- a/njs/njs_variable.c Sat Apr 13 01:11:49 2019 +0800
+++ b/njs/njs_variable.c Sat Apr 13 23:38:53 2019 +0800
@@ -65,6 +65,11 @@ njs_variable_add(njs_vm_t *vm, njs_parse

if (nxt_lvlhsh_find(&scope->variables, &lhq) == NXT_OK) {
var = lhq.value;
+
+ if (type == NJS_VARIABLE_FUNCTION) {
+ var->type = type;
+ }
+
return var;
}

diff -r ace6f73dff8d -r d3743d248ade njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Sat Apr 13 01:11:49 2019 +0800
+++ b/njs/test/njs_unit_test.c Sat Apr 13 23:38:53 2019 +0800
@@ -6413,6 +6413,16 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("function f() { var a = 1; function baz() { return a; } return baz; } f().bind()()"),
nxt_string("1") },

+ { nxt_string("function f() { var t = 1; function baz() { return t; } return baz; }"
+ "f().bind()();"),
+ nxt_string("1") },
+
+ { nxt_string("(function(a) { var s = typeof g, q = g; var g = 1; s += typeof g; function g(b) { return a + b }; return q; })(1)(2)"),
+ nxt_string("3")},
+
+ { nxt_string("(function(a) { var g = f; var f = 1; function f() { return a; } return g; })(42)()"),
+ nxt_string("42") },
+
{ nxt_string("function f(a, b) { return a + b }"
"f(3,4) === f.bind()(3,4)"),
nxt_string("true") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed function declaration with the same name as a variable.

Dmitry Volyntsev 616 April 15, 2019 09:38AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 223
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready