1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
23 * zack-weg@gmx.de, PhilSchwartau@aol.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 * Date: 08 November 2003
42 * SUMMARY: |expr()| should cause a TypeError if |typeof expr| != 'function'
44 * See http://bugzilla.mozilla.org/show_bug.cgi?id=224956
47 //-----------------------------------------------------------------------------
49 var BUGNUMBER = 224956;
50 var summary = "|expr()| should cause TypeError if |typeof expr| != 'function'";
51 var TEST_PASSED = 'TypeError';
52 var TEST_FAILED = 'Generated an error, but NOT a TypeError! ';
53 var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
54 var CHECK_PASSED = 'Should not generate an error';
55 var CHECK_FAILED = 'Generated an error!';
59 var actualvalues = [];
61 var expectedvalues = [];
66 * All the following contain invalid uses of the call operator ()
67 * and should generate TypeErrors. That's what we're testing for.
69 * To save writing try...catch over and over, we hide all the
70 * errors inside eval strings, and let testThis() catch them.
72 status = inSection(1);
76 status = inSection(2);
79 status = inSection(3);
83 status = inSection(4);
84 testThis('Date(12345)()');
86 status = inSection(5);
90 status = inSection(6);
93 status = inSection(7);
97 status = inSection(8);
98 testThis('void(0)()');
100 status = inSection(9);
104 status = inSection(10);
107 status = inSection(11);
111 status = inSection(12);
112 testThis('[1,2,3,4,5]()');
114 status = inSection(13);
115 x = [1,2,3].splice(1,2);
120 * Same as above, but with non-empty call parentheses
122 status = inSection(14);
126 status = inSection(15);
127 testThis('"abc"(1)');
129 status = inSection(16);
133 status = inSection(17);
134 testThis('Date(12345)(1)');
136 status = inSection(18);
140 status = inSection(19);
143 status = inSection(20);
147 status = inSection(21);
148 testThis('void(0)(1)');
150 status = inSection(22);
154 status = inSection(23);
157 status = inSection(24);
161 status = inSection(25);
162 testThis('[1,2,3,4,5](1)');
164 status = inSection(26);
165 x = [1,2,3].splice(1,2);
170 * Expression from website in original bug report above -
172 status = inSection(27);
173 var A = 1, C=2, Y=3, T=4, I=5;
174 testThis('(((C/A-0.3)/0.2)+((Y/A-3)/4)+((T/A)/0.05)+((0.095-I/A)/0.4))(100/6)');
179 * Functions and RegExps both have |typeof| == 'function'.
180 * See http://bugzilla.mozilla.org/show_bug.cgi?id=61911.
182 * Therefore these expressions should not cause any errors.
183 * Note we use checkThis() instead of testThis()
186 status = inSection(28);
187 x = function (y) {return y+1;};
188 checkThis('x("abc")');
190 status = inSection(29);
191 checkThis('(function (y) {return y+1;})("abc")');
193 status = inSection(30);
194 function f(y) { function g() {return y;}; return g();};
195 checkThis('f("abc")');
197 status = inSection(31);
199 checkThis('x("abc")');
201 status = inSection(32);
203 checkThis('x("abc")');
205 status = inSection(33);
207 checkThis('x("abc")');
209 status = inSection(34);
210 x = new RegExp('a()', 'gi');
216 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
224 * |expr()| should generate a TypeError if |expr| is not a function
226 function testThis(sInvalidSyntax)
228 expect = TEST_PASSED;
229 actual = TEST_FAILED_BADLY;
233 eval(sInvalidSyntax);
237 if (e instanceof TypeError)
238 actual = TEST_PASSED;
240 actual = TEST_FAILED + e;
243 statusitems[UBound] = status;
244 expectedvalues[UBound] = expect;
245 actualvalues[UBound] = actual;
251 * Valid syntax shouldn't generate any errors
253 function checkThis(sValidSyntax)
255 expect = CHECK_PASSED;
256 actual = CHECK_PASSED;
264 actual = CHECK_FAILED;
267 statusitems[UBound] = status;
268 expectedvalues[UBound] = expect;
269 actualvalues[UBound] = actual;
277 printBugNumber(BUGNUMBER);
278 printStatus(summary);
280 for (var i=0; i<UBound; i++)
282 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);