]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/js1_5/Regress/regress-118849.js
JavaScriptCore-521.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_5 / Regress / regress-118849.js
CommitLineData
b37bf2e1
A
1/* ***** BEGIN LICENSE BLOCK *****
2* Version: NPL 1.1/GPL 2.0/LGPL 2.1
3*
4* The contents of this file are subject to the Netscape Public License
5* Version 1.1 (the "License"); you may not use this file except in
6* compliance with the License. You may obtain a copy of the License at
7* http://www.mozilla.org/NPL/
8*
9* Software distributed under the License is distributed on an "AS IS" basis,
10* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11* for the specific language governing rights and limitations under the
12* License.
13*
14* The Original Code is JavaScript Engine testing utilities.
15*
16* The Initial Developer of the Original Code is Netscape Communications Corp.
17* Portions created by the Initial Developer are Copyright (C) 2001
18* the Initial Developer. All Rights Reserved.
19*
20* Contributor(s): pschwartau@netscape.com
21*
22* Alternatively, the contents of this file may be used under the terms of
23* either the GNU General Public License Version 2 or later (the "GPL"), or
24* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25* in which case the provisions of the GPL or the LGPL are applicable instead
26* of those above. If you wish to allow use of your version of this file only
27* under the terms of either the GPL or the LGPL, and not to allow others to
28* use your version of this file under the terms of the NPL, indicate your
29* decision by deleting the provisions above and replace them with the notice
30* and other provisions required by the GPL or the LGPL. If you do not delete
31* the provisions above, a recipient may use your version of this file under
32* the terms of any one of the NPL, the GPL or the LGPL.
33*
34* ***** END LICENSE BLOCK *****
35*
36*
37* Date: 08 Jan 2002
38* SUMMARY: Just testing that we don't crash on this code
39* See http://bugzilla.mozilla.org/show_bug.cgi?id=118849
40*
41* http://developer.netscape.com:80/docs/manuals/js/core/jsref/function.htm
42* The Function constructor:
43* Function ([arg1[, arg2[, ... argN]],] functionBody)
44*
45* Parameters
46* arg1, arg2, ... argN
47* (Optional) Names to be used by the function as formal argument names.
48* Each must be a string that corresponds to a valid JavaScript identifier.
49*
50* functionBody
51* A string containing JS statements comprising the function definition.
52*/
53//-----------------------------------------------------------------------------
54var UBound = 0;
55var bug = 118849;
56var summary = 'Should not crash if we provide Function() with bad arguments'
57var status = '';
58var statusitems = [];
59var actual = '';
60var actualvalues = [];
61var expect= '';
62var expectedvalues = [];
63var cnFAIL_1 = 'LEGAL call to Function() caused an ERROR!!!';
64var cnFAIL_2 = 'ILLEGAL call to Function() FAILED to cause an error';
65var cnSTRING = 'ASDF';
66var cnNUMBER = 123;
67
68
69/***********************************************************/
70/**** THESE ARE LEGITMATE CALLS AND SHOULD ALL SUCCEED ***/
71/***********************************************************/
72status = inSection(1);
73actual = cnFAIL_1; // initialize to failure
74try
75{
76 Function(cnSTRING);
77 Function(cnNUMBER); // cnNUMBER is a valid functionBody
78 Function(cnSTRING,cnSTRING);
79 Function(cnSTRING,cnNUMBER);
80 Function(cnSTRING,cnSTRING,cnNUMBER);
81
82 new Function(cnSTRING);
83 new Function(cnNUMBER);
84 new Function(cnSTRING,cnSTRING);
85 new Function(cnSTRING,cnNUMBER);
86 new Function(cnSTRING,cnSTRING,cnNUMBER);
87
88 actual = expect;
89}
90catch(e)
91{
92}
93addThis();
94
95
96
97/**********************************************************/
98/*** EACH CASE THAT FOLLOWS SHOULD TRIGGER AN ERROR ***/
99/*** (BUT NOT A CRASH) ***/
100/*** NOTE WE NOW USE cnFAIL_2 INSTEAD OF cnFAIL_1 ***/
101/**********************************************************/
102status = inSection(2);
103actual = cnFAIL_2;
104try
105{
106 Function(cnNUMBER,cnNUMBER); // cnNUMBER is an invalid JS identifier name
107}
108catch(e)
109{
110 actual = expect;
111}
112addThis();
113
114
115status = inSection(3);
116actual = cnFAIL_2;
117try
118{
119 Function(cnNUMBER,cnSTRING,cnSTRING);
120}
121catch(e)
122{
123 actual = expect;
124}
125addThis();
126
127
128status = inSection(4);
129actual = cnFAIL_2;
130try
131{
132 new Function(cnNUMBER,cnNUMBER);
133}
134catch(e)
135{
136 actual = expect;
137}
138addThis();
139
140
141status = inSection(5);
142actual = cnFAIL_2;
143try
144{
145 new Function(cnNUMBER,cnSTRING,cnSTRING);
146}
147catch(e)
148{
149 actual = expect;
150}
151addThis();
152
153
154
155//-----------------------------------------------------------------------------
156test();
157//-----------------------------------------------------------------------------
158
159
160function addThis()
161{
162 statusitems[UBound] = status;
163 actualvalues[UBound] = actual;
164 expectedvalues[UBound] = expect;
165 UBound++;
166}
167
168
169function test()
170{
171 enterFunc ('test');
172 printBugNumber (bug);
173 printStatus (summary);
174
175 for (var i = 0; i < UBound; i++)
176 {
177 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
178 }
179
180 exitFunc ('test');
181}