Debian Codegraph @

rhino/testsrc/tests/ecma_3/Function/15.3.4.3-1.js

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