Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / 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 /**
41    File Name:          10.1.3.js
42    ECMA Section:       10.1.3.js Variable Instantiation
43    Description:
44    Author:             christine@netscape.com
45    Date:               11 september 1997
46 */
47
48 var SECTION = "10.1.3";
49 var VERSION = "ECMA_1";
50 var TITLE   = "Variable instantiation";
51 var BUGNUMBER = "20256";
52 startTest();
53
54 writeHeaderToLog( SECTION + " "+ TITLE);
55
56    
57 // overriding a variable or function name with a function should succeed
58     
59 new TestCase(SECTION,
60              "function t() { return \"first\" };" +
61              "function t() { return \"second\" };t() ",
62              "second",
63              eval("function t() { return \"first\" };" +
64                   "function t() { return \"second\" };t()"));
65
66    
67 new TestCase(SECTION,
68              "var t; function t(){}; typeof(t)",
69              "function",
70              eval("var t; function t(){}; typeof(t)"));
71
72
73 // formal parameter tests
74     
75 new TestCase(SECTION,
76              "function t1(a,b) { return b; }; t1( 4 );",
77              void 0,
78              eval("function t1(a,b) { return b; }; t1( 4 );") );
79    
80 new TestCase(SECTION,
81              "function t1(a,b) { return a; }; t1(4);",
82              4,
83              eval("function t1(a,b) { return a; }; t1(4)"));
84     
85 new TestCase(SECTION,
86              "function t1(a,b) { return a; }; t1();",
87              void 0,
88              eval("function t1(a,b) { return a; }; t1()"));
89    
90 new TestCase(SECTION,
91              "function t1(a,b) { return a; }; t1(1,2,4);",
92              1,
93              eval("function t1(a,b) { return a; }; t1(1,2,4)"));
94 /*
95    
96 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );",
97 void 0,
98 eval("function t1(a,a) { return a; }; t1( 4 )"));
99     
100 new TestCase(SECTION,
101 "function t1(a,a) { return a; }; t1( 1,2 );",
102 2,
103 eval("function t1(a,a) { return a; }; t1( 1,2 )"));
104 */
105 // variable declarations
106    
107 new TestCase(SECTION,
108              "function t1(a,b) { return a; }; t1( false, true );",
109              false,
110              eval("function t1(a,b) { return a; }; t1( false, true );"));
111    
112 new TestCase(SECTION,
113              "function t1(a,b) { return b; }; t1( false, true );",
114              true,
115              eval("function t1(a,b) { return b; }; t1( false, true );"));
116    
117 new TestCase(SECTION,
118              "function t1(a,b) { return a+b; }; t1( 4, 2 );",
119              6,
120              eval("function t1(a,b) { return a+b; }; t1( 4, 2 );"));
121    
122 new TestCase(SECTION,
123              "function t1(a,b) { return a+b; }; t1( 4 );",
124              Number.NaN,
125              eval("function t1(a,b) { return a+b; }; t1( 4 );"));
126
127 // overriding a function name with a variable should fail
128    
129 new TestCase(SECTION,
130              "function t() { return 'function' };" +
131              "var t = 'variable'; typeof(t)",
132              "string",
133              eval("function t() { return 'function' };" +
134                   "var t = 'variable'; typeof(t)"));
135
136 // function as a constructor
137    
138 new TestCase(SECTION,
139              "function t1(a,b) { var a = b; return a; } t1(1,3);",
140              3,
141              eval("function t1(a, b){ var a = b; return a;}; t1(1,3)"));
142    
143 new TestCase(SECTION,
144              "function t2(a,b) { this.a = b;  } x  = new t2(1,3); x.a",
145              3,
146              eval("function t2(a,b) { this.a = b; };" +
147                   "x = new t2(1,3); x.a"));
148    
149 new TestCase(SECTION,
150              "function t2(a,b) { this.a = a;  } x  = new t2(1,3); x.a",
151              1,
152              eval("function t2(a,b) { this.a = a; };" +
153                   "x = new t2(1,3); x.a"));
154    
155 new TestCase(SECTION,
156              "function t2(a,b) { this.a = b; this.b = a; } " +
157              "x = new t2(1,3);x.a;",
158              3,
159              eval("function t2(a,b) { this.a = b; this.b = a; };" +
160                   "x = new t2(1,3);x.a;"));
161    
162 new TestCase(SECTION,
163              "function t2(a,b) { this.a = b; this.b = a; }" +
164              "x = new t2(1,3);x.b;",
165              1,
166              eval("function t2(a,b) { this.a = b; this.b = a; };" +
167                   "x = new t2(1,3);x.b;") );
168
169 test();