]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/ExecutionContexts/10.1.3.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 ECMA Section: 10.1.3.js Variable Instantiation
26 Author: christine@netscape.com
27 Date: 11 september 1997
30 var SECTION
= "10.1.3";
31 var VERSION
= "ECMA_1";
33 var TITLE
= "Variable instantiation";
34 var BUGNUMBER
= "20256";
36 writeHeaderToLog( SECTION
+ " "+ TITLE
);
38 var testcases
= getTestCases();
43 function getTestCases() {
44 var array
= new Array();
47 // overriding a variable or function name with a function should succeed
50 "function t() { return \"first\" };" +
51 "function t() { return \"second\" };t() ",
53 eval("function t() { return \"first\" };" +
54 "function t() { return \"second\" };t()"));
58 "var t; function t(){}; typeof(t)",
60 eval("var t; function t(){}; typeof(t)"));
63 // formal parameter tests
66 "function t1(a,b) { return b; }; t1( 4 );",
68 eval("function t1(a,b) { return b; }; t1( 4 );") );
71 "function t1(a,b) { return a; }; t1(4);",
73 eval("function t1(a,b) { return a; }; t1(4)"));
76 "function t1(a,b) { return a; }; t1();",
78 eval("function t1(a,b) { return a; }; t1()"));
81 "function t1(a,b) { return a; }; t1(1,2,4);",
83 eval("function t1(a,b) { return a; }; t1(1,2,4)"));
86 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );",
88 eval("function t1(a,a) { return a; }; t1( 4 )"));
91 "function t1(a,a) { return a; }; t1( 1,2 );",
93 eval("function t1(a,a) { return a; }; t1( 1,2 )"));
95 // variable declarations
98 "function t1(a,b) { return a; }; t1( false, true );",
100 eval("function t1(a,b) { return a; }; t1( false, true );"));
102 new TestCase(SECTION
,
103 "function t1(a,b) { return b; }; t1( false, true );",
105 eval("function t1(a,b) { return b; }; t1( false, true );"));
107 new TestCase(SECTION
,
108 "function t1(a,b) { return a+b; }; t1( 4, 2 );",
110 eval("function t1(a,b) { return a+b; }; t1( 4, 2 );"));
112 new TestCase(SECTION
,
113 "function t1(a,b) { return a+b; }; t1( 4 );",
115 eval("function t1(a,b) { return a+b; }; t1( 4 );"));
117 // overriding a function name with a variable should fail
119 new TestCase(SECTION
,
120 "function t() { return 'function' };" +
121 "var t = 'variable'; typeof(t)",
123 eval("function t() { return 'function' };" +
124 "var t = 'variable'; typeof(t)"));
126 // function as a constructor
128 new TestCase(SECTION
,
129 "function t1(a,b) { var a = b; return a; } t1(1,3);",
131 eval("function t1(a, b){ var a = b; return a;}; t1(1,3)"));
133 new TestCase(SECTION
,
134 "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a",
136 eval("function t2(a,b) { this.a = b; };" +
137 "x = new t2(1,3); x.a"));
139 new TestCase(SECTION
,
140 "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a",
142 eval("function t2(a,b) { this.a = a; };" +
143 "x = new t2(1,3); x.a"));
145 new TestCase(SECTION
,
146 "function t2(a,b) { this.a = b; this.b = a; } " +
147 "x = new t2(1,3);x.a;",
149 eval("function t2(a,b) { this.a = b; this.b = a; };" +
150 "x = new t2(1,3);x.a;"));
152 new TestCase(SECTION
,
153 "function t2(a,b) { this.a = b; this.b = a; }" +
154 "x = new t2(1,3);x.b;",
156 eval("function t2(a,b) { this.a = b; this.b = a; };" +
157 "x = new t2(1,3);x.b;") );