Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: test/mjsunit/es6/collections.js

Issue 478683002: ES6: Make sure we do not store -0 as the key in Map/Set (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/collection.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 TestMapBehavior1(new WeakMap); 110 TestMapBehavior1(new WeakMap);
111 111
112 112
113 // Test expected mapping behavior for Maps only 113 // Test expected mapping behavior for Maps only
114 function TestMapBehavior2(m) { 114 function TestMapBehavior2(m) {
115 for (var i = 0; i < 20; i++) { 115 for (var i = 0; i < 20; i++) {
116 TestMapping(m, i, new Object); 116 TestMapping(m, i, new Object);
117 TestMapping(m, i / 10, new Object); 117 TestMapping(m, i / 10, new Object);
118 TestMapping(m, 'key-' + i, new Object); 118 TestMapping(m, 'key-' + i, new Object);
119 } 119 }
120 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; 120 // -0 is handled in TestMinusZeroMap
121 var keys = [ 0, +Infinity, -Infinity, true, false, null, undefined ];
121 for (var i = 0; i < keys.length; i++) { 122 for (var i = 0; i < keys.length; i++) {
122 TestMapping(m, keys[i], new Object); 123 TestMapping(m, keys[i], new Object);
123 } 124 }
124 } 125 }
125 TestMapBehavior2(new Map); 126 TestMapBehavior2(new Map);
126 127
127 128
128 // Test expected querying behavior of Maps and WeakMaps 129 // Test expected querying behavior of Maps and WeakMaps
129 function TestQuery(m) { 130 function TestQuery(m) {
130 var key = new Object; 131 var key = new Object;
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 var k = new Object(); 489 var k = new Object();
489 var w = new WeakSet(); 490 var w = new WeakSet();
490 w.add(k); 491 w.add(k);
491 assertTrue(w.has(k)); 492 assertTrue(w.has(k));
492 w.clear(); 493 w.clear();
493 assertFalse(w.has(k)); 494 assertFalse(w.has(k));
494 })(); 495 })();
495 496
496 497
497 (function TestMinusZeroSet() { 498 (function TestMinusZeroSet() {
498 var m = new Set(); 499 var s = new Set();
499 m.add(0); 500 s.add(-0);
500 m.add(-0); 501 assertSame(0, s.values().next().value);
501 assertEquals(1, m.size); 502 s.add(0);
502 assertTrue(m.has(0)); 503 assertEquals(1, s.size);
503 assertTrue(m.has(-0)); 504 assertTrue(s.has(0));
505 assertTrue(s.has(-0));
504 })(); 506 })();
505 507
506 508
507 (function TestMinusZeroMap() { 509 (function TestMinusZeroMap() {
508 var m = new Map(); 510 var m = new Map();
511 m.set(-0, 'minus');
512 assertSame(0, m.keys().next().value);
509 m.set(0, 'plus'); 513 m.set(0, 'plus');
510 m.set(-0, 'minus');
511 assertEquals(1, m.size); 514 assertEquals(1, m.size);
512 assertTrue(m.has(0)); 515 assertTrue(m.has(0));
513 assertTrue(m.has(-0)); 516 assertTrue(m.has(-0));
514 assertEquals('minus', m.get(0)); 517 assertEquals('plus', m.get(0));
515 assertEquals('minus', m.get(-0)); 518 assertEquals('plus', m.get(-0));
516 })(); 519 })();
517 520
518 521
519 (function TestSetForEachInvalidTypes() { 522 (function TestSetForEachInvalidTypes() {
520 assertThrows(function() { 523 assertThrows(function() {
521 Set.prototype.set.forEach.call({}); 524 Set.prototype.set.forEach.call({});
522 }, TypeError); 525 }, TypeError);
523 526
524 var set = new Set(); 527 var set = new Set();
525 assertThrows(function() { 528 assertThrows(function() {
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 1359
1357 var map = new ctor(42); 1360 var map = new ctor(42);
1358 assertSize(2, map); 1361 assertSize(2, map);
1359 assertEquals(1, map.get(k1)); 1362 assertEquals(1, map.get(k1));
1360 assertEquals(2, map.get(k2)); 1363 assertEquals(2, map.get(k2));
1361 1364
1362 delete Number.prototype[Symbol.iterator]; 1365 delete Number.prototype[Symbol.iterator];
1363 } 1366 }
1364 TestMapConstructorIterableValue(Map); 1367 TestMapConstructorIterableValue(Map);
1365 TestMapConstructorIterableValue(WeakMap); 1368 TestMapConstructorIterableValue(WeakMap);
OLDNEW
« no previous file with comments | « src/collection.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698