initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / js1_5 / Regress / regress-118849.js
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 //-----------------------------------------------------------------------------
54 var UBound = 0;
55 var bug = 118849;
56 var summary = 'Should not crash if we provide Function() with bad arguments'
57 var status = '';
58 var statusitems = [];
59 var actual = '';
60 var actualvalues = [];
61 var expect= '';
62 var expectedvalues = [];
63 var cnFAIL_1 = 'LEGAL call to Function() caused an ERROR!!!';
64 var cnFAIL_2 = 'ILLEGAL call to Function() FAILED to cause an error';
65 var cnSTRING = 'ASDF';
66 var cnNUMBER = 123;
67
68
69 /***********************************************************/
70 /****  THESE ARE LEGITMATE CALLS AND SHOULD ALL SUCCEED  ***/
71 /***********************************************************/
72 status = inSection(1);
73 actual = cnFAIL_1; // initialize to failure
74 try
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 }
90 catch(e)
91 {
92 }
93 addThis();
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 /**********************************************************/
102 status = inSection(2);
103 actual = cnFAIL_2;
104 try
105 {
106   Function(cnNUMBER,cnNUMBER); // cnNUMBER is an invalid JS identifier name
107 }
108 catch(e)
109 {
110   actual = expect;
111 }
112 addThis();
113
114
115 status = inSection(3);
116 actual = cnFAIL_2;
117 try
118 {
119   Function(cnNUMBER,cnSTRING,cnSTRING);
120 }
121 catch(e)
122 {
123   actual = expect;
124 }
125 addThis();
126
127
128 status = inSection(4);
129 actual = cnFAIL_2;
130 try
131 {
132   new Function(cnNUMBER,cnNUMBER);
133 }
134 catch(e)
135 {
136   actual = expect;
137 }
138 addThis();
139
140
141 status = inSection(5);
142 actual = cnFAIL_2;
143 try
144 {
145   new Function(cnNUMBER,cnSTRING,cnSTRING);
146 }
147 catch(e)
148 {
149   actual = expect;
150 }
151 addThis();
152
153
154
155 //-----------------------------------------------------------------------------
156 test();
157 //-----------------------------------------------------------------------------
158
159
160 function addThis()
161 {
162   statusitems[UBound] = status;
163   actualvalues[UBound] = actual;
164   expectedvalues[UBound] = expect;
165   UBound++;
166 }
167
168
169 function 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 }