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