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

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: Fix last issues. 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 primitive valu e.
wingo 2014/09/30 16:01:36 80 characters here and in other places in the test
699 // See ECMA-262, Annex C.
700 var a = [];
701 set.forEach(function() { a.push(this) }, "");
702 assertTrue(a[0] !== a[1]);
703
704 // Do not create a new object otherwise.
705 a = [];
706 set.forEach(function() { a.push(this); }, {});
707 assertFalse(a[0] !== a[1]);
708 })();
709
710
711 (function TestSetForEachReceiverAsObjectInStrictMode() {
712 var set = new Set(["1", "2"]);
713
714 // In strict mode primitive values should not be coerced to an object.
715 var a = [];
716 set.forEach(function() { 'use strict'; a.push(this); }, "");
717 assertTrue(a[0] === "" && a[0] === a[1]);
718 })();
719
720
694 (function TestMapForEachInvalidTypes() { 721 (function TestMapForEachInvalidTypes() {
695 assertThrows(function() { 722 assertThrows(function() {
696 Map.prototype.map.forEach.call({}); 723 Map.prototype.map.forEach.call({});
697 }, TypeError); 724 }, TypeError);
698 725
699 var map = new Map(); 726 var map = new Map();
700 assertThrows(function() { 727 assertThrows(function() {
701 map.forEach({}); 728 map.forEach({});
702 }, TypeError); 729 }, TypeError);
703 })(); 730 })();
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 for (var i = 5; i < 16; i++) { 1018 for (var i = 5; i < 16; i++) {
992 map.delete(i); 1019 map.delete(i);
993 } 1020 }
994 } 1021 }
995 }); 1022 });
996 1023
997 assertArrayEquals([0, 1, 2, 3, 4], buffer); 1024 assertArrayEquals([0, 1, 2, 3, 4], buffer);
998 })(); 1025 })();
999 1026
1000 1027
1028 (function TestMapForEachReceiverAsObject() {
1029 var map = new Map();
1030 map.set("key1", "value1");
1031 map.set("key2", "value2");
1032
1033 // Create a new object in each function call when receiver is a primitive valu e.
1034 // See ECMA-262, Annex C.
1035 var a = [];
1036 map.forEach(function() { a.push(this) }, "");
1037 assertTrue(a[0] !== a[1]);
1038
1039 // Do not create a new object otherwise.
1040 a = [];
1041 map.forEach(function() { a.push(this); }, {});
1042 assertFalse(a[0] !== a[1]);
1043 })();
1044
1045
1046 (function TestMapForEachReceiverAsObjectInStrictMode() {
1047 var map = new Map();
1048 map.set("key1", "value1");
1049 map.set("key2", "value2");
1050
1051 // In strict mode primitive values should not be coerced to an object.
1052 var a = [];
1053 map.forEach(function() { 'use strict'; a.push(this); }, "");
1054 assertTrue(a[0] === "" && a[0] === a[1]);
1055 })();
1056
1057
1001 // Allows testing iterator-based constructors easily. 1058 // Allows testing iterator-based constructors easily.
1002 var oneAndTwo = new Map(); 1059 var oneAndTwo = new Map();
1003 var k0 = {key: 0}; 1060 var k0 = {key: 0};
1004 var k1 = {key: 1}; 1061 var k1 = {key: 1};
1005 var k2 = {key: 2}; 1062 var k2 = {key: 2};
1006 oneAndTwo.set(k1, 1); 1063 oneAndTwo.set(k1, 1);
1007 oneAndTwo.set(k2, 2); 1064 oneAndTwo.set(k2, 2);
1008 1065
1009 1066
1010 function TestSetConstructor(ctor) { 1067 function TestSetConstructor(ctor) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1416
1360 var map = new ctor(42); 1417 var map = new ctor(42);
1361 assertSize(2, map); 1418 assertSize(2, map);
1362 assertEquals(1, map.get(k1)); 1419 assertEquals(1, map.get(k1));
1363 assertEquals(2, map.get(k2)); 1420 assertEquals(2, map.get(k2));
1364 1421
1365 delete Number.prototype[Symbol.iterator]; 1422 delete Number.prototype[Symbol.iterator];
1366 } 1423 }
1367 TestMapConstructorIterableValue(Map); 1424 TestMapConstructorIterableValue(Map);
1368 TestMapConstructorIterableValue(WeakMap); 1425 TestMapConstructorIterableValue(WeakMap);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698