Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / script-tests / vardecl-preserve-arguments.js
blob239cb725d93a69dc076a5edf5ad8a88fd57b00b6
1 description(
2 "This test checks that variable declaration 'var arguments;' doesn't override function's local arguments object."
3 );
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
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;
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'");
24 return arguments.length;
27 function argumentsLengthInnerBlock2() {
28 var i = 0;
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() {
38 try {
39 throw ["foo"];
40 } catch (arguments) {
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
49 // same name
50 function argumentsLengthWith() {
51 var object = { 'arguments': ["foo"] };
53 with (object) {
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");
69 return argslen;
72 function argumentsLengthOverrideInnerBlock() {
73 shouldBe("'" + typeof arguments + "'", "'object'");
74 var argslen = arguments.length;
76 var i = 0;
77 for (var arguments = [0,1,2,3,5,6,7]; i < 1; ++i) {
78 // empty
81 shouldBe("" + arguments.length, "7");
83 return argslen;
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];
92 // empty
95 shouldBe("" + arguments.length, "7");
97 return argslen;
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
109 shouldBe("" + arguments.length, "7");
111 return argslen;
114 function argumentsTearOff1()
116 return argumentsTearOff2(2);
119 function argumentsTearOff2(b)
121 var v = b;
122 var w = argumentsTearOff1.arguments;
123 argumentsTearOff3(3);
124 return v;
127 function argumentsTearOff3(c)
129 var v = 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'");
170 var arguments;
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");