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 ***** */
42 ECMA Section: 10.1.3.js Variable Instantiation
44 Author: christine@netscape.com
45 Date: 11 september 1997
48 var SECTION = "10.1.3";
49 var VERSION = "ECMA_1";
50 var TITLE = "Variable instantiation";
51 var BUGNUMBER = "20256";
54 writeHeaderToLog( SECTION + " "+ TITLE);
57 // overriding a variable or function name with a function should succeed
60 "function t() { return \"first\" };" +
61 "function t() { return \"second\" };t() ",
63 eval("function t() { return \"first\" };" +
64 "function t() { return \"second\" };t()"));
68 "var t; function t(){}; typeof(t)",
70 eval("var t; function t(){}; typeof(t)"));
73 // formal parameter tests
76 "function t1(a,b) { return b; }; t1( 4 );",
78 eval("function t1(a,b) { return b; }; t1( 4 );") );
81 "function t1(a,b) { return a; }; t1(4);",
83 eval("function t1(a,b) { return a; }; t1(4)"));
86 "function t1(a,b) { return a; }; t1();",
88 eval("function t1(a,b) { return a; }; t1()"));
91 "function t1(a,b) { return a; }; t1(1,2,4);",
93 eval("function t1(a,b) { return a; }; t1(1,2,4)"));
96 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );",
98 eval("function t1(a,a) { return a; }; t1( 4 )"));
100 new TestCase(SECTION,
101 "function t1(a,a) { return a; }; t1( 1,2 );",
103 eval("function t1(a,a) { return a; }; t1( 1,2 )"));
105 // variable declarations
107 new TestCase(SECTION,
108 "function t1(a,b) { return a; }; t1( false, true );",
110 eval("function t1(a,b) { return a; }; t1( false, true );"));
112 new TestCase(SECTION,
113 "function t1(a,b) { return b; }; t1( false, true );",
115 eval("function t1(a,b) { return b; }; t1( false, true );"));
117 new TestCase(SECTION,
118 "function t1(a,b) { return a+b; }; t1( 4, 2 );",
120 eval("function t1(a,b) { return a+b; }; t1( 4, 2 );"));
122 new TestCase(SECTION,
123 "function t1(a,b) { return a+b; }; t1( 4 );",
125 eval("function t1(a,b) { return a+b; }; t1( 4 );"));
127 // overriding a function name with a variable should fail
129 new TestCase(SECTION,
130 "function t() { return 'function' };" +
131 "var t = 'variable'; typeof(t)",
133 eval("function t() { return 'function' };" +
134 "var t = 'variable'; typeof(t)"));
136 // function as a constructor
138 new TestCase(SECTION,
139 "function t1(a,b) { var a = b; return a; } t1(1,3);",
141 eval("function t1(a, b){ var a = b; return a;}; t1(1,3)"));
143 new TestCase(SECTION,
144 "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a",
146 eval("function t2(a,b) { this.a = b; };" +
147 "x = new t2(1,3); x.a"));
149 new TestCase(SECTION,
150 "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a",
152 eval("function t2(a,b) { this.a = a; };" +
153 "x = new t2(1,3); x.a"));
155 new TestCase(SECTION,
156 "function t2(a,b) { this.a = b; this.b = a; } " +
157 "x = new t2(1,3);x.a;",
159 eval("function t2(a,b) { this.a = b; this.b = a; };" +
160 "x = new t2(1,3);x.a;"));
162 new TestCase(SECTION,
163 "function t2(a,b) { this.a = b; this.b = a; }" +
164 "x = new t2(1,3);x.b;",
166 eval("function t2(a,b) { this.a = b; this.b = a; };" +
167 "x = new t2(1,3);x.b;") );