Debian Codegraph @

js/src/jit-test/tests/collections/Map-surfaces-2.js

raw
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, ...args) {
6 assertEq(typeof fn, "function");
7 assertThrowsInstanceOf(function () { fn.apply(obj, args); }, TypeError);
8 }
9
10 var Map_size_getter = Object.getOwnPropertyDescriptor(Map.prototype, "size").get;
11
12 function test(obj) {
13 testcase(obj, Map.prototype.get, "x");
14 testcase(obj, Map.prototype.has, "x");
15 testcase(obj, Map.prototype.set, "x", 1);
16 testcase(obj, Map.prototype.delete, "x");
17 testcase(obj, Map.prototype.clear);
18 testcase(obj, Map.prototype.keys);
19 testcase(obj, Map.prototype.values);
20 testcase(obj, Map.prototype.entries);
21 testcase(obj, Map_size_getter);
22 }
23
24 test(Map.prototype);
25 test(Object.create(new Map));
26 test(new Set());
27 test({});
28 test(null);
29 test(undefined);