|
1 // Map methods throw when passed a this-value that isn't a Map. |
|
2 |
|
3 load(libdir + "asserts.js"); |
|
4 |
|
5 function testcase(obj, fn) { |
|
6 assertEq(typeof fn, "function"); |
|
7 var args = Array.slice(arguments, 2); |
|
8 assertThrowsInstanceOf(function () { fn.apply(obj, args); }, TypeError); |
|
9 } |
|
10 |
|
11 var Map_size_getter = Object.getOwnPropertyDescriptor(Map.prototype, "size").get; |
|
12 |
|
13 function test(obj) { |
|
14 testcase(obj, Map.prototype.get, "x"); |
|
15 testcase(obj, Map.prototype.has, "x"); |
|
16 testcase(obj, Map.prototype.set, "x", 1); |
|
17 testcase(obj, Map.prototype.delete, "x"); |
|
18 testcase(obj, Map.prototype.clear); |
|
19 testcase(obj, Map.prototype.keys); |
|
20 testcase(obj, Map.prototype.values); |
|
21 testcase(obj, Map.prototype.entries); |
|
22 testcase(obj, Map_size_getter); |
|
23 } |
|
24 |
|
25 test(Map.prototype); |
|
26 test(Object.create(new Map)); |
|
27 test(new Set()); |
|
28 test({}); |
|
29 test(null); |
|
30 test(undefined); |