Welcome! Log In Create A New Profile

Advanced

[njs] Fixed parser for newline after throw.

Dmitry Volyntsev
November 23, 2018 09:48AM
details: https://hg.nginx.org/njs/rev/185aa0986f71
branches:
changeset: 669:185aa0986f71
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Nov 23 14:30:24 2018 +0300
description:
Fixed parser for newline after throw.

diffstat:

njs/njs_parser.c | 30 +++++++++++-------------------
njs/test/njs_unit_test.c | 3 +++
2 files changed, 14 insertions(+), 19 deletions(-)

diffs (72 lines):

diff -r ec82852f909a -r 185aa0986f71 njs/njs_parser.c
--- a/njs/njs_parser.c Thu Nov 22 19:32:48 2018 +0300
+++ b/njs/njs_parser.c Fri Nov 23 14:30:24 2018 +0300
@@ -1720,11 +1720,6 @@ njs_parser_throw_statement(njs_vm_t *vm,
njs_token_t token;
njs_parser_node_t *node;

- token = njs_parser_token(parser);
- if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
- }
-
node = njs_parser_node_alloc(vm);
if (nxt_slow_path(node == NULL)) {
return NJS_TOKEN_ERROR;
@@ -1732,32 +1727,29 @@ njs_parser_throw_statement(njs_vm_t *vm,

node->token = NJS_TOKEN_THROW;

- token = njs_parser_expression(vm, parser, token);
+ token = njs_lexer_token(parser->lexer);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}

- node->right = parser->node;
- parser->node = node;
-
- parser->code_size += sizeof(njs_vmcode_throw_t);
-
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;
+ njs_parser_syntax_error(vm, parser, "Illegal newline after throw");
+ return NJS_TOKEN_ILLEGAL;

default:
- if (parser->lexer->prev_token == NJS_TOKEN_LINE_END) {
+ token = njs_parser_expression(vm, parser, token);
+ if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}

- return NJS_TOKEN_ILLEGAL;
+ node->right = parser->node;
+ parser->node = node;
+
+ parser->code_size += sizeof(njs_vmcode_throw_t);
+
+ return token;
}
}

diff -r ec82852f909a -r 185aa0986f71 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Nov 22 19:32:48 2018 +0300
+++ b/njs/test/njs_unit_test.c Fri Nov 23 14:30:24 2018 +0300
@@ -6441,6 +6441,9 @@ static njs_unit_test_t njs_test[] =
" catch(x) { a += x } a"),
nxt_string("8") },

+ { nxt_string("throw\nnull"),
+ nxt_string("SyntaxError: Illegal newline after throw in 2") },
+
{ nxt_string("var o = { valueOf: function() { return '3' } }; --o"),
nxt_string("2") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed parser for newline after throw.

Dmitry Volyntsev 316 November 23, 2018 09:48AM



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

Online Users

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