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@gmail.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2022-04-14 19:24:44 +03:00 committed by Alexandre Julliard
parent 251eda6f56
commit 15053a1d17
2 changed files with 18 additions and 2 deletions

View file

@ -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;

View file

@ -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");