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

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

Issue 466003002: ES6: Make Map/Set constructors support iterable values (Closed) Base URL: http://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/weak_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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 var s = new ctor(null); 1008 var s = new ctor(null);
1009 assertSize(0, s); 1009 assertSize(0, s);
1010 1010
1011 s = new ctor(undefined); 1011 s = new ctor(undefined);
1012 assertSize(0, s); 1012 assertSize(0, s);
1013 1013
1014 // No @@iterator 1014 // No @@iterator
1015 assertThrows(function() { 1015 assertThrows(function() {
1016 new ctor({}); 1016 new ctor({});
1017 }, TypeError); 1017 }, TypeError);
1018 assertThrows(function() {
1019 new ctor(true);
1020 }, TypeError);
1018 1021
1019 // @@iterator not callable 1022 // @@iterator not callable
1020 assertThrows(function() { 1023 assertThrows(function() {
1021 var object = {}; 1024 var object = {};
1022 object[Symbol.iterator] = 42; 1025 object[Symbol.iterator] = 42;
1023 new ctor(object); 1026 new ctor(object);
1024 }, TypeError); 1027 }, TypeError);
1025 1028
1026 // @@iterator result not object 1029 // @@iterator result not object
1027 assertThrows(function() { 1030 assertThrows(function() {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 TestSetConstructorNextNotAnObject(WeakSet); 1144 TestSetConstructorNextNotAnObject(WeakSet);
1142 1145
1143 1146
1144 (function TestWeakSetConstructorNonObjectKeys() { 1147 (function TestWeakSetConstructorNonObjectKeys() {
1145 assertThrows(function() { 1148 assertThrows(function() {
1146 new WeakSet([1]); 1149 new WeakSet([1]);
1147 }, TypeError); 1150 }, TypeError);
1148 })(); 1151 })();
1149 1152
1150 1153
1154 function TestSetConstructorIterableValue(ctor) {
1155 'use strict';
1156 // Strict mode is required to prevent implicit wrapping in the getter.
1157 Object.defineProperty(Number.prototype, Symbol.iterator, {
1158 get: function() {
1159 assertEquals('object', typeof this);
1160 return function() {
1161 return oneAndTwo.keys();
1162 };
1163 },
1164 configurable: true
1165 });
1166
1167 var set = new ctor(42);
1168 assertSize(2, set);
1169 assertTrue(set.has(k1));
1170 assertTrue(set.has(k2));
1171
1172 delete Number.prototype[Symbol.iterator];
1173 }
1174 TestSetConstructorIterableValue(Set);
1175 TestSetConstructorIterableValue(WeakSet);
1176
1177
1178 (function TestSetConstructorStringValue() {
1179 var s = new Set('abc');
1180 assertSize(3, s);
1181 assertTrue(s.has('a'));
1182 assertTrue(s.has('b'));
1183 assertTrue(s.has('c'));
1184 })();
1185
1186
1151 function TestMapConstructor(ctor) { 1187 function TestMapConstructor(ctor) {
1152 var m = new ctor(null); 1188 var m = new ctor(null);
1153 assertSize(0, m); 1189 assertSize(0, m);
1154 1190
1155 m = new ctor(undefined); 1191 m = new ctor(undefined);
1156 assertSize(0, m); 1192 assertSize(0, m);
1157 1193
1158 // No @@iterator 1194 // No @@iterator
1159 assertThrows(function() { 1195 assertThrows(function() {
1160 new ctor({}); 1196 new ctor({});
1161 }, TypeError); 1197 }, TypeError);
1198 assertThrows(function() {
1199 new ctor(true);
1200 }, TypeError);
1162 1201
1163 // @@iterator not callable 1202 // @@iterator not callable
1164 assertThrows(function() { 1203 assertThrows(function() {
1165 var object = {}; 1204 var object = {};
1166 object[Symbol.iterator] = 42; 1205 object[Symbol.iterator] = 42;
1167 new ctor(object); 1206 new ctor(object);
1168 }, TypeError); 1207 }, TypeError);
1169 1208
1170 // @@iterator result not object 1209 // @@iterator result not object
1171 assertThrows(function() { 1210 assertThrows(function() {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 } 1332 }
1294 TestMapConstructorIteratorNotObjectValues(Map); 1333 TestMapConstructorIteratorNotObjectValues(Map);
1295 TestMapConstructorIteratorNotObjectValues(WeakMap); 1334 TestMapConstructorIteratorNotObjectValues(WeakMap);
1296 1335
1297 1336
1298 (function TestWeakMapConstructorNonObjectKeys() { 1337 (function TestWeakMapConstructorNonObjectKeys() {
1299 assertThrows(function() { 1338 assertThrows(function() {
1300 new WeakMap([[1, 2]]) 1339 new WeakMap([[1, 2]])
1301 }, TypeError); 1340 }, TypeError);
1302 })(); 1341 })();
1342
1343
1344 function TestMapConstructorIterableValue(ctor) {
1345 'use strict';
1346 // Strict mode is required to prevent implicit wrapping in the getter.
1347 Object.defineProperty(Number.prototype, Symbol.iterator, {
1348 get: function() {
1349 assertEquals('object', typeof this);
1350 return function() {
1351 return oneAndTwo.entries();
1352 };
1353 },
1354 configurable: true
1355 });
1356
1357 var map = new ctor(42);
1358 assertSize(2, map);
1359 assertEquals(1, map.get(k1));
1360 assertEquals(2, map.get(k2));
1361
1362 delete Number.prototype[Symbol.iterator];
1363 }
1364 TestMapConstructorIterableValue(Map);
1365 TestMapConstructorIterableValue(WeakMap);
OLDNEW
« no previous file with comments | « src/weak_collection.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698