Welcome! Log In Create A New Profile

Advanced

[njs] Array and object literals did not support assignment expressions.

December 08, 2016 09:48AM
details: http://hg.nginx.org/njs/rev/0315d62a78c2
branches:
changeset: 277:0315d62a78c2
user: Igor Sysoev <igor@sysoev.ru>
date: Thu Dec 08 17:15:54 2016 +0300
description:
Array and object literals did not support assignment expressions.

Thanks to ??? (Hong Zhi Dao).

diffstat:

njs/njs_parser.c | 4 ++--
njs/njs_parser.h | 2 +-
njs/njs_parser_expression.c | 24 +++++++++++++++++-------
njs/test/njs_unit_test.c | 6 ++++++
4 files changed, 26 insertions(+), 10 deletions(-)

diffs (135 lines):

diff -r 2380d725ec7b -r 0315d62a78c2 njs/njs_parser.c
--- a/njs/njs_parser.c Wed Dec 07 19:34:48 2016 +0300
+++ b/njs/njs_parser.c Thu Dec 08 17:15:54 2016 +0300
@@ -1829,7 +1829,7 @@ njs_parser_object(njs_vm_t *vm, njs_pars
return token;
}

- token = njs_parser_conditional_expression(vm, parser, token);
+ token = njs_parser_assignment_expression(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1924,7 +1924,7 @@ njs_parser_array(njs_vm_t *vm, njs_parse
propref->right = node;
parser->code_size += sizeof(njs_vmcode_3addr_t);

- token = njs_parser_conditional_expression(vm, parser, token);
+ token = njs_parser_assignment_expression(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
diff -r 2380d725ec7b -r 0315d62a78c2 njs/njs_parser.h
--- a/njs/njs_parser.h Wed Dec 07 19:34:48 2016 +0300
+++ b/njs/njs_parser.h Thu Dec 08 17:15:54 2016 +0300
@@ -334,7 +334,7 @@ njs_token_t njs_parser_expression(njs_vm
njs_token_t token);
njs_token_t njs_parser_var_expression(njs_vm_t *vm, njs_parser_t *parser,
njs_token_t token);
-njs_token_t njs_parser_conditional_expression(njs_vm_t *vm,
+njs_token_t njs_parser_assignment_expression(njs_vm_t *vm,
njs_parser_t *parser, njs_token_t token);
njs_token_t njs_parser_terminal(njs_vm_t *vm, njs_parser_t *parser,
njs_token_t token);
diff -r 2380d725ec7b -r 0315d62a78c2 njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c Wed Dec 07 19:34:48 2016 +0300
+++ b/njs/njs_parser_expression.c Thu Dec 08 17:15:54 2016 +0300
@@ -55,9 +55,11 @@ struct njs_parser_expression_s {
};


-static njs_token_t njs_parser_assignment_expression(njs_vm_t *vm,
+static njs_token_t njs_parser_any_expression(njs_vm_t *vm,
njs_parser_t *parser, const njs_parser_expression_t *expr,
njs_token_t token);
+static njs_token_t njs_parser_conditional_expression(njs_vm_t *vm,
+ njs_parser_t *parser, njs_token_t token);
static njs_token_t njs_parser_binary_expression(njs_vm_t *vm,
njs_parser_t *parser, const njs_parser_expression_t *expr,
njs_token_t token);
@@ -227,7 +229,7 @@ static const njs_parser_expression_t
static const njs_parser_expression_t
njs_parser_comma_expression =
{
- njs_parser_assignment_expression,
+ njs_parser_any_expression,
NULL,
1, {
{ NJS_TOKEN_COMMA, NULL, 0 },
@@ -346,8 +348,16 @@ njs_parser_var_expression(njs_vm_t *vm,


static njs_token_t
+njs_parser_any_expression(njs_vm_t *vm, njs_parser_t *parser,
+ const njs_parser_expression_t *expr, njs_token_t token)
+{
+ return njs_parser_assignment_expression(vm, parser, token);
+}
+
+
+njs_token_t
njs_parser_assignment_expression(njs_vm_t *vm, njs_parser_t *parser,
- const njs_parser_expression_t *expr, njs_token_t token)
+ njs_token_t token)
{
size_t size;
njs_parser_node_t *node, *pending;
@@ -475,7 +485,7 @@ njs_parser_assignment_expression(njs_vm_
return token;
}

- token = njs_parser_assignment_expression(vm, parser, NULL, token);
+ token = njs_parser_assignment_expression(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -568,7 +578,7 @@ njs_parser_conditional_expression(njs_vm
cond->right = node;
node->token = NJS_TOKEN_BRANCHING;

- token = njs_parser_assignment_expression(vm, parser, NULL, token);
+ token = njs_parser_assignment_expression(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -585,7 +595,7 @@ njs_parser_conditional_expression(njs_vm
return token;
}

- token = njs_parser_assignment_expression(vm, parser, NULL, token);
+ token = njs_parser_assignment_expression(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1210,7 +1220,7 @@ njs_parser_arguments(njs_vm_t *vm, njs_p
break;
}

- token = njs_parser_assignment_expression(vm, parser, NULL, token);
+ token = njs_parser_assignment_expression(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
diff -r 2380d725ec7b -r 0315d62a78c2 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Wed Dec 07 19:34:48 2016 +0300
+++ b/njs/test/njs_unit_test.c Thu Dec 08 17:15:54 2016 +0300
@@ -1906,6 +1906,9 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("a = 1; a.b++; a.b"),
nxt_string("TypeError") },

+ { nxt_string("var n = 1, o = { p: n += 1 }; o.p"),
+ nxt_string("2") },
+
{ nxt_string("a = {}; a.b = {}; a.b.c = 1; a.b['c']"),
nxt_string("1") },

@@ -2073,6 +2076,9 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("a = [ 1, 2, 3 ]; a[0] + a[1] + a[2]"),
nxt_string("6") },

+ { nxt_string("var n = 1, a = [ n += 1 ]; a"),
+ nxt_string("2") },
+
{ nxt_string("a = [ 1, 2; 3 ]; a[0] + a[1] + a[2]"),
nxt_string("SyntaxError: Unexpected token \";\" in 1") },

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

[njs] Array and object literals did not support assignment expressions.

Igor Sysoev 383 December 08, 2016 09:48AM



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

Online Users

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