Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-118849.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: 08 Jan 2002
9 * SUMMARY: Just testing that we don't crash on this code
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=118849
11 *
12 * http://developer.netscape.com:80/docs/manuals/js/core/jsref/function.htm
13 * The Function constructor:
14 * Function ([arg1[, arg2[, ... argN]],] functionBody)
15 *
16 * Parameters
17 * arg1, arg2, ... argN
18 * (Optional) Names to be used by the function as formal argument names.
19 * Each must be a string that corresponds to a valid JavaScript identifier.
20 *
21 * functionBody
22 * A string containing JS statements comprising the function definition.
23 */
24 //-----------------------------------------------------------------------------
25 var gTestfile = 'regress-118849.js';
26 var UBound = 0;
27 var BUGNUMBER = 118849;
28 var summary = 'Should not crash if we provide Function() with bad arguments'
29 var status = '';
30 var statusitems = [];
31 var actual = '';
32 var actualvalues = [];
33 var expect= '';
34 var expectedvalues = [];
35 var cnFAIL_1 = 'LEGAL call to Function() caused an ERROR!!!';
36 var cnFAIL_2 = 'ILLEGAL call to Function() FAILED to cause an error';
37 var cnSTRING = 'ASDF';
38 var cnNUMBER = 123;
39
40
41 /***********************************************************/
42 /**** THESE ARE LEGITMATE CALLS AND SHOULD ALL SUCCEED ***/
43 /***********************************************************/
44 status = inSection(1);
45 actual = cnFAIL_1; // initialize to failure
46 try
47 {
48 Function(cnSTRING);
49 Function(cnNUMBER); // cnNUMBER is a valid functionBody
50 Function(cnSTRING,cnSTRING);
51 Function(cnSTRING,cnNUMBER);
52 Function(cnSTRING,cnSTRING,cnNUMBER);
53
54 new Function(cnSTRING);
55 new Function(cnNUMBER);
56 new Function(cnSTRING,cnSTRING);
57 new Function(cnSTRING,cnNUMBER);
58 new Function(cnSTRING,cnSTRING,cnNUMBER);
59
60 actual = expect;
61 }
62 catch(e)
63 {
64 }
65 addThis();
66
67
68
69 /**********************************************************/
70 /*** EACH CASE THAT FOLLOWS SHOULD TRIGGER AN ERROR ***/
71 /*** (BUT NOT A CRASH) ***/
72 /*** NOTE WE NOW USE cnFAIL_2 INSTEAD OF cnFAIL_1 ***/
73 /**********************************************************/
74 status = inSection(2);
75 actual = cnFAIL_2;
76 try
77 {
78 Function(cnNUMBER,cnNUMBER); // cnNUMBER is an invalid JS identifier name
79 }
80 catch(e)
81 {
82 actual = expect;
83 }
84 addThis();
85
86
87 status = inSection(3);
88 actual = cnFAIL_2;
89 try
90 {
91 Function(cnNUMBER,cnSTRING,cnSTRING);
92 }
93 catch(e)
94 {
95 actual = expect;
96 }
97 addThis();
98
99
100 status = inSection(4);
101 actual = cnFAIL_2;
102 try
103 {
104 new Function(cnNUMBER,cnNUMBER);
105 }
106 catch(e)
107 {
108 actual = expect;
109 }
110 addThis();
111
112
113 status = inSection(5);
114 actual = cnFAIL_2;
115 try
116 {
117 new Function(cnNUMBER,cnSTRING,cnSTRING);
118 }
119 catch(e)
120 {
121 actual = expect;
122 }
123 addThis();
124
125
126
127 //-----------------------------------------------------------------------------
128 test();
129 //-----------------------------------------------------------------------------
130
131
132 function addThis()
133 {
134 statusitems[UBound] = status;
135 actualvalues[UBound] = actual;
136 expectedvalues[UBound] = expect;
137 UBound++;
138 }
139
140
141 function test()
142 {
143 enterFunc ('test');
144 printBugNumber(BUGNUMBER);
145 printStatus (summary);
146
147 for (var i = 0; i < UBound; i++)
148 {
149 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
150 }
151
152 exitFunc ('test');
153 }