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

Igor Sysoev igor at sysoev.ru
Tue Jan 3 16:43:53 UTC 2017


details:   http://hg.nginx.org/njs/rev/fe8027493a08
branches:  
changeset: 297:fe8027493a08
user:      Igor Sysoev <igor at 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") },
 


More information about the nginx-devel mailing list