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/ 5 * 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. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 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 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22/** 23 File Name: 10.1.3.js 24 ECMA Section: 10.1.3.js Variable Instantiation 25 Description: 26 Author: christine@netscape.com 27 Date: 11 september 1997 28*/ 29 30var SECTION = "10.1.3"; 31var VERSION = "ECMA_1"; 32startTest(); 33var TITLE = "Variable instantiation"; 34var BUGNUMBER = "20256"; 35 36writeHeaderToLog( SECTION + " "+ TITLE); 37 38var testcases = getTestCases(); 39 40test(); 41 42 43function getTestCases() { 44 var array = new Array(); 45 var item = 0; 46 47 // overriding a variable or function name with a function should succeed 48 array[item++] = 49 new TestCase(SECTION, 50 "function t() { return \"first\" };" + 51 "function t() { return \"second\" };t() ", 52 "second", 53 eval("function t() { return \"first\" };" + 54 "function t() { return \"second\" };t()")); 55 56 array[item++] = 57 new TestCase(SECTION, 58 "var t; function t(){}; typeof(t)", 59 "function", 60 eval("var t; function t(){}; typeof(t)")); 61 62 63 // formal parameter tests 64 array[item++] = 65 new TestCase(SECTION, 66 "function t1(a,b) { return b; }; t1( 4 );", 67 void 0, 68 eval("function t1(a,b) { return b; }; t1( 4 );") ); 69 array[item++] = 70 new TestCase(SECTION, 71 "function t1(a,b) { return a; }; t1(4);", 72 4, 73 eval("function t1(a,b) { return a; }; t1(4)")); 74 array[item++] = 75 new TestCase(SECTION, 76 "function t1(a,b) { return a; }; t1();", 77 void 0, 78 eval("function t1(a,b) { return a; }; t1()")); 79 array[item++] = 80 new TestCase(SECTION, 81 "function t1(a,b) { return a; }; t1(1,2,4);", 82 1, 83 eval("function t1(a,b) { return a; }; t1(1,2,4)")); 84/* 85 array[item++] = 86 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );", 87 void 0, 88 eval("function t1(a,a) { return a; }; t1( 4 )")); 89 array[item++] = 90 new TestCase(SECTION, 91 "function t1(a,a) { return a; }; t1( 1,2 );", 92 2, 93 eval("function t1(a,a) { return a; }; t1( 1,2 )")); 94*/ 95 // variable declarations 96 array[item++] = 97 new TestCase(SECTION, 98 "function t1(a,b) { return a; }; t1( false, true );", 99 false, 100 eval("function t1(a,b) { return a; }; t1( false, true );")); 101 array[item++] = 102 new TestCase(SECTION, 103 "function t1(a,b) { return b; }; t1( false, true );", 104 true, 105 eval("function t1(a,b) { return b; }; t1( false, true );")); 106 array[item++] = 107 new TestCase(SECTION, 108 "function t1(a,b) { return a+b; }; t1( 4, 2 );", 109 6, 110 eval("function t1(a,b) { return a+b; }; t1( 4, 2 );")); 111 array[item++] = 112 new TestCase(SECTION, 113 "function t1(a,b) { return a+b; }; t1( 4 );", 114 Number.NaN, 115 eval("function t1(a,b) { return a+b; }; t1( 4 );")); 116 117 // overriding a function name with a variable should fail 118 array[item++] = 119 new TestCase(SECTION, 120 "function t() { return 'function' };" + 121 "var t = 'variable'; typeof(t)", 122 "string", 123 eval("function t() { return 'function' };" + 124 "var t = 'variable'; typeof(t)")); 125 126 // function as a constructor 127 array[item++] = 128 new TestCase(SECTION, 129 "function t1(a,b) { var a = b; return a; } t1(1,3);", 130 3, 131 eval("function t1(a, b){ var a = b; return a;}; t1(1,3)")); 132 array[item++] = 133 new TestCase(SECTION, 134 "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a", 135 3, 136 eval("function t2(a,b) { this.a = b; };" + 137 "x = new t2(1,3); x.a")); 138 array[item++] = 139 new TestCase(SECTION, 140 "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a", 141 1, 142 eval("function t2(a,b) { this.a = a; };" + 143 "x = new t2(1,3); x.a")); 144 array[item++] = 145 new TestCase(SECTION, 146 "function t2(a,b) { this.a = b; this.b = a; } " + 147 "x = new t2(1,3);x.a;", 148 3, 149 eval("function t2(a,b) { this.a = b; this.b = a; };" + 150 "x = new t2(1,3);x.a;")); 151 array[item++] = 152 new TestCase(SECTION, 153 "function t2(a,b) { this.a = b; this.b = a; }" + 154 "x = new t2(1,3);x.b;", 155 1, 156 eval("function t2(a,b) { this.a = b; this.b = a; };" + 157 "x = new t2(1,3);x.b;") ); 158 159 return (array); 160} 161