]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_4/Regress/function-002.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_4 / Regress / function-002.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
5 *
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22 /**
23 * File Name: function-002.js
24 * Description:
25 *
26 * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=330462
27 * js> function f(a){var a,b;}
28 *
29 * causes an an assert on a null 'sprop' in the 'Variables' function in
30 * jsparse.c This will crash non-debug build.
31 *
32 * Author: christine@netscape.com
33 * Date: 11 August 1998
34 * REVISED: 04 February 2001
35 * (changed the comma expressions from trivial to non-trivial)
36 * Author: pschwartau@netscape.com
37 *
38 * Brendan: "The test seemed to require something that ECMA does not
39 * guarantee, and that JS1.4 didn't either. For example, given
40 *
41 * dec2 = "function f2(){1,2}";
42 *
43 * the engine is free to decompile a function object compiled from this source,
44 * via Function.prototype.toString(), into some other string that compiles to
45 * an equivalent function. The engine now eliminates the useless comma expression
46 * 1,2, giving function f2(){}. This should be legal by the testsuite's lights."
47 *
48 */
49 var SECTION = "function-002.js";
50 var VERSION = "JS1_4";
51 var TITLE = "Regression test case for 325843";
52 var BUGNUMBER="330462";
53
54 startTest();
55
56 writeHeaderToLog( SECTION + " "+ TITLE);
57
58 var testcases = new Array();
59
60 dec1 = "function f1(x,y){++x, --y}";
61 dec2 = "function f2(){var y; f1(1,2); y=new Date(); print(y.toString())}";
62
63 eval(dec1);
64 eval(dec2);
65
66 testcases[tc++] = new TestCase(
67 SECTION,
68 "typeof f1",
69 "function",
70 typeof f1 );
71
72
73 // force a function decompilation
74 testcases[tc++] = new TestCase(
75 SECTION,
76 "f1.toString() == dec1",
77 true,
78 StripSpaces(f1.toString()) == StripSpaces(dec1));
79
80 testcases[tc++] = new TestCase(
81 SECTION,
82 "typeof f2",
83 "function",
84 typeof f2 );
85
86 // force a function decompilation
87
88 testcases[tc++] = new TestCase(
89 SECTION,
90 "f2.toString() == dec2",
91 true,
92 StripSpaces(f2.toString()) == StripSpaces(dec2));
93
94 test();
95
96 function StripSpaces( s ) {
97 var strippedString = "";
98 for ( var currentChar = 0; currentChar < s.length; currentChar++ ) {
99 if (!IsWhiteSpace(s.charAt(currentChar))) {
100 strippedString += s.charAt(currentChar);
101 }
102 }
103 return strippedString;
104 }
105
106 function IsWhiteSpace( string ) {
107 var cc = string.charCodeAt(0);
108
109 switch (cc) {
110 case (0x0009):
111 case (0x000B):
112 case (0x000C):
113 case (0x0020):
114 case (0x000A):
115 case (0x000D):
116 case ( 59 ): // let's strip out semicolons, too
117 return true;
118 break;
119 default:
120 return false;
121 }
122 }
123