Welcome! Log In Create A New Profile

Advanced

[njs] Fixed "return" usage in a true branch of an "if" statement.

December 07, 2016 07:20AM
details: http://hg.nginx.org/njs/rev/56d6fc12dc31
branches:
changeset: 275:56d6fc12dc31
user: Igor Sysoev <igor@sysoev.ru>
date: Wed Dec 07 15:02:00 2016 +0300
description:
Fixed "return" usage in a true branch of an "if" statement.

diffstat:

njs/njs_parser.c | 4 ++++
njs/test/njs_unit_test.c | 15 +++++++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)

diffs (39 lines):

diff -r 709ac03a4bfd -r 56d6fc12dc31 njs/njs_parser.c
--- a/njs/njs_parser.c Mon Dec 05 17:47:00 2016 +0300
+++ b/njs/njs_parser.c Wed Dec 07 15:02:00 2016 +0300
@@ -629,6 +629,10 @@ njs_parser_return_statement(njs_vm_t *vm
node->right = parser->node;
parser->node = node;

+ if (token == NJS_TOKEN_SEMICOLON) {
+ return njs_parser_token(parser);
+ }
+
return token;
}
}
diff -r 709ac03a4bfd -r 56d6fc12dc31 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Mon Dec 05 17:47:00 2016 +0300
+++ b/njs/test/njs_unit_test.c Wed Dec 07 15:02:00 2016 +0300
@@ -1514,6 +1514,21 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var a = [3], b; if (1==1||2==2) { b = '1'+'2'+a[0] }; b }"),
nxt_string("123") },

+ { nxt_string("(function(){ if(true) return 1 else return 0; })()"),
+ nxt_string("1") },
+
+ { nxt_string("(function(){ if(true) return 1; else return 0; })()"),
+ nxt_string("1") },
+
+ { nxt_string("(function(){ if(true) return 1;; else return 0; })()"),
+ nxt_string("SyntaxError: Unexpected token \"else\" in 1") },
+
+ { nxt_string("(function(){ if(true) return 1\n else return 0; })()"),
+ nxt_string("1") },
+
+ { nxt_string("(function(){ if(true) return 1\n;\n else return 0; })()"),
+ nxt_string("1") },
+
/* do while. */

{ nxt_string("do { break } if (false)"),
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed "return" usage in a true branch of an "if" statement.

Igor Sysoev 981 December 07, 2016 07:20AM



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

Online Users

Guests: 262
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