Debian Codegraph @

rhino/testsrc/tests/ecma/ExecutionContexts/10.1.3.js

raw symbols SCIP
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 gTestfile = '10.1.3.js';
7
8 /**
9 File Name: 10.1.3.js
10 ECMA Section: 10.1.3.js Variable Instantiation
11 Description:
12 Author: [email protected]
13 Date: 11 september 1997
14 */
15
16 var SECTION = "10.1.3";
17 var VERSION = "ECMA_1";
18 var TITLE = "Variable instantiation";
19 var BUGNUMBER = "20256";
20 startTest();
21
22 writeHeaderToLog( SECTION + " "+ TITLE);
23
24
25 // overriding a variable or function name with a function should succeed
26
27 new TestCase(SECTION,
28 "function t() { return \"first\" };" +
29 "function t() { return \"second\" };t() ",
30 "second",
31 eval("function t() { return \"first\" };" +
32 "function t() { return \"second\" };t()"));
33
34
35 new TestCase(SECTION,
36 "var t; function t(){}; typeof(t)",
37 "function",
38 eval("var t; function t(){}; typeof(t)"));
39
40
41 // formal parameter tests
42
43 new TestCase(SECTION,
44 "function t1(a,b) { return b; }; t1( 4 );",
45 void 0,
46 eval("function t1(a,b) { return b; }; t1( 4 );") );
47
48 new TestCase(SECTION,
49 "function t1(a,b) { return a; }; t1(4);",
50 4,
51 eval("function t1(a,b) { return a; }; t1(4)"));
52
53 new TestCase(SECTION,
54 "function t1(a,b) { return a; }; t1();",
55 void 0,
56 eval("function t1(a,b) { return a; }; t1()"));
57
58 new TestCase(SECTION,
59 "function t1(a,b) { return a; }; t1(1,2,4);",
60 1,
61 eval("function t1(a,b) { return a; }; t1(1,2,4)"));
62 /*
63
64 new TestCase(SECTION, "function t1(a,a) { return a; }; t1( 4 );",
65 void 0,
66 eval("function t1(a,a) { return a; }; t1( 4 )"));
67
68 new TestCase(SECTION,
69 "function t1(a,a) { return a; }; t1( 1,2 );",
70 2,
71 eval("function t1(a,a) { return a; }; t1( 1,2 )"));
72 */
73 // variable declarations
74
75 new TestCase(SECTION,
76 "function t1(a,b) { return a; }; t1( false, true );",
77 false,
78 eval("function t1(a,b) { return a; }; t1( false, true );"));
79
80 new TestCase(SECTION,
81 "function t1(a,b) { return b; }; t1( false, true );",
82 true,
83 eval("function t1(a,b) { return b; }; t1( false, true );"));
84
85 new TestCase(SECTION,
86 "function t1(a,b) { return a+b; }; t1( 4, 2 );",
87 6,
88 eval("function t1(a,b) { return a+b; }; t1( 4, 2 );"));
89
90 new TestCase(SECTION,
91 "function t1(a,b) { return a+b; }; t1( 4 );",
92 Number.NaN,
93 eval("function t1(a,b) { return a+b; }; t1( 4 );"));
94
95 // overriding a function name with a variable should fail
96
97 new TestCase(SECTION,
98 "function t() { return 'function' };" +
99 "var t = 'variable'; typeof(t)",
100 "string",
101 eval("function t() { return 'function' };" +
102 "var t = 'variable'; typeof(t)"));
103
104 // function as a constructor
105
106 new TestCase(SECTION,
107 "function t1(a,b) { var a = b; return a; } t1(1,3);",
108 3,
109 eval("function t1(a, b){ var a = b; return a;}; t1(1,3)"));
110
111 new TestCase(SECTION,
112 "function t2(a,b) { this.a = b; } x = new t2(1,3); x.a",
113 3,
114 eval("function t2(a,b) { this.a = b; };" +
115 "x = new t2(1,3); x.a"));
116
117 new TestCase(SECTION,
118 "function t2(a,b) { this.a = a; } x = new t2(1,3); x.a",
119 1,
120 eval("function t2(a,b) { this.a = a; };" +
121 "x = new t2(1,3); x.a"));
122
123 new TestCase(SECTION,
124 "function t2(a,b) { this.a = b; this.b = a; } " +
125 "x = new t2(1,3);x.a;",
126 3,
127 eval("function t2(a,b) { this.a = b; this.b = a; };" +
128 "x = new t2(1,3);x.a;"));
129
130 new TestCase(SECTION,
131 "function t2(a,b) { this.a = b; this.b = a; }" +
132 "x = new t2(1,3);x.b;",
133 1,
134 eval("function t2(a,b) { this.a = b; this.b = a; };" +
135 "x = new t2(1,3);x.b;") );
136
137 test();