Debian Codegraph @

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