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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 TestValidSetCalls(new Set); | 44 TestValidSetCalls(new Set); |
45 TestValidSetCalls(new WeakSet); | 45 TestValidSetCalls(new WeakSet); |
46 | 46 |
47 | 47 |
48 // Test valid getter and setter calls on Maps and WeakMaps | 48 // Test valid getter and setter calls on Maps and WeakMaps |
49 function TestValidMapCalls(m) { | 49 function TestValidMapCalls(m) { |
50 assertDoesNotThrow(function () { m.get(new Object) }); | 50 assertDoesNotThrow(function () { m.get(new Object) }); |
51 assertDoesNotThrow(function () { m.set(new Object) }); | 51 assertDoesNotThrow(function () { m.set(new Object) }); |
52 assertDoesNotThrow(function () { m.has(new Object) }); | 52 assertDoesNotThrow(function () { m.has(new Object) }); |
53 assertDoesNotThrow(function () { m.delete(new Object) }); | 53 assertDoesNotThrow(function () { m.delete(new Object) }); |
54 assertDoesNotThrow(function () { m.get(undefined) }); | |
Dmitry Lomov (no reviews)
2015/03/18 10:55:44
Validate the return value here and below
rossberg
2015/03/18 11:59:24
The actual behaviour ought to be tested further be
| |
55 assertDoesNotThrow(function () { m.get(null) }); | |
56 assertDoesNotThrow(function () { m.get(0) }); | |
57 assertDoesNotThrow(function () { m.get('a-key') }); | |
58 assertDoesNotThrow(function () { m.get(Symbol()) }); | |
59 assertDoesNotThrow(function () { m.has(undefined) }); | |
60 assertDoesNotThrow(function () { m.has(null) }); | |
61 assertDoesNotThrow(function () { m.has(0) }); | |
62 assertDoesNotThrow(function () { m.has('a-key') }); | |
63 assertDoesNotThrow(function () { m.has(Symbol()) }); | |
64 assertDoesNotThrow(function () { m.delete(undefined) }); | |
65 assertDoesNotThrow(function () { m.delete(null) }); | |
66 assertDoesNotThrow(function () { m.delete(0) }); | |
67 assertDoesNotThrow(function () { m.delete('a-key') }); | |
68 assertDoesNotThrow(function () { m.delete(Symbol()) }); | |
54 } | 69 } |
55 TestValidMapCalls(new Map); | 70 TestValidMapCalls(new Map); |
56 TestValidMapCalls(new WeakMap); | 71 TestValidMapCalls(new WeakMap); |
57 | 72 |
58 | 73 |
59 // Test invalid getter and setter calls for WeakMap only | 74 // Test invalid getter and setter calls for WeakMap only |
60 function TestInvalidCalls(m) { | 75 function TestInvalidCalls(m) { |
61 assertThrows(function () { m.get(undefined) }, TypeError); | |
62 assertThrows(function () { m.set(undefined, 0) }, TypeError); | 76 assertThrows(function () { m.set(undefined, 0) }, TypeError); |
63 assertThrows(function () { m.get(null) }, TypeError); | |
64 assertThrows(function () { m.set(null, 0) }, TypeError); | 77 assertThrows(function () { m.set(null, 0) }, TypeError); |
65 assertThrows(function () { m.get(0) }, TypeError); | |
66 assertThrows(function () { m.set(0, 0) }, TypeError); | 78 assertThrows(function () { m.set(0, 0) }, TypeError); |
67 assertThrows(function () { m.get('a-key') }, TypeError); | |
68 assertThrows(function () { m.set('a-key', 0) }, TypeError); | 79 assertThrows(function () { m.set('a-key', 0) }, TypeError); |
80 assertThrows(function () { m.set(Symbol(), 0) }, TypeError); | |
69 } | 81 } |
70 TestInvalidCalls(new WeakMap); | 82 TestInvalidCalls(new WeakMap); |
71 | 83 |
72 | 84 |
73 // Test expected behavior for Sets and WeakSets | 85 // Test expected behavior for Sets and WeakSets |
74 function TestSet(set, key) { | 86 function TestSet(set, key) { |
75 assertFalse(set.has(key)); | 87 assertFalse(set.has(key)); |
76 assertSame(set, set.add(key)); | 88 assertSame(set, set.add(key)); |
77 assertTrue(set.has(key)); | 89 assertTrue(set.has(key)); |
78 assertTrue(set.delete(key)); | 90 assertTrue(set.delete(key)); |
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1436 assertEquals(adderName + 'iterator', log); | 1448 assertEquals(adderName + 'iterator', log); |
1437 | 1449 |
1438 Object.defineProperty(ctor.prototype, adderName, { | 1450 Object.defineProperty(ctor.prototype, adderName, { |
1439 value: adderFunction | 1451 value: adderFunction |
1440 }); | 1452 }); |
1441 } | 1453 } |
1442 TestConstructorOrderOfAdderIterator(Map, 'set'); | 1454 TestConstructorOrderOfAdderIterator(Map, 'set'); |
1443 TestConstructorOrderOfAdderIterator(Set, 'add'); | 1455 TestConstructorOrderOfAdderIterator(Set, 'add'); |
1444 TestConstructorOrderOfAdderIterator(WeakMap, 'set'); | 1456 TestConstructorOrderOfAdderIterator(WeakMap, 'set'); |
1445 TestConstructorOrderOfAdderIterator(WeakSet, 'add'); | 1457 TestConstructorOrderOfAdderIterator(WeakSet, 'add'); |
OLD | NEW |