tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / js / script-tests / vardecl-preserve-arguments.js
1 description(
2 "This test checks that variable declaration 'var arguments;' doesn't override function's local arguments object."
3 );
4
5 // this test needs to use shouldBe() a bit wrong, since passing the string that
6 // would evaluate the actual expression (like "typeof arguments" instead of
7 // "'" + typeof arguments + "'" would use the arguments property that would possibly
8 // be set by the eval function. We want to test the arguments object that is in
9 // the current scope
10
11 // this tests the overriding of arguments in the top-level funcition block
12 function argumentsLength() {
13   var arguments;
14   shouldBe("'" + typeof arguments + "'", "'object'");
15   return arguments.length;
16 }
17
18 // this tests the overriding of arguments in a block statement inside function block
19 function argumentsLengthInnerBlock() {
20   for (var i=0; i < 1; ++i) {
21     var arguments;
22     shouldBe("'" + typeof arguments + "'", "'object'");
23   }
24   return arguments.length;
25 }
26
27 function argumentsLengthInnerBlock2() {
28   var i = 0;
29   for (var arguments; i > 1; ++i) {
30     shouldBe("'" + typeof arguments + "'", "'object'");
31   }
32   return arguments.length;
33 }
34
35 // this tests that arguments doesn't get overriden by a variable declaration
36 // with an initializer in a catch block with a parameter of the same name
37 function argumentsLengthTryCatch() {
38   try {
39     throw ["foo"];
40   } catch (arguments) {
41     var arguments = ["foo", "bar"];
42   }
43
44   return arguments.length;
45 }
46
47 // this tests that arguments doesn't get overriden by a variable declaration
48 // with an initializer in a with block where the parameter has a property of
49 // same name
50 function argumentsLengthWith() {
51   var object = { 'arguments': ["foo"] };
52
53   with (object) {
54     var arguments = ["foo", "bar"];
55   }
56
57   return arguments.length;
58 }
59
60 // this tests that arguments can still be overridden
61 function argumentsLengthOverride() {
62   shouldBe("'" + typeof arguments + "'", "'object'");
63   var argslen = arguments.length;
64
65   var arguments = [0,1,2,3,5,6,7];
66
67   shouldBe("'" + typeof arguments + "'", "'object'");
68   shouldBe("" + arguments.length, "7");
69   return argslen;
70 }
71
72 function argumentsLengthOverrideInnerBlock() {
73   shouldBe("'" + typeof arguments + "'", "'object'");
74   var argslen = arguments.length;
75
76   var i = 0;
77   for (var arguments = [0,1,2,3,5,6,7]; i < 1; ++i) {
78       // empty
79   }
80
81   shouldBe("" + arguments.length, "7");
82
83   return argslen;
84 }
85
86 function argumentsLengthOverrideInnerBlock2() {
87   shouldBe("'" + typeof arguments + "'", "'object'");
88   var argslen = arguments.length;
89
90   for (var i = 0; i < 1; ++i) {
91       var arguments = [0,1,2,3,5,6,7];
92       // empty
93   }
94
95   shouldBe("" + arguments.length, "7");
96
97   return argslen;
98 }
99
100 function argumentsLengthOverrideInnerBlock3() {
101   shouldBe("'" + typeof arguments + "'", "'object'");
102   var argslen = arguments.length;
103   var arguments;
104   for (var i = 0; i < 1; ++i) {
105       arguments = [0,1,2,3,5,6,7];
106       // empty
107   }
108
109   shouldBe("" + arguments.length, "7");
110
111   return argslen;
112 }
113
114 function argumentsTearOff1()
115 {
116     return argumentsTearOff2(2);
117 }
118
119 function argumentsTearOff2(b)
120 {
121     var v = b;
122     var w = argumentsTearOff1.arguments;
123     argumentsTearOff3(3);
124     return v;
125 }
126
127 function argumentsTearOff3(c)
128 {
129     var v = c;
130 }
131
132 shouldBe("argumentsLength()", "0");
133 shouldBe("argumentsLength(1)", "1");
134 shouldBe("argumentsLength('a','b')", "2");
135
136 shouldBe("argumentsLengthInnerBlock()", "0");
137 shouldBe("argumentsLengthInnerBlock(1)", "1");
138 shouldBe("argumentsLengthInnerBlock('a','b')", "2");
139
140 shouldBe("argumentsLengthInnerBlock2()", "0");
141 shouldBe("argumentsLengthInnerBlock2(1)", "1");
142 shouldBe("argumentsLengthInnerBlock2('a','b')", "2");
143
144 shouldBe("argumentsLengthTryCatch()", "0");
145 shouldBe("argumentsLengthWith()", "0");
146
147 shouldBe("argumentsLengthOverride()", "0");
148 shouldBe("argumentsLengthOverride(1)", "1");
149 shouldBe("argumentsLengthOverride('a','b')", "2");
150
151 shouldBe("argumentsLengthOverrideInnerBlock()", "0");
152 shouldBe("argumentsLengthOverrideInnerBlock(1)", "1");
153 shouldBe("argumentsLengthOverrideInnerBlock('a','b')", "2");
154
155 shouldBe("argumentsLengthOverrideInnerBlock2()", "0");
156 shouldBe("argumentsLengthOverrideInnerBlock2(1)", "1");
157 shouldBe("argumentsLengthOverrideInnerBlock2('a','b')", "2");
158
159 shouldBe("argumentsLengthOverrideInnerBlock3()", "0");
160 shouldBe("argumentsLengthOverrideInnerBlock3(1)", "1");
161 shouldBe("argumentsLengthOverrideInnerBlock3('a','b')", "2");
162
163 shouldBe("argumentsTearOff1()", "2");
164
165 // this tests that behaviour should persists for
166 // the program source elements also
167 shouldBe("typeof undefined", "'undefined'");
168 shouldBe("'" + typeof arguments + "'", "'undefined'");
169
170 var arguments;
171 shouldBe("typeof arguments", "'object'");
172 shouldBe("'" + typeof arguments + "'", "'undefined'");
173
174 var arguments = [3,2];
175 shouldBe("'" + typeof arguments + "'", "'object'");
176 shouldBe("" + arguments.length, "2");