|
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/. */ |
|
5 |
|
6 /* |
|
7 * |
|
8 * Date: 21 May 2002 |
|
9 * SUMMARY: ECMA conformance of Function.prototype.apply |
|
10 * |
|
11 * Function.prototype.apply(thisArg, argArray) |
|
12 * |
|
13 * See ECMA-262 Edition 3 Final, Section 15.3.4.3 |
|
14 */ |
|
15 //----------------------------------------------------------------------------- |
|
16 var UBound = 0; |
|
17 var BUGNUMBER = 145791; |
|
18 var summary = 'Testing ECMA conformance of Function.prototype.apply'; |
|
19 var status = ''; |
|
20 var statusitems = []; |
|
21 var actual = ''; |
|
22 var actualvalues = []; |
|
23 var expect= ''; |
|
24 var expectedvalues = []; |
|
25 |
|
26 |
|
27 function F0(a) |
|
28 { |
|
29 return "" + this + arguments.length; |
|
30 } |
|
31 |
|
32 function F1(a) |
|
33 { |
|
34 return "" + this + a; |
|
35 } |
|
36 |
|
37 function F2() |
|
38 { |
|
39 return "" + this; |
|
40 } |
|
41 |
|
42 |
|
43 |
|
44 /* |
|
45 * Function.prototype.apply.length should return 2 |
|
46 */ |
|
47 status = inSection(1); |
|
48 actual = Function.prototype.apply.length; |
|
49 expect = 2; |
|
50 addThis(); |
|
51 |
|
52 |
|
53 /* |
|
54 * When |thisArg| is not provided to the apply() method, the |
|
55 * called function must be passed the global object as |this| |
|
56 */ |
|
57 status = inSection(2); |
|
58 actual = F0.apply(); |
|
59 expect = "" + this + 0; |
|
60 addThis(); |
|
61 |
|
62 |
|
63 /* |
|
64 * If |argArray| is not provided to the apply() method, the |
|
65 * called function should be invoked with an empty argument list |
|
66 */ |
|
67 status = inSection(3); |
|
68 actual = F0.apply(""); |
|
69 expect = "" + "" + 0; |
|
70 addThis(); |
|
71 |
|
72 status = inSection(4); |
|
73 actual = F0.apply(true); |
|
74 expect = "" + true + 0; |
|
75 addThis(); |
|
76 |
|
77 |
|
78 /* |
|
79 * Function.prototype.apply(x) and |
|
80 * Function.prototype.apply(x, undefined) should return the same result |
|
81 */ |
|
82 status = inSection(5); |
|
83 actual = F1.apply(0, undefined); |
|
84 expect = F1.apply(0); |
|
85 addThis(); |
|
86 |
|
87 status = inSection(6); |
|
88 actual = F1.apply("", undefined); |
|
89 expect = F1.apply(""); |
|
90 addThis(); |
|
91 |
|
92 status = inSection(7); |
|
93 actual = F1.apply(null, undefined); |
|
94 expect = F1.apply(null); |
|
95 addThis(); |
|
96 |
|
97 status = inSection(8); |
|
98 actual = F1.apply(undefined, undefined); |
|
99 expect = F1.apply(undefined); |
|
100 addThis(); |
|
101 |
|
102 |
|
103 /* |
|
104 * Function.prototype.apply(x) and |
|
105 * Function.prototype.apply(x, null) should return the same result |
|
106 */ |
|
107 status = inSection(9); |
|
108 actual = F1.apply(0, null); |
|
109 expect = F1.apply(0); |
|
110 addThis(); |
|
111 |
|
112 status = inSection(10); |
|
113 actual = F1.apply("", null); |
|
114 expect = F1.apply(""); |
|
115 addThis(); |
|
116 |
|
117 status = inSection(11); |
|
118 actual = F1.apply(null, null); |
|
119 expect = F1.apply(null); |
|
120 addThis(); |
|
121 |
|
122 status = inSection(12); |
|
123 actual = F1.apply(undefined, null); |
|
124 expect = F1.apply(undefined); |
|
125 addThis(); |
|
126 |
|
127 |
|
128 /* |
|
129 * Function.prototype.apply() and |
|
130 * Function.prototype.apply(undefined) should return the same result |
|
131 */ |
|
132 status = inSection(13); |
|
133 actual = F2.apply(undefined); |
|
134 expect = F2.apply(); |
|
135 addThis(); |
|
136 |
|
137 |
|
138 /* |
|
139 * Function.prototype.apply() and |
|
140 * Function.prototype.apply(null) should return the same result |
|
141 */ |
|
142 status = inSection(14); |
|
143 actual = F2.apply(null); |
|
144 expect = F2.apply(); |
|
145 addThis(); |
|
146 |
|
147 |
|
148 |
|
149 //----------------------------------------------------------------------------- |
|
150 test(); |
|
151 //----------------------------------------------------------------------------- |
|
152 |
|
153 |
|
154 |
|
155 function addThis() |
|
156 { |
|
157 statusitems[UBound] = status; |
|
158 actualvalues[UBound] = actual; |
|
159 expectedvalues[UBound] = expect; |
|
160 UBound++; |
|
161 } |
|
162 |
|
163 |
|
164 function test() |
|
165 { |
|
166 enterFunc('test'); |
|
167 printBugNumber(BUGNUMBER); |
|
168 printStatus(summary); |
|
169 |
|
170 for (var i=0; i<UBound; i++) |
|
171 { |
|
172 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
173 } |
|
174 |
|
175 exitFunc ('test'); |
|
176 } |