Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
4 * Contributor:
5 * Jeff Walden <jwalden+code@mit.edu>
6 */
8 //-----------------------------------------------------------------------------
9 var BUGNUMBER = 575535;
10 var summary = 'Function.prototype.call';
11 print(BUGNUMBER + ": " + summary);
13 /**************
14 * BEGIN TEST *
15 **************/
17 function expectTypeError(fun, msg)
18 {
19 try
20 {
21 fun();
22 assertEq(true, false, "should have thrown a TypeError");
23 }
24 catch (e)
25 {
26 assertEq(e instanceof TypeError, true, msg + "; instead threw " + e);
27 }
28 }
30 function fun() { }
32 var global = this;
34 assertEq(Function.prototype.call.length, 1);
37 /* Step 1. */
38 var nonfuns = [null, 1, -1, 2.5, "[[Call]]", undefined, true, false, {}];
39 for (var i = 0, sz = nonfuns.length; i < sz; i++)
40 {
41 var f = function()
42 {
43 Function.prototype.call.apply(nonfuns[i]);
44 };
45 var msg =
46 "expected TypeError calling Function.prototype.call with uncallable this";
47 expectTypeError(f, msg);
48 }
51 /* Steps 2-4. */
52 function none()
53 {
54 assertEq(this, global, "bad this");
55 assertEq(arguments.length, 0, "wrong arguments");
56 }
58 none.call();
59 none.call(undefined);
60 none.call(null);
62 var seenThis;
63 function strictNone()
64 {
65 "use strict";
66 assertEq(this, seenThis, "bad this");
67 assertEq(arguments.length, 0, "wrong arguments");
68 }
70 seenThis = undefined;
71 strictNone.call();
72 strictNone.call(undefined);
74 seenThis = null;
75 strictNone.call(null);
77 seenThis = 17;
78 strictNone.call(17);
80 var seenThisBox, args;
81 function some()
82 {
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);
90 }
92 seenThis = false;
93 seenThisBox = Boolean;
94 args = [8, 6, 7, NaN, undefined, 0.3];
95 some.call(false, 8, 6, 7, NaN, undefined, 0.3);
97 var obj = {};
99 seenThis = "foo";
100 seenThisBox = String;
101 args = [obj];
102 some.call("foo", obj);
104 seenThis = obj;
105 seenThisBox = Object;
106 some.call(obj, obj);
108 function strictSome()
109 {
110 "use strict";
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);
115 }
117 seenThis = NaN;
118 args = [8, 6, 7, NaN, undefined, 0.3];
119 strictSome.call(NaN, 8, 6, 7, NaN, undefined, 0.3);
121 seenThis = "foo";
122 args = [obj];
123 strictSome.call("foo", obj);
125 seenThis = obj;
126 strictSome.call(obj, obj);
129 /******************************************************************************/
131 if (typeof reportCompare === "function")
132 reportCompare(true, true);
134 print("All tests passed!");