Welcome! Log In Create A New Profile

Advanced

[njs] Fixed parsing of throw statement inside if.

Dmitry Volyntsev
November 22, 2018 09:40AM
details: https://hg.nginx.org/njs/rev/b3691d847ff4
branches:
changeset: 665:b3691d847ff4
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Nov 22 17:38:40 2018 +0300
description:
Fixed parsing of throw statement inside if.

diffstat:

njs/njs_parser.c | 18 +++++++++++++++++-
njs/test/njs_unit_test.c | 9 +++++++++
2 files changed, 26 insertions(+), 1 deletions(-)

diffs (47 lines):

diff -r 3b2689be3a57 -r b3691d847ff4 njs/njs_parser.c
--- a/njs/njs_parser.c Thu Nov 22 17:38:25 2018 +0300
+++ b/njs/njs_parser.c Thu Nov 22 17:38:40 2018 +0300
@@ -1696,7 +1696,23 @@ njs_parser_try_statement(njs_vm_t *vm, n

parser->node = try;

- return token;
+ switch (token) {
+
+ case NJS_TOKEN_SEMICOLON:
+ case NJS_TOKEN_LINE_END:
+ return njs_parser_token(parser);
+
+ case NJS_TOKEN_CLOSE_BRACE:
+ case NJS_TOKEN_END:
+ return token;
+
+ default:
+ if (parser->lexer->prev_token == NJS_TOKEN_LINE_END) {
+ return token;
+ }
+
+ return NJS_TOKEN_ILLEGAL;
+ }
}


diff -r 3b2689be3a57 -r b3691d847ff4 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Nov 22 17:38:25 2018 +0300
+++ b/njs/test/njs_unit_test.c Thu Nov 22 17:38:40 2018 +0300
@@ -2159,6 +2159,15 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("(function(){ if(true) return 1\n;\n else return 0; })()"),
nxt_string("1") },

+ { nxt_string("function f(n) {if (n)\n throw 'foo'\nelse return 1}; f(0)"),
+ nxt_string("1") },
+
+ { nxt_string("function f(n) {if (n)\n throw 'foo'\nelse return 1}; f(1)"),
+ nxt_string("foo") },
+
+ { nxt_string("function f(n) {if (n == 1) throw 'foo'\nelse if (n == 2) return 1}; f(2)"),
+ 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 parsing of throw statement inside if.

Dmitry Volyntsev 265 November 22, 2018 09:40AM



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

Online Users

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