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

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

Issue 553413002: Array.prototype.{every, filter, find, findIndex, forEach, map, some}: Use fresh primitive wrapper f… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Apply same changes to MapForEach and SetForEach Created 6 years, 3 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
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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 var accumulated = 0; 684 var accumulated = 0;
685 set.forEach(function(v) { 685 set.forEach(function(v) {
686 accumulated += v; 686 accumulated += v;
687 if (v % 10 === 0) { 687 if (v % 10 === 0) {
688 gc(); 688 gc();
689 } 689 }
690 }); 690 });
691 assertEquals(4950, accumulated); 691 assertEquals(4950, accumulated);
692 })(); 692 })();
693 693
694
695 (function TestSetForEachReceiverAsObject() {
696 var set = new Set(["1", "2"]);
697
698 // Create a new object in each function call when receiver is a
699 // primitive value.
700 var a = [];
701 set.forEach(function() { a.push(this); }, "");
702 assertTrue(a[0] !== a[1]);
703
704 // Do not create a new object in each function call when receiver is a
705 // primitive value.
706 a = [];
707 set.forEach(function() { a.push(this); }, {});
708 assertFalse(a[0] !== a[1]);
709 })();
710
711
694 (function TestMapForEachInvalidTypes() { 712 (function TestMapForEachInvalidTypes() {
695 assertThrows(function() { 713 assertThrows(function() {
696 Map.prototype.map.forEach.call({}); 714 Map.prototype.map.forEach.call({});
697 }, TypeError); 715 }, TypeError);
698 716
699 var map = new Map(); 717 var map = new Map();
700 assertThrows(function() { 718 assertThrows(function() {
701 map.forEach({}); 719 map.forEach({});
702 }, TypeError); 720 }, TypeError);
703 })(); 721 })();
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 for (var i = 5; i < 16; i++) { 1009 for (var i = 5; i < 16; i++) {
992 map.delete(i); 1010 map.delete(i);
993 } 1011 }
994 } 1012 }
995 }); 1013 });
996 1014
997 assertArrayEquals([0, 1, 2, 3, 4], buffer); 1015 assertArrayEquals([0, 1, 2, 3, 4], buffer);
998 })(); 1016 })();
999 1017
1000 1018
1019 (function TestMapForEachReceiverAsObject() {
1020 var map = new Map();
1021 map.set("key1", "value1");
1022 map.set("key2", "value2");
1023
1024 // Create a new object in each function call when receiver is a
1025 // primitive value.
1026 var a = [];
1027 map.forEach(function() { a.push(this); }, "");
1028 assertTrue(a[0] !== a[1]);
1029
1030 // Do not create a new object in each function call when receiver is a
1031 // primitive value.
1032 a = [];
1033 map.forEach(function() { a.push(this); }, {});
1034 assertFalse(a[0] !== a[1]);
1035 })();
1036
1037
1001 // Allows testing iterator-based constructors easily. 1038 // Allows testing iterator-based constructors easily.
1002 var oneAndTwo = new Map(); 1039 var oneAndTwo = new Map();
1003 var k0 = {key: 0}; 1040 var k0 = {key: 0};
1004 var k1 = {key: 1}; 1041 var k1 = {key: 1};
1005 var k2 = {key: 2}; 1042 var k2 = {key: 2};
1006 oneAndTwo.set(k1, 1); 1043 oneAndTwo.set(k1, 1);
1007 oneAndTwo.set(k2, 2); 1044 oneAndTwo.set(k2, 2);
1008 1045
1009 1046
1010 function TestSetConstructor(ctor) { 1047 function TestSetConstructor(ctor) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1396
1360 var map = new ctor(42); 1397 var map = new ctor(42);
1361 assertSize(2, map); 1398 assertSize(2, map);
1362 assertEquals(1, map.get(k1)); 1399 assertEquals(1, map.get(k1));
1363 assertEquals(2, map.get(k2)); 1400 assertEquals(2, map.get(k2));
1364 1401
1365 delete Number.prototype[Symbol.iterator]; 1402 delete Number.prototype[Symbol.iterator];
1366 } 1403 }
1367 TestMapConstructorIterableValue(Map); 1404 TestMapConstructorIterableValue(Map);
1368 TestMapConstructorIterableValue(WeakMap); 1405 TestMapConstructorIterableValue(WeakMap);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698