Gabriel Ivăncescu : jscript: Compare numbers in a Map bitwise for equality.

Alexandre Julliard julliard at winehq.org
Thu Apr 14 16:50:34 CDT 2022


Module: wine
Branch: master
Commit: 15053a1d17039980fff50e06e84ba29c197e0616
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=15053a1d17039980fff50e06e84ba29c197e0616

Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date:   Thu Apr 14 19:24:44 2022 +0300

jscript: Compare numbers in a Map bitwise for equality.

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>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 281049a91ae..bdfe7b75e55 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 0da8d129383..6d06dad9fc7 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");




More information about the wine-cvs mailing list