1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/collections/Map-surfaces-2.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,30 @@ 1.4 +// Map methods throw when passed a this-value that isn't a Map. 1.5 + 1.6 +load(libdir + "asserts.js"); 1.7 + 1.8 +function testcase(obj, fn) { 1.9 + assertEq(typeof fn, "function"); 1.10 + var args = Array.slice(arguments, 2); 1.11 + assertThrowsInstanceOf(function () { fn.apply(obj, args); }, TypeError); 1.12 +} 1.13 + 1.14 +var Map_size_getter = Object.getOwnPropertyDescriptor(Map.prototype, "size").get; 1.15 + 1.16 +function test(obj) { 1.17 + testcase(obj, Map.prototype.get, "x"); 1.18 + testcase(obj, Map.prototype.has, "x"); 1.19 + testcase(obj, Map.prototype.set, "x", 1); 1.20 + testcase(obj, Map.prototype.delete, "x"); 1.21 + testcase(obj, Map.prototype.clear); 1.22 + testcase(obj, Map.prototype.keys); 1.23 + testcase(obj, Map.prototype.values); 1.24 + testcase(obj, Map.prototype.entries); 1.25 + testcase(obj, Map_size_getter); 1.26 +} 1.27 + 1.28 +test(Map.prototype); 1.29 +test(Object.create(new Map)); 1.30 +test(new Set()); 1.31 +test({}); 1.32 +test(null); 1.33 +test(undefined);