2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
5 * Jeff Walden <jwalden+code@mit.edu>
8 //-----------------------------------------------------------------------------
9 var BUGNUMBER = 575535;
10 var summary = 'Function.prototype.call';
11 print(BUGNUMBER + ": " + summary);
17 function expectTypeError(fun, msg)
22 assertEq(true, false, "should have thrown a TypeError");
26 assertEq(e instanceof TypeError, true, msg + "; instead threw " + e);
34 assertEq(Function.prototype.call.length, 1);
38 var nonfuns = [null, 1, -1, 2.5, "[[Call]]", undefined, true, false, {}];
39 for (var i = 0, sz = nonfuns.length; i < sz; i++)
43 Function.prototype.call.apply(nonfuns[i]);
46 "expected TypeError calling Function.prototype.call with uncallable this";
47 expectTypeError(f, msg);
54 assertEq(this, global, "bad this");
55 assertEq(arguments.length, 0, "wrong arguments");
66 assertEq(this, seenThis, "bad this");
67 assertEq(arguments.length, 0, "wrong arguments");
72 strictNone.call(undefined);
75 strictNone.call(null);
80 var seenThisBox, args;
83 assertEq(this instanceof seenThisBox, true,
84 "this not instanceof " + seenThisBox);
85 assertEq(this.valueOf(), seenThis,
86 "wrong this valueOf()");
87 assertEq(arguments.length, args.length, "wrong arguments count");
88 for (var i = 0; i < args.length; i++)
89 assertEq(arguments[i], args[i], "wrong argument " + i);
93 seenThisBox = Boolean;
94 args = [8, 6, 7, NaN, undefined, 0.3];
95 some.call(false, 8, 6, 7, NaN, undefined, 0.3);
100 seenThisBox = String;
102 some.call("foo", obj);
105 seenThisBox = Object;
108 function strictSome()
111 assertEq(this, seenThis, "wrong this");
112 assertEq(arguments.length, args.length, "wrong arguments count");
113 for (var i = 0; i < args.length; i++)
114 assertEq(arguments[i], args[i], "wrong argument " + i);
118 args = [8, 6, 7, NaN, undefined, 0.3];
119 strictSome.call(NaN, 8, 6, 7, NaN, undefined, 0.3);
123 strictSome.call("foo", obj);
126 strictSome.call(obj, obj);
129 /******************************************************************************/
131 if (typeof reportCompare === "function")
132 reportCompare(true, true);
134 print("All tests passed!");