OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 assertEquals(3, argc0(1, 2, 3)); | 43 assertEquals(3, argc0(1, 2, 3)); |
44 assertEquals(0, argc1()); | 44 assertEquals(0, argc1()); |
45 assertEquals(1, argc1(1)); | 45 assertEquals(1, argc1(1)); |
46 assertEquals(2, argc1(1, 2)); | 46 assertEquals(2, argc1(1, 2)); |
47 assertEquals(3, argc1(1, 2, 3)); | 47 assertEquals(3, argc1(1, 2, 3)); |
48 assertEquals(0, argc2()); | 48 assertEquals(0, argc2()); |
49 assertEquals(1, argc2(1)); | 49 assertEquals(1, argc2(1)); |
50 assertEquals(2, argc2(1, 2)); | 50 assertEquals(2, argc2(1, 2)); |
51 assertEquals(3, argc2(1, 2, 3)); | 51 assertEquals(3, argc2(1, 2, 3)); |
52 | 52 |
53 | |
54 | |
55 var index; | 53 var index; |
56 | 54 |
57 function argv0() { | 55 function argv0() { |
58 return arguments[index]; | 56 return arguments[index]; |
59 } | 57 } |
60 | 58 |
61 function argv1(i) { | 59 function argv1(i) { |
62 return arguments[index]; | 60 return arguments[index]; |
63 } | 61 } |
64 | 62 |
(...skipping 23 matching lines...) Expand all Loading... |
88 index = 2; | 86 index = 2; |
89 assertEquals(9, argv0(7, 8, 9)); | 87 assertEquals(9, argv0(7, 8, 9)); |
90 assertEquals(9, argv1(7, 8, 9)); | 88 assertEquals(9, argv1(7, 8, 9)); |
91 assertEquals(9, argv2(7, 8, 9)); | 89 assertEquals(9, argv2(7, 8, 9)); |
92 | 90 |
93 | 91 |
94 // Test that calling a lazily compiled function with | 92 // Test that calling a lazily compiled function with |
95 // an unexpected number of arguments works. | 93 // an unexpected number of arguments works. |
96 function f(a) { return arguments.length; }; | 94 function f(a) { return arguments.length; }; |
97 assertEquals(3, f(1, 2, 3)); | 95 assertEquals(3, f(1, 2, 3)); |
| 96 |
| 97 function f1(x, y) { |
| 98 function g(a) { |
| 99 a[0] = "three"; |
| 100 return a.length; |
| 101 } |
| 102 var l = g(arguments); |
| 103 y = 5; |
| 104 assertEquals(2, l); |
| 105 assertEquals("three", x); |
| 106 assertEquals(5, y); |
| 107 } |
| 108 f1(3, "five"); |
| 109 |
| 110 |
| 111 function f2() { |
| 112 if (arguments[0] > 0) { |
| 113 return arguments.callee(arguments[0] - 1) + arguments[0]; |
| 114 } |
| 115 return 0; |
| 116 } |
| 117 assertEquals(55, f2(10)); |
| 118 |
| 119 |
| 120 function f3() { |
| 121 assertEquals(0, arguments.length); |
| 122 } |
| 123 f3(); |
| 124 |
| 125 |
| 126 function f4() { |
| 127 var arguments = 0; |
| 128 assertEquals(void 0, arguments.length); |
| 129 } |
| 130 f4(); |
| 131 |
| 132 |
| 133 function f5(x, y, z) { |
| 134 function g(a) { |
| 135 x = "two"; |
| 136 y = "three"; |
| 137 a[1] = "drei"; |
| 138 a[2] = "fuenf"; |
| 139 }; |
| 140 |
| 141 g(arguments); |
| 142 assertEquals("two", x); |
| 143 assertEquals("drei", y); |
| 144 assertEquals("fuenf", z); |
| 145 } |
| 146 f5(2, 3, 5); |
| 147 |
| 148 |
| 149 function f6(x, y) { |
| 150 x = "x"; |
| 151 arguments[1] = "y"; |
| 152 return [arguments.length, arguments[0], y, arguments[2]]; |
| 153 } |
| 154 |
| 155 assertArrayEquals([0, "x", "y", void 0], f6()); |
| 156 assertArrayEquals([1, "x", "y", void 0], f6(1)); |
| 157 assertArrayEquals([2, "x", "y", void 0], f6(9, 17)); |
| 158 assertArrayEquals([3, "x", "y", 7], f6(3, 5, 7)); |
| 159 assertArrayEquals([4, "x", "y", "c"], f6("a", "b", "c", "d")); |
| 160 |
| 161 |
| 162 function list_args(a) { |
| 163 assertEquals("function", typeof a.callee); |
| 164 var result = []; |
| 165 result.push(a.length); |
| 166 for (i = 0; i < a.length; i++) result.push(a[i]); |
| 167 return result; |
| 168 } |
| 169 |
| 170 |
| 171 function f1(x, y) { |
| 172 function g(p) { |
| 173 x = p; |
| 174 } |
| 175 g(y); |
| 176 return list_args(arguments); |
| 177 } |
| 178 |
| 179 assertArrayEquals([0], f1()); |
| 180 assertArrayEquals([1, void 0], f1(3)); |
| 181 assertArrayEquals([2, 5, 5], f1(3, 5)); |
| 182 assertArrayEquals([3, 5, 5, 7], f1(3, 5, 7)); |
OLD | NEW |