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

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

Issue 139973004: A64: Synchronize with r15814. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 | « test/mjsunit/harmony/block-let-crankshaft.js ('k') | test/mjsunit/harmony/numeric-literals.js » ('j') | 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 17 matching lines...) Expand all
28 // Flags: --harmony-collections --expose-gc --allow-natives-syntax 28 // Flags: --harmony-collections --expose-gc --allow-natives-syntax
29 29
30 30
31 // Test valid getter and setter calls on Sets. 31 // Test valid getter and setter calls on Sets.
32 function TestValidSetCalls(m) { 32 function TestValidSetCalls(m) {
33 assertDoesNotThrow(function () { m.add(new Object) }); 33 assertDoesNotThrow(function () { m.add(new Object) });
34 assertDoesNotThrow(function () { m.has(new Object) }); 34 assertDoesNotThrow(function () { m.has(new Object) });
35 assertDoesNotThrow(function () { m.delete(new Object) }); 35 assertDoesNotThrow(function () { m.delete(new Object) });
36 } 36 }
37 TestValidSetCalls(new Set); 37 TestValidSetCalls(new Set);
38 TestValidSetCalls(new WeakSet);
38 39
39 40
40 // Test valid getter and setter calls on Maps and WeakMaps 41 // Test valid getter and setter calls on Maps and WeakMaps
41 function TestValidMapCalls(m) { 42 function TestValidMapCalls(m) {
42 assertDoesNotThrow(function () { m.get(new Object) }); 43 assertDoesNotThrow(function () { m.get(new Object) });
43 assertDoesNotThrow(function () { m.set(new Object) }); 44 assertDoesNotThrow(function () { m.set(new Object) });
44 assertDoesNotThrow(function () { m.has(new Object) }); 45 assertDoesNotThrow(function () { m.has(new Object) });
45 assertDoesNotThrow(function () { m.delete(new Object) }); 46 assertDoesNotThrow(function () { m.delete(new Object) });
46 } 47 }
47 TestValidMapCalls(new Map); 48 TestValidMapCalls(new Map);
(...skipping 30 matching lines...) Expand all
78 TestSet(set, i); 79 TestSet(set, i);
79 TestSet(set, i / 100); 80 TestSet(set, i / 100);
80 TestSet(set, 'key-' + i); 81 TestSet(set, 'key-' + i);
81 } 82 }
82 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; 83 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ];
83 for (var i = 0; i < keys.length; i++) { 84 for (var i = 0; i < keys.length; i++) {
84 TestSet(set, keys[i]); 85 TestSet(set, keys[i]);
85 } 86 }
86 } 87 }
87 TestSetBehavior(new Set); 88 TestSetBehavior(new Set);
89 TestSet(new WeakSet, new Object);
88 90
89 91
90 // Test expected mapping behavior for Maps and WeakMaps 92 // Test expected mapping behavior for Maps and WeakMaps
91 function TestMapping(map, key, value) { 93 function TestMapping(map, key, value) {
92 assertSame(undefined, map.set(key, value)); 94 assertSame(undefined, map.set(key, value));
93 assertSame(value, map.get(key)); 95 assertSame(value, map.get(key));
94 } 96 }
95 function TestMapBehavior1(m) { 97 function TestMapBehavior1(m) {
96 TestMapping(m, new Object, 23); 98 TestMapping(m, new Object, 23);
97 TestMapping(m, new Object, 'the-value'); 99 TestMapping(m, new Object, 'the-value');
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 for (var p in x) array.push(p); 180 for (var p in x) array.push(p);
179 return array.sort(); 181 return array.sort();
180 } 182 }
181 assertArrayEquals([], props(func)); 183 assertArrayEquals([], props(func));
182 assertArrayEquals([], props(func.prototype)); 184 assertArrayEquals([], props(func.prototype));
183 assertArrayEquals([], props(new func())); 185 assertArrayEquals([], props(new func()));
184 } 186 }
185 TestEnumerable(Set); 187 TestEnumerable(Set);
186 TestEnumerable(Map); 188 TestEnumerable(Map);
187 TestEnumerable(WeakMap); 189 TestEnumerable(WeakMap);
190 TestEnumerable(WeakSet);
188 191
189 192
190 // Test arbitrary properties on Maps and WeakMaps 193 // Test arbitrary properties on Maps and WeakMaps
191 function TestArbitrary(m) { 194 function TestArbitrary(m) {
192 function TestProperty(map, property, value) { 195 function TestProperty(map, property, value) {
193 map[property] = value; 196 map[property] = value;
194 assertEquals(value, map[property]); 197 assertEquals(value, map[property]);
195 } 198 }
196 for (var i = 0; i < 20; i++) { 199 for (var i = 0; i < 20; i++) {
197 TestProperty(m, i, 'val' + i); 200 TestProperty(m, i, 'val' + i);
198 TestProperty(m, 'foo' + i, 'bar' + i); 201 TestProperty(m, 'foo' + i, 'bar' + i);
199 } 202 }
200 TestMapping(m, new Object, 'foobar'); 203 TestMapping(m, new Object, 'foobar');
201 } 204 }
202 TestArbitrary(new Map); 205 TestArbitrary(new Map);
203 TestArbitrary(new WeakMap); 206 TestArbitrary(new WeakMap);
204 207
205 208
206 // Test direct constructor call 209 // Test direct constructor call
207 assertTrue(Set() instanceof Set); 210 assertTrue(Set() instanceof Set);
208 assertTrue(Map() instanceof Map); 211 assertTrue(Map() instanceof Map);
209 assertTrue(WeakMap() instanceof WeakMap); 212 assertTrue(WeakMap() instanceof WeakMap);
213 assertTrue(WeakSet() instanceof WeakSet);
210 214
211 215
212 // Test whether NaN values as keys are treated correctly. 216 // Test whether NaN values as keys are treated correctly.
213 var s = new Set; 217 var s = new Set;
214 assertFalse(s.has(NaN)); 218 assertFalse(s.has(NaN));
215 assertFalse(s.has(NaN + 1)); 219 assertFalse(s.has(NaN + 1));
216 assertFalse(s.has(23)); 220 assertFalse(s.has(23));
217 s.add(NaN); 221 s.add(NaN);
218 assertTrue(s.has(NaN)); 222 assertTrue(s.has(NaN));
219 assertTrue(s.has(NaN + 1)); 223 assertTrue(s.has(NaN + 1));
220 assertFalse(s.has(23)); 224 assertFalse(s.has(23));
221 var m = new Map; 225 var m = new Map;
222 assertFalse(m.has(NaN)); 226 assertFalse(m.has(NaN));
223 assertFalse(m.has(NaN + 1)); 227 assertFalse(m.has(NaN + 1));
224 assertFalse(m.has(23)); 228 assertFalse(m.has(23));
225 m.set(NaN, 'a-value'); 229 m.set(NaN, 'a-value');
226 assertTrue(m.has(NaN)); 230 assertTrue(m.has(NaN));
227 assertTrue(m.has(NaN + 1)); 231 assertTrue(m.has(NaN + 1));
228 assertFalse(m.has(23)); 232 assertFalse(m.has(23));
229 233
230 234
231 // Test some common JavaScript idioms for Sets 235 // Test some common JavaScript idioms for Sets
232 var s = new Set; 236 var s = new Set;
233 assertTrue(s instanceof Set); 237 assertTrue(s instanceof Set);
234 assertTrue(Set.prototype.add instanceof Function) 238 assertTrue(Set.prototype.add instanceof Function)
235 assertTrue(Set.prototype.has instanceof Function) 239 assertTrue(Set.prototype.has instanceof Function)
236 assertTrue(Set.prototype.delete instanceof Function) 240 assertTrue(Set.prototype.delete instanceof Function)
241 assertTrue(Set.prototype.clear instanceof Function)
237 242
238 243
239 // Test some common JavaScript idioms for Maps 244 // Test some common JavaScript idioms for Maps
240 var m = new Map; 245 var m = new Map;
241 assertTrue(m instanceof Map); 246 assertTrue(m instanceof Map);
242 assertTrue(Map.prototype.set instanceof Function) 247 assertTrue(Map.prototype.set instanceof Function)
243 assertTrue(Map.prototype.get instanceof Function) 248 assertTrue(Map.prototype.get instanceof Function)
244 assertTrue(Map.prototype.has instanceof Function) 249 assertTrue(Map.prototype.has instanceof Function)
245 assertTrue(Map.prototype.delete instanceof Function) 250 assertTrue(Map.prototype.delete instanceof Function)
251 assertTrue(Map.prototype.clear instanceof Function)
246 252
247 253
248 // Test some common JavaScript idioms for WeakMaps 254 // Test some common JavaScript idioms for WeakMaps
249 var m = new WeakMap; 255 var m = new WeakMap;
250 assertTrue(m instanceof WeakMap); 256 assertTrue(m instanceof WeakMap);
251 assertTrue(WeakMap.prototype.set instanceof Function) 257 assertTrue(WeakMap.prototype.set instanceof Function)
252 assertTrue(WeakMap.prototype.get instanceof Function) 258 assertTrue(WeakMap.prototype.get instanceof Function)
253 assertTrue(WeakMap.prototype.has instanceof Function) 259 assertTrue(WeakMap.prototype.has instanceof Function)
254 assertTrue(WeakMap.prototype.delete instanceof Function) 260 assertTrue(WeakMap.prototype.delete instanceof Function)
261 assertTrue(WeakMap.prototype.clear instanceof Function)
255 262
256 263
257 // Test class of the Set, Map and WeakMap instance and prototype. 264 // Test some common JavaScript idioms for WeakSets
265 var s = new WeakSet;
266 assertTrue(s instanceof WeakSet);
267 assertTrue(WeakSet.prototype.add instanceof Function)
268 assertTrue(WeakSet.prototype.has instanceof Function)
269 assertTrue(WeakSet.prototype.delete instanceof Function)
270 assertTrue(WeakSet.prototype.clear instanceof Function)
271
272
273 // Test class of instance and prototype.
258 assertEquals("Set", %_ClassOf(new Set)) 274 assertEquals("Set", %_ClassOf(new Set))
259 assertEquals("Object", %_ClassOf(Set.prototype)) 275 assertEquals("Object", %_ClassOf(Set.prototype))
260 assertEquals("Map", %_ClassOf(new Map)) 276 assertEquals("Map", %_ClassOf(new Map))
261 assertEquals("Object", %_ClassOf(Map.prototype)) 277 assertEquals("Object", %_ClassOf(Map.prototype))
262 assertEquals("WeakMap", %_ClassOf(new WeakMap)) 278 assertEquals("WeakMap", %_ClassOf(new WeakMap))
263 assertEquals("Object", %_ClassOf(WeakMap.prototype)) 279 assertEquals("Object", %_ClassOf(WeakMap.prototype))
280 assertEquals("WeakSet", %_ClassOf(new WeakSet))
281 assertEquals("Object", %_ClassOf(WeakMap.prototype))
264 282
265 283
266 // Test constructor property of the Set, Map and WeakMap prototype. 284 // Test name of constructor.
285 assertEquals("Set", Set.name);
286 assertEquals("Map", Map.name);
287 assertEquals("WeakMap", WeakMap.name);
288 assertEquals("WeakSet", WeakSet.name);
289
290
291 // Test prototype property of Set, Map, WeakMap and WeakSet.
292 function TestPrototype(C) {
293 assertTrue(C.prototype instanceof Object);
294 assertEquals({
295 value: {},
296 writable: true, // TODO(2793): This should be non-writable.
297 enumerable: false,
298 configurable: false
299 }, Object.getOwnPropertyDescriptor(C, "prototype"));
300 }
301 TestPrototype(Set);
302 TestPrototype(Map);
303 TestPrototype(WeakMap);
304 TestPrototype(WeakSet);
305
306
307 // Test constructor property of the Set, Map, WeakMap and WeakSet prototype.
267 function TestConstructor(C) { 308 function TestConstructor(C) {
268 assertFalse(C === Object.prototype.constructor); 309 assertFalse(C === Object.prototype.constructor);
269 assertSame(C, C.prototype.constructor); 310 assertSame(C, C.prototype.constructor);
270 assertSame(C, C().__proto__.constructor); 311 assertSame(C, C().__proto__.constructor);
271 assertSame(C, (new C).__proto__.constructor); 312 assertSame(C, (new C).__proto__.constructor);
272 } 313 }
273 TestConstructor(Set); 314 TestConstructor(Set);
274 TestConstructor(Map); 315 TestConstructor(Map);
275 TestConstructor(WeakMap); 316 TestConstructor(WeakMap);
317 TestConstructor(WeakSet);
318
319
320 // Test the Set, Map, WeakMap and WeakSet global properties themselves.
321 function TestDescriptor(global, C) {
322 assertEquals({
323 value: C,
324 writable: true,
325 enumerable: false,
326 configurable: true
327 }, Object.getOwnPropertyDescriptor(global, C.name));
328 }
329 TestDescriptor(this, Set);
330 TestDescriptor(this, Map);
331 TestDescriptor(this, WeakMap);
332 TestDescriptor(this, WeakSet);
276 333
277 334
278 // Regression test for WeakMap prototype. 335 // Regression test for WeakMap prototype.
279 assertTrue(WeakMap.prototype.constructor === WeakMap) 336 assertTrue(WeakMap.prototype.constructor === WeakMap)
280 assertTrue(Object.getPrototypeOf(WeakMap.prototype) === Object.prototype) 337 assertTrue(Object.getPrototypeOf(WeakMap.prototype) === Object.prototype)
281 338
282 339
283 // Regression test for issue 1617: The prototype of the WeakMap constructor 340 // Regression test for issue 1617: The prototype of the WeakMap constructor
284 // needs to be unique (i.e. different from the one of the Object constructor). 341 // needs to be unique (i.e. different from the one of the Object constructor).
285 assertFalse(WeakMap.prototype === Object.prototype); 342 assertFalse(WeakMap.prototype === Object.prototype);
(...skipping 11 matching lines...) Expand all
297 assertEquals(10, o.myValue); 354 assertEquals(10, o.myValue);
298 355
299 356
300 // Regression test for issue 1884: Invoking any of the methods for Harmony 357 // Regression test for issue 1884: Invoking any of the methods for Harmony
301 // maps, sets, or weak maps, with a wrong type of receiver should be throwing 358 // maps, sets, or weak maps, with a wrong type of receiver should be throwing
302 // a proper TypeError. 359 // a proper TypeError.
303 var alwaysBogus = [ undefined, null, true, "x", 23, {} ]; 360 var alwaysBogus = [ undefined, null, true, "x", 23, {} ];
304 var bogusReceiversTestSet = [ 361 var bogusReceiversTestSet = [
305 { proto: Set.prototype, 362 { proto: Set.prototype,
306 funcs: [ 'add', 'has', 'delete' ], 363 funcs: [ 'add', 'has', 'delete' ],
307 receivers: alwaysBogus.concat([ new Map, new WeakMap ]), 364 receivers: alwaysBogus.concat([ new Map, new WeakMap, new WeakSet ]),
308 }, 365 },
309 { proto: Map.prototype, 366 { proto: Map.prototype,
310 funcs: [ 'get', 'set', 'has', 'delete' ], 367 funcs: [ 'get', 'set', 'has', 'delete' ],
311 receivers: alwaysBogus.concat([ new Set, new WeakMap ]), 368 receivers: alwaysBogus.concat([ new Set, new WeakMap, new WeakSet ]),
312 }, 369 },
313 { proto: WeakMap.prototype, 370 { proto: WeakMap.prototype,
314 funcs: [ 'get', 'set', 'has', 'delete' ], 371 funcs: [ 'get', 'set', 'has', 'delete' ],
315 receivers: alwaysBogus.concat([ new Set, new Map ]), 372 receivers: alwaysBogus.concat([ new Set, new Map, new WeakSet ]),
373 },
374 { proto: WeakSet.prototype,
375 funcs: [ 'add', 'has', 'delete' ],
376 receivers: alwaysBogus.concat([ new Set, new Map, new WeakMap ]),
316 }, 377 },
317 ]; 378 ];
318 function TestBogusReceivers(testSet) { 379 function TestBogusReceivers(testSet) {
319 for (var i = 0; i < testSet.length; i++) { 380 for (var i = 0; i < testSet.length; i++) {
320 var proto = testSet[i].proto; 381 var proto = testSet[i].proto;
321 var funcs = testSet[i].funcs; 382 var funcs = testSet[i].funcs;
322 var receivers = testSet[i].receivers; 383 var receivers = testSet[i].receivers;
323 for (var j = 0; j < funcs.length; j++) { 384 for (var j = 0; j < funcs.length; j++) {
324 var func = proto[funcs[j]]; 385 var func = proto[funcs[j]];
325 for (var k = 0; k < receivers.length; k++) { 386 for (var k = 0; k < receivers.length; k++) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 (function() { 467 (function() {
407 var k = new Object(); 468 var k = new Object();
408 var w = new WeakMap(); 469 var w = new WeakMap();
409 w.set(k, 23); 470 w.set(k, 23);
410 assertTrue(w.has(k)); 471 assertTrue(w.has(k));
411 assertEquals(23, w.get(k)); 472 assertEquals(23, w.get(k));
412 w.clear(); 473 w.clear();
413 assertFalse(w.has(k)); 474 assertFalse(w.has(k));
414 assertEquals(undefined, w.get(k)); 475 assertEquals(undefined, w.get(k));
415 })(); 476 })();
477
478
479 // Test WeakSet clear
480 (function() {
481 var k = new Object();
482 var w = new WeakSet();
483 w.add(k);
484 assertTrue(w.has(k));
485 w.clear();
486 assertFalse(w.has(k));
487 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/block-let-crankshaft.js ('k') | test/mjsunit/harmony/numeric-literals.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698