| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 assertTrue(Map.prototype.clear instanceof Function) | 259 assertTrue(Map.prototype.clear instanceof Function) |
| 260 | 260 |
| 261 | 261 |
| 262 // Test some common JavaScript idioms for WeakMaps | 262 // Test some common JavaScript idioms for WeakMaps |
| 263 var m = new WeakMap; | 263 var m = new WeakMap; |
| 264 assertTrue(m instanceof WeakMap); | 264 assertTrue(m instanceof WeakMap); |
| 265 assertTrue(WeakMap.prototype.set instanceof Function) | 265 assertTrue(WeakMap.prototype.set instanceof Function) |
| 266 assertTrue(WeakMap.prototype.get instanceof Function) | 266 assertTrue(WeakMap.prototype.get instanceof Function) |
| 267 assertTrue(WeakMap.prototype.has instanceof Function) | 267 assertTrue(WeakMap.prototype.has instanceof Function) |
| 268 assertTrue(WeakMap.prototype.delete instanceof Function) | 268 assertTrue(WeakMap.prototype.delete instanceof Function) |
| 269 assertTrue(WeakMap.prototype.clear instanceof Function) | |
| 270 | 269 |
| 271 | 270 |
| 272 // Test some common JavaScript idioms for WeakSets | 271 // Test some common JavaScript idioms for WeakSets |
| 273 var s = new WeakSet; | 272 var s = new WeakSet; |
| 274 assertTrue(s instanceof WeakSet); | 273 assertTrue(s instanceof WeakSet); |
| 275 assertTrue(WeakSet.prototype.add instanceof Function) | 274 assertTrue(WeakSet.prototype.add instanceof Function) |
| 276 assertTrue(WeakSet.prototype.has instanceof Function) | 275 assertTrue(WeakSet.prototype.has instanceof Function) |
| 277 assertTrue(WeakSet.prototype.delete instanceof Function) | 276 assertTrue(WeakSet.prototype.delete instanceof Function) |
| 278 assertTrue(WeakSet.prototype.clear instanceof Function) | |
| 279 | 277 |
| 280 | 278 |
| 281 // Test class of instance and prototype. | 279 // Test class of instance and prototype. |
| 282 assertEquals("Set", %_ClassOf(new Set)) | 280 assertEquals("Set", %_ClassOf(new Set)) |
| 283 assertEquals("Object", %_ClassOf(Set.prototype)) | 281 assertEquals("Object", %_ClassOf(Set.prototype)) |
| 284 assertEquals("Map", %_ClassOf(new Map)) | 282 assertEquals("Map", %_ClassOf(new Map)) |
| 285 assertEquals("Object", %_ClassOf(Map.prototype)) | 283 assertEquals("Object", %_ClassOf(Map.prototype)) |
| 286 assertEquals("WeakMap", %_ClassOf(new WeakMap)) | 284 assertEquals("WeakMap", %_ClassOf(new WeakMap)) |
| 287 assertEquals("Object", %_ClassOf(WeakMap.prototype)) | 285 assertEquals("Object", %_ClassOf(WeakMap.prototype)) |
| 288 assertEquals("WeakSet", %_ClassOf(new WeakSet)) | 286 assertEquals("WeakSet", %_ClassOf(new WeakSet)) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 var m = new Map(); | 462 var m = new Map(); |
| 465 m.set(42, true); | 463 m.set(42, true); |
| 466 assertTrue(m.has(42)); | 464 assertTrue(m.has(42)); |
| 467 assertEquals(1, m.size); | 465 assertEquals(1, m.size); |
| 468 m.clear(); | 466 m.clear(); |
| 469 assertFalse(m.has(42)); | 467 assertFalse(m.has(42)); |
| 470 assertEquals(0, m.size); | 468 assertEquals(0, m.size); |
| 471 })(); | 469 })(); |
| 472 | 470 |
| 473 | 471 |
| 474 // Test WeakMap clear | |
| 475 (function() { | |
| 476 var k = new Object(); | |
| 477 var w = new WeakMap(); | |
| 478 w.set(k, 23); | |
| 479 assertTrue(w.has(k)); | |
| 480 assertEquals(23, w.get(k)); | |
| 481 w.clear(); | |
| 482 assertFalse(w.has(k)); | |
| 483 assertEquals(undefined, w.get(k)); | |
| 484 })(); | |
| 485 | |
| 486 | |
| 487 // Test WeakSet clear | |
| 488 (function() { | |
| 489 var k = new Object(); | |
| 490 var w = new WeakSet(); | |
| 491 w.add(k); | |
| 492 assertTrue(w.has(k)); | |
| 493 w.clear(); | |
| 494 assertFalse(w.has(k)); | |
| 495 })(); | |
| 496 | |
| 497 | |
| 498 (function TestMinusZeroSet() { | 472 (function TestMinusZeroSet() { |
| 499 var s = new Set(); | 473 var s = new Set(); |
| 500 s.add(-0); | 474 s.add(-0); |
| 501 assertSame(0, s.values().next().value); | 475 assertSame(0, s.values().next().value); |
| 502 s.add(0); | 476 s.add(0); |
| 503 assertEquals(1, s.size); | 477 assertEquals(1, s.size); |
| 504 assertTrue(s.has(0)); | 478 assertTrue(s.has(0)); |
| 505 assertTrue(s.has(-0)); | 479 assertTrue(s.has(-0)); |
| 506 })(); | 480 })(); |
| 507 | 481 |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 TestMapConstructorIterableValue(WeakMap); | 1399 TestMapConstructorIterableValue(WeakMap); |
| 1426 | 1400 |
| 1427 function TestCollectionToString(C) { | 1401 function TestCollectionToString(C) { |
| 1428 assertEquals("[object " + C.name + "]", | 1402 assertEquals("[object " + C.name + "]", |
| 1429 Object.prototype.toString.call(new C())); | 1403 Object.prototype.toString.call(new C())); |
| 1430 } | 1404 } |
| 1431 TestCollectionToString(Map); | 1405 TestCollectionToString(Map); |
| 1432 TestCollectionToString(Set); | 1406 TestCollectionToString(Set); |
| 1433 TestCollectionToString(WeakMap); | 1407 TestCollectionToString(WeakMap); |
| 1434 TestCollectionToString(WeakSet); | 1408 TestCollectionToString(WeakSet); |
| OLD | NEW |