|
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 * File Name: function-002.js |
|
9 * Description: |
|
10 * |
|
11 * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=330462 |
|
12 * js> function f(a){var a,b;} |
|
13 * |
|
14 * causes an an assert on a null 'sprop' in the 'Variables' function in |
|
15 * jsparse.c This will crash non-debug build. |
|
16 * |
|
17 * Author: christine@netscape.com |
|
18 * Date: 11 August 1998 |
|
19 * REVISED: 04 February 2001 |
|
20 * (changed the comma expressions from trivial to non-trivial) |
|
21 * Author: pschwartau@netscape.com |
|
22 * |
|
23 * Brendan: "The test seemed to require something that ECMA does not |
|
24 * guarantee, and that JS1.4 didn't either. For example, given |
|
25 * |
|
26 * dec2 = "function f2(){1,2}"; |
|
27 * |
|
28 * the engine is free to decompile a function object compiled from this source, |
|
29 * via Function.prototype.toString(), into some other string that compiles to |
|
30 * an equivalent function. The engine now eliminates the useless comma expression |
|
31 * 1,2, giving function f2(){}. This should be legal by the testsuite's lights." |
|
32 * |
|
33 */ |
|
34 var SECTION = "function-002.js"; |
|
35 var VERSION = "JS1_4"; |
|
36 var TITLE = "Regression test case for 325843"; |
|
37 var BUGNUMBER="330462"; |
|
38 |
|
39 startTest(); |
|
40 |
|
41 writeHeaderToLog( SECTION + " "+ TITLE); |
|
42 |
|
43 dec1 = "function f1(x,y){++x, --y}"; |
|
44 dec2 = "function f2(){var y; f1(1,2); y=new Date(); print(y.toString())}"; |
|
45 |
|
46 eval(dec1); |
|
47 eval(dec2); |
|
48 |
|
49 new TestCase( |
|
50 SECTION, |
|
51 "typeof f1", |
|
52 "function", |
|
53 typeof f1 ); |
|
54 |
|
55 |
|
56 // force a function decompilation |
|
57 new TestCase( |
|
58 SECTION, |
|
59 "f1.toString() == dec1", |
|
60 true, |
|
61 StripSpaces(f1.toString()) == StripSpaces(dec1)); |
|
62 |
|
63 new TestCase( |
|
64 SECTION, |
|
65 "typeof f2", |
|
66 "function", |
|
67 typeof f2 ); |
|
68 |
|
69 // force a function decompilation |
|
70 |
|
71 new TestCase( |
|
72 SECTION, |
|
73 "f2.toString() == dec2", |
|
74 true, |
|
75 StripSpaces(f2.toString().replace(/new Date\(\)/g, 'new Date')) == |
|
76 StripSpaces(dec2.replace(/new Date\(\)/g, 'new Date'))); |
|
77 |
|
78 test(); |
|
79 |
|
80 function StripSpaces( s ) { |
|
81 var strippedString = ""; |
|
82 for ( var currentChar = 0; currentChar < s.length; currentChar++ ) { |
|
83 if (!IsWhiteSpace(s.charAt(currentChar))) { |
|
84 strippedString += s.charAt(currentChar); |
|
85 } |
|
86 } |
|
87 return strippedString; |
|
88 } |
|
89 |
|
90 function IsWhiteSpace( string ) { |
|
91 var cc = string.charCodeAt(0); |
|
92 |
|
93 switch (cc) { |
|
94 case (0x0009): |
|
95 case (0x000B): |
|
96 case (0x000C): |
|
97 case (0x0020): |
|
98 case (0x000A): |
|
99 case (0x000D): |
|
100 case ( 59 ): // let's strip out semicolons, too |
|
101 return true; |
|
102 break; |
|
103 default: |
|
104 return false; |
|
105 } |
|
106 } |
|
107 |