michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 10.1.3.js michael@0: ECMA Section: 10.1.3.js Variable Instantiation michael@0: Description: michael@0: Author: christine@netscape.com michael@0: Date: 11 september 1997 michael@0: */ michael@0: michael@0: var SECTION = "10.1.3"; michael@0: var VERSION = "ECMA_1"; michael@0: var TITLE = "Variable instantiation"; michael@0: var BUGNUMBER = "20256"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: michael@0: // overriding a variable or function name with a function should succeed michael@0: michael@0: new TestCase(SECTION, michael@0: "function t() { return \"first\" };" + michael@0: "function t() { return \"second\" };t() ", michael@0: "second", michael@0: eval("function t() { return \"first\" };" + michael@0: "function t() { return \"second\" };t()")); michael@0: michael@0: michael@0: new TestCase(SECTION, michael@0: "var t; function t(){}; typeof(t)", michael@0: "function", michael@0: eval("var t; function t(){}; typeof(t)")); michael@0: michael@0: michael@0: // formal parameter tests michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return b; }; t1( 4 );", michael@0: void 0, michael@0: eval("function t1(a,b) { return b; }; t1( 4 );") ); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return a; }; t1(4);", michael@0: 4, michael@0: eval("function t1(a,b) { return a; }; t1(4)")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return a; }; t1();", michael@0: void 0, michael@0: eval("function t1(a,b) { return a; }; t1()")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return a; }; t1(1,2,4);", michael@0: 1, michael@0: eval("function t1(a,b) { return a; }; t1(1,2,4)")); michael@0: /* michael@0: michael@0: new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );", michael@0: void 0, michael@0: eval("function t1(a,a) { return a; }; t1( 4 )")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,a) { return a; }; t1( 1,2 );", michael@0: 2, michael@0: eval("function t1(a,a) { return a; }; t1( 1,2 )")); michael@0: */ michael@0: // variable declarations michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return a; }; t1( false, true );", michael@0: false, michael@0: eval("function t1(a,b) { return a; }; t1( false, true );")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return b; }; t1( false, true );", michael@0: true, michael@0: eval("function t1(a,b) { return b; }; t1( false, true );")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return a+b; }; t1( 4, 2 );", michael@0: 6, michael@0: eval("function t1(a,b) { return a+b; }; t1( 4, 2 );")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { return a+b; }; t1( 4 );", michael@0: Number.NaN, michael@0: eval("function t1(a,b) { return a+b; }; t1( 4 );")); michael@0: michael@0: // overriding a function name with a variable should fail michael@0: michael@0: new TestCase(SECTION, michael@0: "function t() { return 'function' };" + michael@0: "var t = 'variable'; typeof(t)", michael@0: "string", michael@0: eval("function t() { return 'function' };" + michael@0: "var t = 'variable'; typeof(t)")); michael@0: michael@0: // function as a constructor michael@0: michael@0: new TestCase(SECTION, michael@0: "function t1(a,b) { var a = b; return a; } t1(1,3);", michael@0: 3, michael@0: eval("function t1(a, b){ var a = b; return a;}; t1(1,3)")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a", michael@0: 3, michael@0: eval("function t2(a,b) { this.a = b; };" + michael@0: "x = new t2(1,3); x.a")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a", michael@0: 1, michael@0: eval("function t2(a,b) { this.a = a; };" + michael@0: "x = new t2(1,3); x.a")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t2(a,b) { this.a = b; this.b = a; } " + michael@0: "x = new t2(1,3);x.a;", michael@0: 3, michael@0: eval("function t2(a,b) { this.a = b; this.b = a; };" + michael@0: "x = new t2(1,3);x.a;")); michael@0: michael@0: new TestCase(SECTION, michael@0: "function t2(a,b) { this.a = b; this.b = a; }" + michael@0: "x = new t2(1,3);x.b;", michael@0: 1, michael@0: eval("function t2(a,b) { this.a = b; this.b = a; };" + michael@0: "x = new t2(1,3);x.b;") ); michael@0: michael@0: test();