[njs] Fixed equality operator when both operands are objects.

Valentin Bartenev vbart at nginx.com
Fri Nov 9 15:20:34 UTC 2018


details:   http://hg.nginx.org/njs/rev/025b22bf8c49
branches:  
changeset: 645:025b22bf8c49
user:      Valentin Bartenev <vbart at nginx.com>
date:      Thu Nov 08 20:32:45 2018 +0300
description:
Fixed equality operator when both operands are objects.

diffstat:

 njs/njs_vm.c             |  4 ++++
 njs/test/njs_unit_test.c |  6 ++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diffs (30 lines):

diff -r abec5f8d55a1 -r 025b22bf8c49 njs/njs_vm.c
--- a/njs/njs_vm.c	Fri Nov 09 18:05:39 2018 +0300
+++ b/njs/njs_vm.c	Thu Nov 08 20:32:45 2018 +0300
@@ -1543,6 +1543,10 @@ njs_values_equal(njs_vm_t *vm, const njs
         return (val1->data.u.object == val2->data.u.object);
     }
 
+    if (njs_is_object(val1) && njs_is_object(val2)) {
+        return 0;
+    }
+
     return njs_trap(vm, NJS_TRAP_NUMBERS);
 }
 
diff -r abec5f8d55a1 -r 025b22bf8c49 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Fri Nov 09 18:05:39 2018 +0300
+++ b/njs/test/njs_unit_test.c	Thu Nov 08 20:32:45 2018 +0300
@@ -1136,6 +1136,12 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("({}) == false"),
       nxt_string("false") },
 
+    { nxt_string("new Number(1) == new String('1')"),
+      nxt_string("false") },
+
+    { nxt_string("var a = Object; a == Object"),
+      nxt_string("true") },
+
     { nxt_string("var a = { valueOf: function() { return 5 } };   a == 5"),
       nxt_string("true") },
 


More information about the nginx-devel mailing list