Welcome! Log In Create A New Profile

Advanced

[njs] Logical "or" and "and" operations should store result in a

January 03, 2017 11:46AM
details: http://hg.nginx.org/njs/rev/fe8027493a08
branches:
changeset: 297:fe8027493a08
user: Igor Sysoev <igor@sysoev.ru>
date: Tue Jan 03 19:38:17 2017 +0300
description:
Logical "or" and "and" operations should store result in a
temporary destination because they are actually branch operations.

diffstat:

njs/njs_generator.c | 4 ++--
njs/test/njs_unit_test.c | 6 ++++++
2 files changed, 8 insertions(+), 2 deletions(-)

diffs (37 lines):

diff -r 9672a3c3aaae -r fe8027493a08 njs/njs_generator.c
--- a/njs/njs_generator.c Mon Jan 02 22:59:33 2017 +0300
+++ b/njs/njs_generator.c Tue Jan 03 19:38:17 2017 +0300
@@ -1666,7 +1666,7 @@ njs_generate_test_jump_expression(njs_vm
test_jump->code.retval = NJS_VMCODE_RETVAL;
test_jump->value = node->left->index;

- node->index = njs_generator_dest_index(vm, parser, node);
+ node->index = njs_generator_node_temp_index_get(vm, parser, node);
if (nxt_slow_path(node->index == NJS_INDEX_ERROR)) {
return node->index;
}
@@ -1695,7 +1695,7 @@ njs_generate_test_jump_expression(njs_vm

test_jump->offset = parser->code_end - (u_char *) test_jump;

- return njs_generator_node_index_release(vm, parser, node->right);
+ return njs_generator_children_indexes_release(vm, parser, node);
}


diff -r 9672a3c3aaae -r fe8027493a08 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Mon Jan 02 22:59:33 2017 +0300
+++ b/njs/test/njs_unit_test.c Tue Jan 03 19:38:17 2017 +0300
@@ -568,6 +568,12 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var a = 1; 1 || (a = 2); a"),
nxt_string("1") },

+ { nxt_string("var x; x = 0 || x; x"),
+ nxt_string("undefined") },
+
+ { nxt_string("var x; x = 1 && x; x"),
+ nxt_string("undefined") },
+
{ nxt_string("1 || 2 || 3"),
nxt_string("1") },

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

[njs] Logical "or" and "and" operations should store result in a

Igor Sysoev 665 January 03, 2017 11:46AM



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