* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma / ExecutionContexts / 10.1.3.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /**
40    File Name:          10.1.3.js
41    ECMA Section:       10.1.3.js Variable Instantiation
42    Description:
43    Author:             christine@netscape.com
44    Date:               11 september 1997
45 */
46
47 var SECTION = "10.1.3";
48 var VERSION = "ECMA_1";
49 startTest();
50 var TITLE   = "Variable instantiation";
51 var BUGNUMBER = "20256";
52
53 writeHeaderToLog( SECTION + " "+ TITLE);
54
55     
56 // overriding a variable or function name with a function should succeed
57      
58 new TestCase(SECTION,
59              "function t() { return \"first\" };" +
60              "function t() { return \"second\" };t() ",
61              "second",
62              eval("function t() { return \"first\" };" +
63                   "function t() { return \"second\" };t()"));
64
65     
66 new TestCase(SECTION,
67              "var t; function t(){}; typeof(t)",
68              "function",
69              eval("var t; function t(){}; typeof(t)"));
70
71
72 // formal parameter tests
73      
74 new TestCase(SECTION,
75              "function t1(a,b) { return b; }; t1( 4 );",
76              void 0,
77              eval("function t1(a,b) { return b; }; t1( 4 );") );
78     
79 new TestCase(SECTION, 
80              "function t1(a,b) { return a; }; t1(4);",
81              4,
82              eval("function t1(a,b) { return a; }; t1(4)"));
83      
84 new TestCase(SECTION,
85              "function t1(a,b) { return a; }; t1();",
86              void 0,
87              eval("function t1(a,b) { return a; }; t1()"));
88     
89 new TestCase(SECTION, 
90              "function t1(a,b) { return a; }; t1(1,2,4);",
91              1,
92              eval("function t1(a,b) { return a; }; t1(1,2,4)"));
93 /*
94     
95 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );",
96 void 0,
97 eval("function t1(a,a) { return a; }; t1( 4 )"));
98      
99 new TestCase(SECTION,
100 "function t1(a,a) { return a; }; t1( 1,2 );",
101 2,
102 eval("function t1(a,a) { return a; }; t1( 1,2 )"));
103 */
104 // variable declarations
105     
106 new TestCase(SECTION,
107              "function t1(a,b) { return a; }; t1( false, true );",
108              false,
109              eval("function t1(a,b) { return a; }; t1( false, true );"));
110     
111 new TestCase(SECTION,
112              "function t1(a,b) { return b; }; t1( false, true );",
113              true,
114              eval("function t1(a,b) { return b; }; t1( false, true );"));
115     
116 new TestCase(SECTION,
117              "function t1(a,b) { return a+b; }; t1( 4, 2 );",
118              6,
119              eval("function t1(a,b) { return a+b; }; t1( 4, 2 );"));
120     
121 new TestCase(SECTION,
122              "function t1(a,b) { return a+b; }; t1( 4 );",
123              Number.NaN,
124              eval("function t1(a,b) { return a+b; }; t1( 4 );"));
125
126 // overriding a function name with a variable should fail
127     
128 new TestCase(SECTION,
129              "function t() { return 'function' };" +
130              "var t = 'variable'; typeof(t)",
131              "string",
132              eval("function t() { return 'function' };" +
133                   "var t = 'variable'; typeof(t)"));
134
135 // function as a constructor
136     
137 new TestCase(SECTION,
138              "function t1(a,b) { var a = b; return a; } t1(1,3);",
139              3,
140              eval("function t1(a, b){ var a = b; return a;}; t1(1,3)"));
141     
142 new TestCase(SECTION,
143              "function t2(a,b) { this.a = b;  } x  = new t2(1,3); x.a",
144              3,
145              eval("function t2(a,b) { this.a = b; };" +
146                   "x = new t2(1,3); x.a"));
147     
148 new TestCase(SECTION, 
149              "function t2(a,b) { this.a = a;  } x  = new t2(1,3); x.a",
150              1,
151              eval("function t2(a,b) { this.a = a; };" +
152                   "x = new t2(1,3); x.a"));
153     
154 new TestCase(SECTION,
155              "function t2(a,b) { this.a = b; this.b = a; } " +
156              "x = new t2(1,3);x.a;",
157              3,
158              eval("function t2(a,b) { this.a = b; this.b = a; };" +
159                   "x = new t2(1,3);x.a;"));
160     
161 new TestCase(SECTION,
162              "function t2(a,b) { this.a = b; this.b = a; }" +
163              "x = new t2(1,3);x.b;",
164              1,
165              eval("function t2(a,b) { this.a = b; this.b = a; };" +
166                   "x = new t2(1,3);x.b;") );
167
168 test();