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