[PATCH 7/9] jscript: Compare numbers in a Map bitwise for equality.

Gabriel Ivăncescu gabrielopcode at gmail.com
Thu Apr 14 11:24:44 CDT 2022


Native treats -0 and 0 differently, so it must be doing a bitwise
comparison. This might not order the numbers correctly, but that's not
important, since we don't need them sorted other than for quick lookup
(and any arbitrary sorting is fine, as long as it's consistent).

Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/jscript/set.c                | 11 +++++++++--
 dlls/mshtml/tests/documentmode.js |  9 +++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/set.c b/dlls/jscript/set.c
index 281049a..bdfe7b7 100644
--- a/dlls/jscript/set.c
+++ b/dlls/jscript/set.c
@@ -56,6 +56,10 @@ static int jsval_map_compare(const void *k, const struct wine_rb_entry *e)
 {
     const struct jsval_map_entry *entry = WINE_RB_ENTRY_VALUE(e, const struct jsval_map_entry, entry);
     const jsval_t *key = k;
+    union {
+        double d;
+        INT64 n;
+    } bits1, bits2;
 
     if(jsval_type(entry->key) != jsval_type(*key))
         return (int)jsval_type(entry->key) - (int)jsval_type(*key);
@@ -70,10 +74,13 @@ static int jsval_map_compare(const void *k, const struct wine_rb_entry *e)
     case JSV_STRING:
         return jsstr_cmp(get_string(*key), get_string(entry->key));
     case JSV_NUMBER:
-        if(get_number(*key) == get_number(entry->key)) return 0;
         if(isnan(get_number(*key))) return isnan(get_number(entry->key)) ? 0 : -1;
         if(isnan(get_number(entry->key))) return 1;
-        return get_number(*key) < get_number(entry->key) ? -1 : 1;
+
+        /* native treats -0 differently than 0, so need to compare bitwise */
+        bits1.d = get_number(*key);
+        bits2.d = get_number(entry->key);
+        return (bits1.n == bits2.n) ? 0 : (bits1.n < bits2.n ? -1 : 1);
     case JSV_BOOL:
         if(get_bool(*key) == get_bool(entry->key)) return 0;
         return get_bool(*key) ? 1 : -1;
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js
index 0da8d12..6d06dad 100644
--- a/dlls/mshtml/tests/documentmode.js
+++ b/dlls/mshtml/tests/documentmode.js
@@ -1051,6 +1051,15 @@ sync_test("map_obj", function() {
     });
     ok(i === 66, "i = " + i);
 
+    s = new Map();
+    s.set(0,  10);
+    s.set(-0, 20);
+    ok(s.size === 2, "size = " + s.size + " expected 2");
+    r = s.get(-0);
+    ok(r === 20, "get(-0) returned " + r);
+    r = s.get(0);
+    ok(r === 10, "get(0) returned " + r);
+
     try {
         Map.prototype.set.call({}, 1, 2);
         ok(false, "expected exception");
-- 
2.34.1




More information about the wine-devel mailing list