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
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/
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
15 * The Original Code is Mozilla Communicator client code, released
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.
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.
37 * ***** END LICENSE BLOCK ***** */
41 ECMA Section: 10.1.3.js Variable Instantiation
43 Author: christine@netscape.com
44 Date: 11 september 1997
47 var SECTION = "10.1.3";
48 var VERSION = "ECMA_1";
50 var TITLE = "Variable instantiation";
51 var BUGNUMBER = "20256";
53 writeHeaderToLog( SECTION + " "+ TITLE);
56 // overriding a variable or function name with a function should succeed
59 "function t() { return \"first\" };" +
60 "function t() { return \"second\" };t() ",
62 eval("function t() { return \"first\" };" +
63 "function t() { return \"second\" };t()"));
67 "var t; function t(){}; typeof(t)",
69 eval("var t; function t(){}; typeof(t)"));
72 // formal parameter tests
75 "function t1(a,b) { return b; }; t1( 4 );",
77 eval("function t1(a,b) { return b; }; t1( 4 );") );
80 "function t1(a,b) { return a; }; t1(4);",
82 eval("function t1(a,b) { return a; }; t1(4)"));
85 "function t1(a,b) { return a; }; t1();",
87 eval("function t1(a,b) { return a; }; t1()"));
90 "function t1(a,b) { return a; }; t1(1,2,4);",
92 eval("function t1(a,b) { return a; }; t1(1,2,4)"));
95 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );",
97 eval("function t1(a,a) { return a; }; t1( 4 )"));
100 "function t1(a,a) { return a; }; t1( 1,2 );",
102 eval("function t1(a,a) { return a; }; t1( 1,2 )"));
104 // variable declarations
106 new TestCase(SECTION,
107 "function t1(a,b) { return a; }; t1( false, true );",
109 eval("function t1(a,b) { return a; }; t1( false, true );"));
111 new TestCase(SECTION,
112 "function t1(a,b) { return b; }; t1( false, true );",
114 eval("function t1(a,b) { return b; }; t1( false, true );"));
116 new TestCase(SECTION,
117 "function t1(a,b) { return a+b; }; t1( 4, 2 );",
119 eval("function t1(a,b) { return a+b; }; t1( 4, 2 );"));
121 new TestCase(SECTION,
122 "function t1(a,b) { return a+b; }; t1( 4 );",
124 eval("function t1(a,b) { return a+b; }; t1( 4 );"));
126 // overriding a function name with a variable should fail
128 new TestCase(SECTION,
129 "function t() { return 'function' };" +
130 "var t = 'variable'; typeof(t)",
132 eval("function t() { return 'function' };" +
133 "var t = 'variable'; typeof(t)"));
135 // function as a constructor
137 new TestCase(SECTION,
138 "function t1(a,b) { var a = b; return a; } t1(1,3);",
140 eval("function t1(a, b){ var a = b; return a;}; t1(1,3)"));
142 new TestCase(SECTION,
143 "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a",
145 eval("function t2(a,b) { this.a = b; };" +
146 "x = new t2(1,3); x.a"));
148 new TestCase(SECTION,
149 "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a",
151 eval("function t2(a,b) { this.a = a; };" +
152 "x = new t2(1,3); x.a"));
154 new TestCase(SECTION,
155 "function t2(a,b) { this.a = b; this.b = a; } " +
156 "x = new t2(1,3);x.a;",
158 eval("function t2(a,b) { this.a = b; this.b = a; };" +
159 "x = new t2(1,3);x.a;"));
161 new TestCase(SECTION,
162 "function t2(a,b) { this.a = b; this.b = a; }" +
163 "x = new t2(1,3);x.b;",
165 eval("function t2(a,b) { this.a = b; this.b = a; };" +
166 "x = new t2(1,3);x.b;") );