2 "This test checks that variable declaration 'var arguments;' doesn't override function's local arguments object."
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
11 // this tests the overriding of arguments in the top-level funcition block
12 function argumentsLength() {
14 shouldBe("'" + typeof arguments
+ "'", "'object'");
15 return arguments
.length
;
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
) {
22 shouldBe("'" + typeof arguments
+ "'", "'object'");
24 return arguments
.length
;
27 function argumentsLengthInnerBlock2() {
29 for (var arguments
; i
> 1; ++i
) {
30 shouldBe("'" + typeof arguments
+ "'", "'object'");
32 return arguments
.length
;
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() {
41 var arguments
= ["foo", "bar"];
44 return arguments
.length
;
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
50 function argumentsLengthWith() {
51 var object
= { 'arguments': ["foo"] };
54 var arguments
= ["foo", "bar"];
57 return arguments
.length
;
60 // this tests that arguments can still be overridden
61 function argumentsLengthOverride() {
62 shouldBe("'" + typeof arguments
+ "'", "'object'");
63 var argslen
= arguments
.length
;
65 var arguments
= [0,1,2,3,5,6,7];
67 shouldBe("'" + typeof arguments
+ "'", "'object'");
68 shouldBe("" + arguments
.length
, "7");
72 function argumentsLengthOverrideInnerBlock() {
73 shouldBe("'" + typeof arguments
+ "'", "'object'");
74 var argslen
= arguments
.length
;
77 for (var arguments
= [0,1,2,3,5,6,7]; i
< 1; ++i
) {
81 shouldBe("" + arguments
.length
, "7");
86 function argumentsLengthOverrideInnerBlock2() {
87 shouldBe("'" + typeof arguments
+ "'", "'object'");
88 var argslen
= arguments
.length
;
90 for (var i
= 0; i
< 1; ++i
) {
91 var arguments
= [0,1,2,3,5,6,7];
95 shouldBe("" + arguments
.length
, "7");
100 function argumentsLengthOverrideInnerBlock3() {
101 shouldBe("'" + typeof arguments
+ "'", "'object'");
102 var argslen
= arguments
.length
;
104 for (var i
= 0; i
< 1; ++i
) {
105 arguments
= [0,1,2,3,5,6,7];
109 shouldBe("" + arguments
.length
, "7");
114 function argumentsTearOff1()
116 return argumentsTearOff2(2);
119 function argumentsTearOff2(b
)
122 var w
= argumentsTearOff1
.arguments
;
123 argumentsTearOff3(3);
127 function argumentsTearOff3(c
)
132 shouldBe("argumentsLength()", "0");
133 shouldBe("argumentsLength(1)", "1");
134 shouldBe("argumentsLength('a','b')", "2");
136 shouldBe("argumentsLengthInnerBlock()", "0");
137 shouldBe("argumentsLengthInnerBlock(1)", "1");
138 shouldBe("argumentsLengthInnerBlock('a','b')", "2");
140 shouldBe("argumentsLengthInnerBlock2()", "0");
141 shouldBe("argumentsLengthInnerBlock2(1)", "1");
142 shouldBe("argumentsLengthInnerBlock2('a','b')", "2");
144 shouldBe("argumentsLengthTryCatch()", "0");
145 shouldBe("argumentsLengthWith()", "0");
147 shouldBe("argumentsLengthOverride()", "0");
148 shouldBe("argumentsLengthOverride(1)", "1");
149 shouldBe("argumentsLengthOverride('a','b')", "2");
151 shouldBe("argumentsLengthOverrideInnerBlock()", "0");
152 shouldBe("argumentsLengthOverrideInnerBlock(1)", "1");
153 shouldBe("argumentsLengthOverrideInnerBlock('a','b')", "2");
155 shouldBe("argumentsLengthOverrideInnerBlock2()", "0");
156 shouldBe("argumentsLengthOverrideInnerBlock2(1)", "1");
157 shouldBe("argumentsLengthOverrideInnerBlock2('a','b')", "2");
159 shouldBe("argumentsLengthOverrideInnerBlock3()", "0");
160 shouldBe("argumentsLengthOverrideInnerBlock3(1)", "1");
161 shouldBe("argumentsLengthOverrideInnerBlock3('a','b')", "2");
163 shouldBe("argumentsTearOff1()", "2");
165 // this tests that behaviour should persists for
166 // the program source elements also
167 shouldBe("typeof undefined", "'undefined'");
168 shouldBe("'" + typeof arguments
+ "'", "'undefined'");
171 shouldBe("typeof arguments", "'object'");
172 shouldBe("'" + typeof arguments
+ "'", "'undefined'");
174 var arguments
= [3,2];
175 shouldBe("'" + typeof arguments
+ "'", "'object'");
176 shouldBe("" + arguments
.length
, "2");