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

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: Created wrapper. Added tests for strict mode. Fixed nits. 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 // When evaluating 'this', primitive values should be coerced to an object.
699 // See ECMA-262, Annex C.
700 var a = [];
701 set.forEach(function() { a.push(this) }, "");
702 assertTrue(a[0] !== a[1]);
703
704 // When evaluating 'this', non-primitive values are not coerced to an object.
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, when evaluating 'this', primitive values should not be
715 // coerced to an object. See ECMA-262, Annex C.
716 var a = [];
717 set.forEach(function() { 'use strict'; a.push(this); }, "");
718 assertTrue(a[0] === "" && a[0] === a[1]);
719 })();
720
721
694 (function TestMapForEachInvalidTypes() { 722 (function TestMapForEachInvalidTypes() {
695 assertThrows(function() { 723 assertThrows(function() {
696 Map.prototype.map.forEach.call({}); 724 Map.prototype.map.forEach.call({});
697 }, TypeError); 725 }, TypeError);
698 726
699 var map = new Map(); 727 var map = new Map();
700 assertThrows(function() { 728 assertThrows(function() {
701 map.forEach({}); 729 map.forEach({});
702 }, TypeError); 730 }, TypeError);
703 })(); 731 })();
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 for (var i = 5; i < 16; i++) { 1019 for (var i = 5; i < 16; i++) {
992 map.delete(i); 1020 map.delete(i);
993 } 1021 }
994 } 1022 }
995 }); 1023 });
996 1024
997 assertArrayEquals([0, 1, 2, 3, 4], buffer); 1025 assertArrayEquals([0, 1, 2, 3, 4], buffer);
998 })(); 1026 })();
999 1027
1000 1028
1029 (function TestMapForEachReceiverAsObject() {
1030 var map = new Map();
1031 map.set("key1", "value1");
1032 map.set("key2", "value2");
1033
1034 // When evaluating 'this', primitive values should be coerced to an object.
1035 // See ECMA-262, Annex C.
1036 var a = [];
1037 map.forEach(function() { a.push(this) }, "");
1038 assertTrue(a[0] !== a[1]);
1039
1040 // When evaluating 'this', non-primitive values are not coerced to an object.
1041 a = [];
1042 map.forEach(function() { a.push(this); }, {});
1043 assertFalse(a[0] !== a[1]);
1044 })();
1045
1046
1047 (function TestMapForEachReceiverAsObjectInStrictMode() {
1048 var map = new Map();
1049 map.set("key1", "value1");
1050 map.set("key2", "value2");
1051
1052 // In strict mode, when evaluating 'this', primitive values should not be
1053 // coerced to an object. See ECMA-262, Annex C.
1054 var a = [];
1055 map.forEach(function() { 'use strict'; a.push(this); }, "");
1056 assertTrue(a[0] === "" && a[0] === a[1]);
1057 })();
1058
1059
1001 // Allows testing iterator-based constructors easily. 1060 // Allows testing iterator-based constructors easily.
1002 var oneAndTwo = new Map(); 1061 var oneAndTwo = new Map();
1003 var k0 = {key: 0}; 1062 var k0 = {key: 0};
1004 var k1 = {key: 1}; 1063 var k1 = {key: 1};
1005 var k2 = {key: 2}; 1064 var k2 = {key: 2};
1006 oneAndTwo.set(k1, 1); 1065 oneAndTwo.set(k1, 1);
1007 oneAndTwo.set(k2, 2); 1066 oneAndTwo.set(k2, 2);
1008 1067
1009 1068
1010 function TestSetConstructor(ctor) { 1069 function TestSetConstructor(ctor) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1418
1360 var map = new ctor(42); 1419 var map = new ctor(42);
1361 assertSize(2, map); 1420 assertSize(2, map);
1362 assertEquals(1, map.get(k1)); 1421 assertEquals(1, map.get(k1));
1363 assertEquals(2, map.get(k2)); 1422 assertEquals(2, map.get(k2));
1364 1423
1365 delete Number.prototype[Symbol.iterator]; 1424 delete Number.prototype[Symbol.iterator];
1366 } 1425 }
1367 TestMapConstructorIterableValue(Map); 1426 TestMapConstructorIterableValue(Map);
1368 TestMapConstructorIterableValue(WeakMap); 1427 TestMapConstructorIterableValue(WeakMap);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698