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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 *
8 * Date: 21 May 2002
9 * SUMMARY: ECMA conformance of Function.prototype.call
10 *
11 * Function.prototype.call(thisArg [,arg1 [,arg2, ...]])
12 *
13 * See ECMA-262 Edition 3 Final, Section 15.3.4.4
14 */
15 //-----------------------------------------------------------------------------
16 var UBound = 0;
17 var BUGNUMBER = 145791;
18 var summary = 'Testing ECMA conformance of Function.prototype.call';
19 var status = '';
20 var statusitems = [];
21 var actual = '';
22 var actualvalues = [];
23 var expect= '';
24 var expectedvalues = [];
27 function F0(a)
28 {
29 return "" + this + arguments.length;
30 }
32 function F1(a)
33 {
34 return "" + this + a;
35 }
37 function F2()
38 {
39 return "" + this;
40 }
44 /*
45 * Function.prototype.call.length should return 1
46 */
47 status = inSection(1);
48 actual = Function.prototype.call.length;
49 expect = 1;
50 addThis();
53 /*
54 * When |thisArg| is not provided to the call() method, the
55 * called function must be passed the global object as |this|
56 */
57 status = inSection(2);
58 actual = F0.call();
59 expect = "" + this + 0;
60 addThis();
63 /*
64 * If [,arg1 [,arg2, ...]] are not provided to the call() method,
65 * the called function should be invoked with an empty argument list
66 */
67 status = inSection(3);
68 actual = F0.call("");
69 expect = "" + "" + 0;
70 addThis();
72 status = inSection(4);
73 actual = F0.call(true);
74 expect = "" + true + 0;
75 addThis();
78 /*
79 * Function.prototype.call(x) and
80 * Function.prototype.call(x, undefined) should return the same result
81 */
82 status = inSection(5);
83 actual = F1.call(0, undefined);
84 expect = F1.call(0);
85 addThis();
87 status = inSection(6);
88 actual = F1.call("", undefined);
89 expect = F1.call("");
90 addThis();
92 status = inSection(7);
93 actual = F1.call(null, undefined);
94 expect = F1.call(null);
95 addThis();
97 status = inSection(8);
98 actual = F1.call(undefined, undefined);
99 expect = F1.call(undefined);
100 addThis();
103 /*
104 * Function.prototype.call() and
105 * Function.prototype.call(undefined) should return the same result
106 */
107 status = inSection(9);
108 actual = F2.call(undefined);
109 expect = F2.call();
110 addThis();
113 /*
114 * Function.prototype.call() and
115 * Function.prototype.call(null) should return the same result
116 */
117 status = inSection(10);
118 actual = F2.call(null);
119 expect = F2.call();
120 addThis();
122 if (typeof newGlobal === "function")
123 {
124 /*
125 * Function.prototype.call gets lexical globals, not caller globals
126 */
127 status = inSection(11);
128 actual = g2 = newGlobal();
129 g2.eval("boundMethod = Function('return this');");
130 expect = g2.boundMethod.call();
131 addThis();
132 }
135 //-----------------------------------------------------------------------------
136 test();
137 //-----------------------------------------------------------------------------
141 function addThis()
142 {
143 statusitems[UBound] = status;
144 actualvalues[UBound] = actual;
145 expectedvalues[UBound] = expect;
146 UBound++;
147 }
150 function test()
151 {
152 enterFunc('test');
153 printBugNumber(BUGNUMBER);
154 printStatus(summary);
156 for (var i=0; i<UBound; i++)
157 {
158 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
159 }
161 exitFunc ('test');
162 }