[njs] Parser: catching errors parsing in await expression.

Alexander Borisov alexander.borisov at nginx.com
Thu Sep 2 16:35:03 UTC 2021


details:   https://hg.nginx.org/njs/rev/502be9e80244
branches:  
changeset: 1703:502be9e80244
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Thu Sep 02 19:33:03 2021 +0300
description:
Parser: catching errors parsing in await expression.

The bug was introduced in 92d10cd761e2.

diffstat:

 src/njs_parser.c         |  4 ++++
 src/test/njs_unit_test.c |  3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)

diffs (27 lines):

diff -r f2410c8b80d9 -r 502be9e80244 src/njs_parser.c
--- a/src/njs_parser.c	Thu Sep 02 19:32:52 2021 +0300
+++ b/src/njs_parser.c	Thu Sep 02 19:33:03 2021 +0300
@@ -3504,6 +3504,10 @@ static njs_int_t
 njs_parser_await_after(njs_parser_t *parser, njs_lexer_token_t *token,
     njs_queue_link_t *current)
 {
+    if (parser->ret != NJS_OK) {
+        return njs_parser_failed(parser);
+    }
+
     parser->target->right = parser->node;
     parser->node = parser->target;
 
diff -r f2410c8b80d9 -r 502be9e80244 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Thu Sep 02 19:32:52 2021 +0300
+++ b/src/test/njs_unit_test.c	Thu Sep 02 19:33:03 2021 +0300
@@ -20517,6 +20517,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("function f(a) {}"
               "(async function() {f('Number: ' + await 111)})"),
       njs_str("SyntaxError: await in arguments not supported in 1") },
+
+    { njs_str("async function af() {await encrypt({},}"),
+      njs_str("SyntaxError: Unexpected token \"}\" in 1") },
 };
 
 


More information about the nginx-devel mailing list