OLD | NEW |
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 Loading... |
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); | |
1021 | 1018 |
1022 // @@iterator not callable | 1019 // @@iterator not callable |
1023 assertThrows(function() { | 1020 assertThrows(function() { |
1024 var object = {}; | 1021 var object = {}; |
1025 object[Symbol.iterator] = 42; | 1022 object[Symbol.iterator] = 42; |
1026 new ctor(object); | 1023 new ctor(object); |
1027 }, TypeError); | 1024 }, TypeError); |
1028 | 1025 |
1029 // @@iterator result not object | 1026 // @@iterator result not object |
1030 assertThrows(function() { | 1027 assertThrows(function() { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 TestSetConstructorNextNotAnObject(WeakSet); | 1141 TestSetConstructorNextNotAnObject(WeakSet); |
1145 | 1142 |
1146 | 1143 |
1147 (function TestWeakSetConstructorNonObjectKeys() { | 1144 (function TestWeakSetConstructorNonObjectKeys() { |
1148 assertThrows(function() { | 1145 assertThrows(function() { |
1149 new WeakSet([1]); | 1146 new WeakSet([1]); |
1150 }, TypeError); | 1147 }, TypeError); |
1151 })(); | 1148 })(); |
1152 | 1149 |
1153 | 1150 |
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 | |
1187 function TestMapConstructor(ctor) { | 1151 function TestMapConstructor(ctor) { |
1188 var m = new ctor(null); | 1152 var m = new ctor(null); |
1189 assertSize(0, m); | 1153 assertSize(0, m); |
1190 | 1154 |
1191 m = new ctor(undefined); | 1155 m = new ctor(undefined); |
1192 assertSize(0, m); | 1156 assertSize(0, m); |
1193 | 1157 |
1194 // No @@iterator | 1158 // No @@iterator |
1195 assertThrows(function() { | 1159 assertThrows(function() { |
1196 new ctor({}); | 1160 new ctor({}); |
1197 }, TypeError); | 1161 }, TypeError); |
1198 assertThrows(function() { | |
1199 new ctor(true); | |
1200 }, TypeError); | |
1201 | 1162 |
1202 // @@iterator not callable | 1163 // @@iterator not callable |
1203 assertThrows(function() { | 1164 assertThrows(function() { |
1204 var object = {}; | 1165 var object = {}; |
1205 object[Symbol.iterator] = 42; | 1166 object[Symbol.iterator] = 42; |
1206 new ctor(object); | 1167 new ctor(object); |
1207 }, TypeError); | 1168 }, TypeError); |
1208 | 1169 |
1209 // @@iterator result not object | 1170 // @@iterator result not object |
1210 assertThrows(function() { | 1171 assertThrows(function() { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 } | 1293 } |
1333 TestMapConstructorIteratorNotObjectValues(Map); | 1294 TestMapConstructorIteratorNotObjectValues(Map); |
1334 TestMapConstructorIteratorNotObjectValues(WeakMap); | 1295 TestMapConstructorIteratorNotObjectValues(WeakMap); |
1335 | 1296 |
1336 | 1297 |
1337 (function TestWeakMapConstructorNonObjectKeys() { | 1298 (function TestWeakMapConstructorNonObjectKeys() { |
1338 assertThrows(function() { | 1299 assertThrows(function() { |
1339 new WeakMap([[1, 2]]) | 1300 new WeakMap([[1, 2]]) |
1340 }, TypeError); | 1301 }, TypeError); |
1341 })(); | 1302 })(); |
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); | |
OLD | NEW |