2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
6 //-----------------------------------------------------------------------------
7 var BUGNUMBER = 619283;
9 "ECMAScript built-in methods that immediately throw when |this| is " +
10 "|undefined| or |null| (due to CheckObjectCoercible, ToObject, or ToString)";
12 print(BUGNUMBER + ": " + summary);
18 // This test fills out for the non-standard methods which
19 // ecma_5/misc/builtin-methods-reject-null-undefined-this.js declines to test.
21 var ClassToMethodMap =
24 * Don't box this just yet for these methods -- they're used too
25 * much without qualification to do that. :-(
27 /* "__defineGetter__", "__defineSetter__", */
28 "__lookupGetter__", "__lookupSetter__", "watch", "unwatch",
30 Function: ["toSource"],
32 String: ["toSource", "quote", "bold", "italics", "fixed", "fontsize",
33 "fontcolor", "link", "anchor", "strike", "small", "big", "blink",
34 "sup", "sub", "substr", "trimLeft", "trimRight", "toJSON"],
35 Boolean: ["toSource", "toJSON"],
36 Number: ["toSource", "toJSON"],
37 Date: ["toSource", "toLocaleFormat", "getYear", "setYear",
43 var badThisValues = [null, undefined];
45 function testMethod(Class, className, method)
49 // Try out explicit this values
50 for (var i = 0, sz = badThisValues.length; i < sz; i++)
52 var badThis = badThisValues[i];
54 expr = className + ".prototype." + method + ".call(" + badThis + ")";
57 Class.prototype[method].call(badThis);
58 throw new Error(expr + " didn't throw a TypeError");
62 assertEq(e instanceof TypeError, true,
63 "wrong error for " + expr + ", instead threw " + e);
66 expr = className + ".prototype." + method + ".apply(" + badThis + ")";
69 Class.prototype[method].apply(badThis);
70 throw new Error(expr + " didn't throw a TypeError");
74 assertEq(e instanceof TypeError, true,
75 "wrong error for " + expr + ", instead threw " + e);
79 // ..and for good measure..
81 expr = "(0, " + className + ".prototype." + method + ")()"
84 // comma operator to call GetValue() on the method and de-Reference it
85 (0, Class.prototype[method])();
86 throw new Error(expr + " didn't throw a TypeError");
90 assertEq(e instanceof TypeError, true,
91 "wrong error for " + expr + ", instead threw " + e);
95 for (var className in ClassToMethodMap)
97 var Class = this[className];
99 var methodNames = ClassToMethodMap[className];
100 for (var i = 0, sz = methodNames.length; i < sz; i++)
102 var method = methodNames[i];
103 testMethod(Class, className, method);
107 /******************************************************************************/
109 if (typeof reportCompare === "function")
110 reportCompare(true, true);
112 print("All tests passed!");