Revision: 23204
Author: [email protected]
Date: Tue Aug 19 15:15:41 2014 UTC
Log: ES6: Make sure we do not store -0 as the key in Map/Set
BUG=v8:3515
LOG=Y
[email protected], [email protected]
Review URL: https://codereview.chromium.org/478683002
http://code.google.com/p/v8/source/detail?r=23204
Modified:
/branches/bleeding_edge/src/collection.js
/branches/bleeding_edge/test/mjsunit/es6/collections.js
=======================================
--- /branches/bleeding_edge/src/collection.js Wed Aug 13 14:34:15 2014 UTC
+++ /branches/bleeding_edge/src/collection.js Tue Aug 19 15:15:41 2014 UTC
@@ -49,6 +49,13 @@
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.add', this]);
}
+ // Normalize -0 to +0 as required by the spec.
+ // Even though we use SameValueZero as the comparison for the keys we
don't
+ // want to ever store -0 as the key since the key is directly exposed
when
+ // doing iteration.
+ if (key === 0) {
+ key = 0;
+ }
return %SetAdd(this, key);
}
@@ -186,6 +193,13 @@
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.set', this]);
}
+ // Normalize -0 to +0 as required by the spec.
+ // Even though we use SameValueZero as the comparison for the keys we
don't
+ // want to ever store -0 as the key since the key is directly exposed
when
+ // doing iteration.
+ if (key === 0) {
+ key = 0;
+ }
return %MapSet(this, key, value);
}
=======================================
--- /branches/bleeding_edge/test/mjsunit/es6/collections.js Wed Aug 13
14:34:15 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/es6/collections.js Tue Aug 19
15:15:41 2014 UTC
@@ -117,7 +117,8 @@
TestMapping(m, i / 10, new Object);
TestMapping(m, 'key-' + i, new Object);
}
- var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined
];
+ // -0 is handled in TestMinusZeroMap
+ var keys = [ 0, +Infinity, -Infinity, true, false, null, undefined ];
for (var i = 0; i < keys.length; i++) {
TestMapping(m, keys[i], new Object);
}
@@ -495,24 +496,26 @@
(function TestMinusZeroSet() {
- var m = new Set();
- m.add(0);
- m.add(-0);
- assertEquals(1, m.size);
- assertTrue(m.has(0));
- assertTrue(m.has(-0));
+ var s = new Set();
+ s.add(-0);
+ assertSame(0, s.values().next().value);
+ s.add(0);
+ assertEquals(1, s.size);
+ assertTrue(s.has(0));
+ assertTrue(s.has(-0));
})();
(function TestMinusZeroMap() {
var m = new Map();
+ m.set(-0, 'minus');
+ assertSame(0, m.keys().next().value);
m.set(0, 'plus');
- m.set(-0, 'minus');
assertEquals(1, m.size);
assertTrue(m.has(0));
assertTrue(m.has(-0));
- assertEquals('minus', m.get(0));
- assertEquals('minus', m.get(-0));
+ assertEquals('plus', m.get(0));
+ assertEquals('plus', m.get(-0));
})();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.