Alexander Borisov
June 29, 2021 10:10AM
details: https://hg.nginx.org/njs/rev/45c470a2d710
branches:
changeset: 1672:45c470a2d710
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Tue Jun 29 17:08:23 2021 +0300
description:
Fixed rest parameter parsing without binding identifier.

This closes #400 issue on GitHub.

diffstat:

src/njs_parser.c | 9 +++++++++
src/test/njs_unit_test.c | 6 ++++++
2 files changed, 15 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r fe1888cc2e3c -r 45c470a2d710 src/njs_parser.c
--- a/src/njs_parser.c Tue Jun 29 17:08:21 2021 +0300
+++ b/src/njs_parser.c Tue Jun 29 17:08:23 2021 +0300
@@ -6791,6 +6791,15 @@ njs_parser_formal_parameters(njs_parser_

njs_lexer_consume_token(parser->lexer, 1);

+ token = njs_lexer_token(parser->lexer, 0);
+ if (token == NULL) {
+ return NJS_ERROR;
+ }
+
+ if (!njs_lexer_token_is_binding_identifier(token)) {
+ return njs_parser_failed(parser);
+ }
+
lambda->rest_parameters = 1;

return NJS_OK;
diff -r fe1888cc2e3c -r 45c470a2d710 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Jun 29 17:08:21 2021 +0300
+++ b/src/test/njs_unit_test.c Tue Jun 29 17:08:23 2021 +0300
@@ -9330,6 +9330,12 @@ static njs_unit_test_t njs_test[] =
{ njs_str("function f(a,...rest) { }; f.length"),
njs_str("1") },

+ { njs_str("function f(...) {}"),
+ njs_str("SyntaxError: Unexpected token \")\" in 1") },
+
+ { njs_str("(function (...) {})()"),
+ njs_str("SyntaxError: Unexpected token \")\" in 1") },
+
{ njs_str("function f(a,b) { }; var ff = f.bind(f, 1); ff.length"),
njs_str("1") },

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

[njs] Fixed rest parameter parsing without binding identifier.

Alexander Borisov 161 June 29, 2021 10:10AM



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

Online Users

Guests: 59
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready