js/src/tests/ecma/ExecutionContexts/10.1.3.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:15d2f0655284
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
7 /**
8 File Name: 10.1.3.js
9 ECMA Section: 10.1.3.js Variable Instantiation
10 Description:
11 Author: christine@netscape.com
12 Date: 11 september 1997
13 */
14
15 var SECTION = "10.1.3";
16 var VERSION = "ECMA_1";
17 var TITLE = "Variable instantiation";
18 var BUGNUMBER = "20256";
19 startTest();
20
21 writeHeaderToLog( SECTION + " "+ TITLE);
22
23
24 // overriding a variable or function name with a function should succeed
25
26 new TestCase(SECTION,
27 "function t() { return \"first\" };" +
28 "function t() { return \"second\" };t() ",
29 "second",
30 eval("function t() { return \"first\" };" +
31 "function t() { return \"second\" };t()"));
32
33
34 new TestCase(SECTION,
35 "var t; function t(){}; typeof(t)",
36 "function",
37 eval("var t; function t(){}; typeof(t)"));
38
39
40 // formal parameter tests
41
42 new TestCase(SECTION,
43 "function t1(a,b) { return b; }; t1( 4 );",
44 void 0,
45 eval("function t1(a,b) { return b; }; t1( 4 );") );
46
47 new TestCase(SECTION,
48 "function t1(a,b) { return a; }; t1(4);",
49 4,
50 eval("function t1(a,b) { return a; }; t1(4)"));
51
52 new TestCase(SECTION,
53 "function t1(a,b) { return a; }; t1();",
54 void 0,
55 eval("function t1(a,b) { return a; }; t1()"));
56
57 new TestCase(SECTION,
58 "function t1(a,b) { return a; }; t1(1,2,4);",
59 1,
60 eval("function t1(a,b) { return a; }; t1(1,2,4)"));
61 /*
62
63 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );",
64 void 0,
65 eval("function t1(a,a) { return a; }; t1( 4 )"));
66
67 new TestCase(SECTION,
68 "function t1(a,a) { return a; }; t1( 1,2 );",
69 2,
70 eval("function t1(a,a) { return a; }; t1( 1,2 )"));
71 */
72 // variable declarations
73
74 new TestCase(SECTION,
75 "function t1(a,b) { return a; }; t1( false, true );",
76 false,
77 eval("function t1(a,b) { return a; }; t1( false, true );"));
78
79 new TestCase(SECTION,
80 "function t1(a,b) { return b; }; t1( false, true );",
81 true,
82 eval("function t1(a,b) { return b; }; t1( false, true );"));
83
84 new TestCase(SECTION,
85 "function t1(a,b) { return a+b; }; t1( 4, 2 );",
86 6,
87 eval("function t1(a,b) { return a+b; }; t1( 4, 2 );"));
88
89 new TestCase(SECTION,
90 "function t1(a,b) { return a+b; }; t1( 4 );",
91 Number.NaN,
92 eval("function t1(a,b) { return a+b; }; t1( 4 );"));
93
94 // overriding a function name with a variable should fail
95
96 new TestCase(SECTION,
97 "function t() { return 'function' };" +
98 "var t = 'variable'; typeof(t)",
99 "string",
100 eval("function t() { return 'function' };" +
101 "var t = 'variable'; typeof(t)"));
102
103 // function as a constructor
104
105 new TestCase(SECTION,
106 "function t1(a,b) { var a = b; return a; } t1(1,3);",
107 3,
108 eval("function t1(a, b){ var a = b; return a;}; t1(1,3)"));
109
110 new TestCase(SECTION,
111 "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a",
112 3,
113 eval("function t2(a,b) { this.a = b; };" +
114 "x = new t2(1,3); x.a"));
115
116 new TestCase(SECTION,
117 "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a",
118 1,
119 eval("function t2(a,b) { this.a = a; };" +
120 "x = new t2(1,3); x.a"));
121
122 new TestCase(SECTION,
123 "function t2(a,b) { this.a = b; this.b = a; } " +
124 "x = new t2(1,3);x.a;",
125 3,
126 eval("function t2(a,b) { this.a = b; this.b = a; };" +
127 "x = new t2(1,3);x.a;"));
128
129 new TestCase(SECTION,
130 "function t2(a,b) { this.a = b; this.b = a; }" +
131 "x = new t2(1,3);x.b;",
132 1,
133 eval("function t2(a,b) { this.a = b; this.b = a; };" +
134 "x = new t2(1,3);x.b;") );
135
136 test();

mercurial