Debian Codegraph @

rhino/testsrc/tests/ecma_3/Function/15.3.4.4-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.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 gTestfile = '15.3.4.4-1.js';
17 var UBound = 0;
18 var BUGNUMBER = 145791;
19 var summary = 'Testing ECMA conformance of Function.prototype.call';
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.call.length should return 1
47 */
48 status = inSection(1);
49 actual = Function.prototype.call.length;
50 expect = 1;
51 addThis();
52
53
54 /*
55 * When |thisArg| is not provided to the call() method, the
56 * called function must be passed the global object as |this|
57 */
58 status = inSection(2);
59 actual = F0.call();
60 expect = "" + this + 0;
61 addThis();
62
63
64 /*
65 * If [,arg1 [,arg2, ...]] are not provided to the call() method,
66 * the called function should be invoked with an empty argument list
67 */
68 status = inSection(3);
69 actual = F0.call("");
70 expect = "" + "" + 0;
71 addThis();
72
73 status = inSection(4);
74 actual = F0.call(true);
75 expect = "" + true + 0;
76 addThis();
77
78
79 /*
80 * Function.prototype.call(x) and
81 * Function.prototype.call(x, undefined) should return the same result
82 */
83 status = inSection(5);
84 actual = F1.call(0, undefined);
85 expect = F1.call(0);
86 addThis();
87
88 status = inSection(6);
89 actual = F1.call("", undefined);
90 expect = F1.call("");
91 addThis();
92
93 status = inSection(7);
94 actual = F1.call(null, undefined);
95 expect = F1.call(null);
96 addThis();
97
98 status = inSection(8);
99 actual = F1.call(undefined, undefined);
100 expect = F1.call(undefined);
101 addThis();
102
103
104 /*
105 * Function.prototype.call() and
106 * Function.prototype.call(undefined) should return the same result
107 */
108 status = inSection(9);
109 actual = F2.call(undefined);
110 expect = F2.call();
111 addThis();
112
113
114 /*
115 * Function.prototype.call() and
116 * Function.prototype.call(null) should return the same result
117 */
118 status = inSection(10);
119 actual = F2.call(null);
120 expect = F2.call();
121 addThis();
122
123
124
125 //-----------------------------------------------------------------------------
126 test();
127 //-----------------------------------------------------------------------------
128
129
130
131 function addThis()
132 {
133 statusitems[UBound] = status;
134 actualvalues[UBound] = actual;
135 expectedvalues[UBound] = expect;
136 UBound++;
137 }
138
139
140 function test()
141 {
142 enterFunc('test');
143 printBugNumber(BUGNUMBER);
144 printStatus(summary);
145
146 for (var i=0; i<UBound; i++)
147 {
148 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
149 }
150
151 exitFunc ('test');
152 }