1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/ExecutionContexts/10.1.3.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 10.1.3.js 1.12 + ECMA Section: 10.1.3.js Variable Instantiation 1.13 + Description: 1.14 + Author: christine@netscape.com 1.15 + Date: 11 september 1997 1.16 +*/ 1.17 + 1.18 +var SECTION = "10.1.3"; 1.19 +var VERSION = "ECMA_1"; 1.20 +var TITLE = "Variable instantiation"; 1.21 +var BUGNUMBER = "20256"; 1.22 +startTest(); 1.23 + 1.24 +writeHeaderToLog( SECTION + " "+ TITLE); 1.25 + 1.26 + 1.27 +// overriding a variable or function name with a function should succeed 1.28 + 1.29 +new TestCase(SECTION, 1.30 + "function t() { return \"first\" };" + 1.31 + "function t() { return \"second\" };t() ", 1.32 + "second", 1.33 + eval("function t() { return \"first\" };" + 1.34 + "function t() { return \"second\" };t()")); 1.35 + 1.36 + 1.37 +new TestCase(SECTION, 1.38 + "var t; function t(){}; typeof(t)", 1.39 + "function", 1.40 + eval("var t; function t(){}; typeof(t)")); 1.41 + 1.42 + 1.43 +// formal parameter tests 1.44 + 1.45 +new TestCase(SECTION, 1.46 + "function t1(a,b) { return b; }; t1( 4 );", 1.47 + void 0, 1.48 + eval("function t1(a,b) { return b; }; t1( 4 );") ); 1.49 + 1.50 +new TestCase(SECTION, 1.51 + "function t1(a,b) { return a; }; t1(4);", 1.52 + 4, 1.53 + eval("function t1(a,b) { return a; }; t1(4)")); 1.54 + 1.55 +new TestCase(SECTION, 1.56 + "function t1(a,b) { return a; }; t1();", 1.57 + void 0, 1.58 + eval("function t1(a,b) { return a; }; t1()")); 1.59 + 1.60 +new TestCase(SECTION, 1.61 + "function t1(a,b) { return a; }; t1(1,2,4);", 1.62 + 1, 1.63 + eval("function t1(a,b) { return a; }; t1(1,2,4)")); 1.64 +/* 1.65 + 1.66 +new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );", 1.67 +void 0, 1.68 +eval("function t1(a,a) { return a; }; t1( 4 )")); 1.69 + 1.70 +new TestCase(SECTION, 1.71 +"function t1(a,a) { return a; }; t1( 1,2 );", 1.72 +2, 1.73 +eval("function t1(a,a) { return a; }; t1( 1,2 )")); 1.74 +*/ 1.75 +// variable declarations 1.76 + 1.77 +new TestCase(SECTION, 1.78 + "function t1(a,b) { return a; }; t1( false, true );", 1.79 + false, 1.80 + eval("function t1(a,b) { return a; }; t1( false, true );")); 1.81 + 1.82 +new TestCase(SECTION, 1.83 + "function t1(a,b) { return b; }; t1( false, true );", 1.84 + true, 1.85 + eval("function t1(a,b) { return b; }; t1( false, true );")); 1.86 + 1.87 +new TestCase(SECTION, 1.88 + "function t1(a,b) { return a+b; }; t1( 4, 2 );", 1.89 + 6, 1.90 + eval("function t1(a,b) { return a+b; }; t1( 4, 2 );")); 1.91 + 1.92 +new TestCase(SECTION, 1.93 + "function t1(a,b) { return a+b; }; t1( 4 );", 1.94 + Number.NaN, 1.95 + eval("function t1(a,b) { return a+b; }; t1( 4 );")); 1.96 + 1.97 +// overriding a function name with a variable should fail 1.98 + 1.99 +new TestCase(SECTION, 1.100 + "function t() { return 'function' };" + 1.101 + "var t = 'variable'; typeof(t)", 1.102 + "string", 1.103 + eval("function t() { return 'function' };" + 1.104 + "var t = 'variable'; typeof(t)")); 1.105 + 1.106 +// function as a constructor 1.107 + 1.108 +new TestCase(SECTION, 1.109 + "function t1(a,b) { var a = b; return a; } t1(1,3);", 1.110 + 3, 1.111 + eval("function t1(a, b){ var a = b; return a;}; t1(1,3)")); 1.112 + 1.113 +new TestCase(SECTION, 1.114 + "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a", 1.115 + 3, 1.116 + eval("function t2(a,b) { this.a = b; };" + 1.117 + "x = new t2(1,3); x.a")); 1.118 + 1.119 +new TestCase(SECTION, 1.120 + "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a", 1.121 + 1, 1.122 + eval("function t2(a,b) { this.a = a; };" + 1.123 + "x = new t2(1,3); x.a")); 1.124 + 1.125 +new TestCase(SECTION, 1.126 + "function t2(a,b) { this.a = b; this.b = a; } " + 1.127 + "x = new t2(1,3);x.a;", 1.128 + 3, 1.129 + eval("function t2(a,b) { this.a = b; this.b = a; };" + 1.130 + "x = new t2(1,3);x.a;")); 1.131 + 1.132 +new TestCase(SECTION, 1.133 + "function t2(a,b) { this.a = b; this.b = a; }" + 1.134 + "x = new t2(1,3);x.b;", 1.135 + 1, 1.136 + eval("function t2(a,b) { this.a = b; this.b = a; };" + 1.137 + "x = new t2(1,3);x.b;") ); 1.138 + 1.139 +test();