OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // Check variants of negatives and positive indices. | 109 // Check variants of negatives and positive indices. |
110 (function() { | 110 (function() { |
111 var array, spliced; | 111 var array, spliced; |
112 for (var i = 0; i < 7; i++) { | 112 for (var i = 0; i < 7; i++) { |
113 array = [1, 2, 3, 4, 5, 6, 7]; | 113 array = [1, 2, 3, 4, 5, 6, 7]; |
114 spliced = array.splice(-100); | 114 spliced = array.splice(-100); |
115 assertEquals([], array); | 115 assertEquals([], array); |
116 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); | 116 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); |
117 | 117 |
118 array = [1, 2, 3, 4, 5, 6, 7]; | 118 array = [1, 2, 3, 4, 5, 6, 7]; |
| 119 spliced = array.splice(-1e100); |
| 120 assertEquals([], array); |
| 121 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); |
| 122 |
| 123 array = [1, 2, 3, 4, 5, 6, 7]; |
119 spliced = array.splice(-3); | 124 spliced = array.splice(-3); |
120 assertEquals([1, 2, 3, 4], array); | 125 assertEquals([1, 2, 3, 4], array); |
121 assertEquals([5, 6, 7], spliced); | 126 assertEquals([5, 6, 7], spliced); |
122 | 127 |
123 array = [1, 2, 3, 4, 5, 6, 7]; | 128 array = [1, 2, 3, 4, 5, 6, 7]; |
124 spliced = array.splice(4); | 129 spliced = array.splice(4); |
125 assertEquals([1, 2, 3, 4], array); | 130 assertEquals([1, 2, 3, 4], array); |
126 assertEquals([5, 6, 7], spliced); | 131 assertEquals([5, 6, 7], spliced); |
127 | 132 |
128 array = [1, 2, 3, 4, 5, 6, 7]; | 133 array = [1, 2, 3, 4, 5, 6, 7]; |
(...skipping 10 matching lines...) Expand all Loading... |
139 spliced = array.splice(8); | 144 spliced = array.splice(8); |
140 assertEquals([1, 2, 3, 4, 5, 6, 7], array); | 145 assertEquals([1, 2, 3, 4, 5, 6, 7], array); |
141 assertEquals([], spliced); | 146 assertEquals([], spliced); |
142 | 147 |
143 array = [1, 2, 3, 4, 5, 6, 7]; | 148 array = [1, 2, 3, 4, 5, 6, 7]; |
144 spliced = array.splice(100); | 149 spliced = array.splice(100); |
145 assertEquals([1, 2, 3, 4, 5, 6, 7], array); | 150 assertEquals([1, 2, 3, 4, 5, 6, 7], array); |
146 assertEquals([], spliced); | 151 assertEquals([], spliced); |
147 | 152 |
148 array = [1, 2, 3, 4, 5, 6, 7]; | 153 array = [1, 2, 3, 4, 5, 6, 7]; |
| 154 spliced = array.splice(1e100); |
| 155 assertEquals([1, 2, 3, 4, 5, 6, 7], array); |
| 156 assertEquals([], spliced); |
| 157 |
| 158 array = [1, 2, 3, 4, 5, 6, 7]; |
149 spliced = array.splice(0, -100); | 159 spliced = array.splice(0, -100); |
150 assertEquals([1, 2, 3, 4, 5, 6, 7], array); | 160 assertEquals([1, 2, 3, 4, 5, 6, 7], array); |
151 assertEquals([], spliced); | 161 assertEquals([], spliced); |
152 | 162 |
153 array = [1, 2, 3, 4, 5, 6, 7]; | 163 array = [1, 2, 3, 4, 5, 6, 7]; |
| 164 spliced = array.splice(0, -1e100); |
| 165 assertEquals([1, 2, 3, 4, 5, 6, 7], array); |
| 166 assertEquals([], spliced); |
| 167 |
| 168 array = [1, 2, 3, 4, 5, 6, 7]; |
154 spliced = array.splice(0, -3); | 169 spliced = array.splice(0, -3); |
155 assertEquals([1, 2, 3, 4, 5, 6, 7], array); | 170 assertEquals([1, 2, 3, 4, 5, 6, 7], array); |
156 assertEquals([], spliced); | 171 assertEquals([], spliced); |
157 | 172 |
158 array = [1, 2, 3, 4, 5, 6, 7]; | 173 array = [1, 2, 3, 4, 5, 6, 7]; |
159 spliced = array.splice(0, 4); | 174 spliced = array.splice(0, 4); |
160 assertEquals([5, 6, 7], array); | 175 assertEquals([5, 6, 7], array); |
161 assertEquals([1, 2, 3, 4], spliced); | 176 assertEquals([1, 2, 3, 4], spliced); |
162 | 177 |
163 array = [1, 2, 3, 4, 5, 6, 7]; | 178 array = [1, 2, 3, 4, 5, 6, 7]; |
164 spliced = array.splice(0, 6); | 179 spliced = array.splice(0, 6); |
165 assertEquals([7], array); | 180 assertEquals([7], array); |
166 assertEquals([1, 2, 3, 4, 5, 6], spliced); | 181 assertEquals([1, 2, 3, 4, 5, 6], spliced); |
167 | 182 |
168 array = [1, 2, 3, 4, 5, 6, 7]; | 183 array = [1, 2, 3, 4, 5, 6, 7]; |
169 spliced = array.splice(0, 7); | 184 spliced = array.splice(0, 7); |
170 assertEquals([], array); | 185 assertEquals([], array); |
171 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); | 186 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); |
172 | 187 |
173 array = [1, 2, 3, 4, 5, 6, 7]; | 188 array = [1, 2, 3, 4, 5, 6, 7]; |
174 spliced = array.splice(0, 8); | 189 spliced = array.splice(0, 8); |
175 assertEquals([], array); | 190 assertEquals([], array); |
176 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); | 191 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); |
177 | 192 |
178 array = [1, 2, 3, 4, 5, 6, 7]; | 193 array = [1, 2, 3, 4, 5, 6, 7]; |
179 spliced = array.splice(0, 100); | 194 spliced = array.splice(0, 100); |
180 assertEquals([], array); | 195 assertEquals([], array); |
181 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); | 196 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); |
182 | 197 |
| 198 array = [1, 2, 3, 4, 5, 6, 7]; |
| 199 spliced = array.splice(0, 1e100); |
| 200 assertEquals([], array); |
| 201 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); |
| 202 |
183 // Some exotic cases. | 203 // Some exotic cases. |
184 obj = { toString: function() { throw 'Exception'; } }; | 204 obj = { toString: function() { throw 'Exception'; } }; |
185 | 205 |
186 // Throwing an exception in conversion: | 206 // Throwing an exception in conversion: |
187 try { | 207 try { |
188 [1, 2, 3].splice(obj, 3); | 208 [1, 2, 3].splice(obj, 3); |
189 throw 'Should have thrown'; | 209 throw 'Should have thrown'; |
190 } catch (e) { | 210 } catch (e) { |
191 assertEquals('Exception', e); | 211 assertEquals('Exception', e); |
192 } | 212 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 393 |
374 (function() { | 394 (function() { |
375 for (var i = 0; i < 7; i++) { | 395 for (var i = 0; i < 7; i++) { |
376 var a = [7, 8, 9]; | 396 var a = [7, 8, 9]; |
377 a.splice(0, 0, 1, 2, 3, 4, 5, 6); | 397 a.splice(0, 0, 1, 2, 3, 4, 5, 6); |
378 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); | 398 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); |
379 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); | 399 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); |
380 assertEquals(undefined, a[10]); | 400 assertEquals(undefined, a[10]); |
381 } | 401 } |
382 })(); | 402 })(); |
OLD | NEW |