Bug 952870 - Treat -0 and 0 as the same key in Maps and Sets. r=jorendorff

--HG--
extra : rebase_source : c5fb6daf43530d67bfb60c24ac8ceecd2fa0b60d
This commit is contained in:
Till Schneidereit 2014-02-01 23:30:44 +01:00
parent 36d54591b5
commit 22ea5f0853
5 changed files with 26 additions and 37 deletions

View File

@ -21,7 +21,7 @@
using namespace js;
using mozilla::DoubleIsInt32;
using mozilla::DoubleEqualsInt32;
using mozilla::Forward;
using mozilla::IsNaN;
using mozilla::Move;
@ -784,7 +784,7 @@ HashableValue::setValue(JSContext *cx, HandleValue v)
} else if (v.isDouble()) {
double d = v.toDouble();
int32_t i;
if (DoubleIsInt32(d, &i)) {
if (DoubleEqualsInt32(d, &i)) {
// Normalize int32_t-valued doubles to int32_t for faster hashing and testing.
value = Int32Value(i);
} else if (IsNaN(d)) {

View File

@ -1,17 +0,0 @@
// Binary: cache/js-dbg-32-b6aa44d8f11f-linux
// Flags:
//
gczeal(4);
var s = new Set;
s.add(-0);
s.add(0);
assertEq(s.delete(-0), true);
assertEq(s.has(0), (true ));
assertEq(s.has(-0), false);
var m = new Map;
m.set(-0, 'x');
assertEq(m.has(0), false);
assertEq(m.get(0), undefined);
assertEq(m.has(-0), true);
assertEq(m.delete(-0), true);

View File

@ -5,11 +5,11 @@ var s = new Set;
s.add(-0);
s.add(0);
assertEq(s.delete(-0), true);
assertEq(s.has(0), (true ));
assertEq(s.has(0), (false ));
assertEq(s.has(-0), false);
var m = new Map;
m.set(-0, 'x');
assertEq(m.has(0), false);
assertEq(m.get(0), undefined);
assertEq(m.has(0), true);
assertEq(m.get(0), 'x');
assertEq(m.has(-0), true);
assertEq(m.delete(-0), true);

View File

@ -13,7 +13,7 @@ var keys = [undefined, null, true, false,
-1, -65536, -2147483648,
0.5, Math.sqrt(81), Math.PI,
Number.MAX_VALUE, -Number.MAX_VALUE, Number.MIN_VALUE, -Number.MIN_VALUE,
-0, NaN, Infinity, -Infinity,
NaN, Infinity, -Infinity,
"", "\0", "a", "ab", "abcdefg", rope(),
{}, [], /a*b/, Object.prototype, Object];

View File

@ -1,37 +1,43 @@
// -0 is a distinct key from +0.
// -0 is treated as the same key as +0.
var s = new Set;
s.add(-0);
assertEq(s.has(0), false);
assertEq(s.has(0), true);
assertEq(s.has(-0), true);
assertEq(s.delete(0), false);
assertEq(s.has(-0), true);
assertEq(s.delete(0), true);
assertEq(s.has(-0), false);
assertEq(s.has(0), false);
s.add(0);
assertEq(s.delete(-0), true);
assertEq(s.has(0), true);
assertEq(s.has(-0), true);
assertEq(s.delete(-0), true);
assertEq(s.has(-0), false);
assertEq(s.has(0), false);
var m = new Map;
m.set(-0, 'x');
assertEq(m.has(0), true);
assertEq(m.get(0), 'x');
assertEq(m.has(-0), true);
assertEq(m.get(-0), 'x');
assertEq(m.delete(0), true);
assertEq(m.has(-0), false);
assertEq(m.get(-0), undefined);
assertEq(m.has(0), false);
assertEq(m.get(0), undefined);
assertEq(m.has(-0), true);
assertEq(m.get(-0), 'x');
assertEq(m.delete(0), false);
assertEq(m.has(-0), true);
assertEq(m.get(-0), 'x');
m.set(-0, 'x');
m.set(0, 'y');
assertEq(m.has(0), true);
assertEq(m.get(0), 'y');
assertEq(m.has(-0), true);
assertEq(m.get(-0), 'x');
assertEq(m.get(-0), 'y');
assertEq(m.delete(-0), true);
assertEq(m.has(0), true);
assertEq(m.get(0), 'y');
assertEq(m.has(0), false);
assertEq(m.get(0), undefined);
assertEq(m.has(-0), false);
assertEq(m.get(-0), undefined);