| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 array = [1, 2, 3]; | 211 array = [1, 2, 3]; |
| 212 spliced = array.splice({valueOf: function() { return 1; }}, | 212 spliced = array.splice({valueOf: function() { return 1; }}, |
| 213 {toString: function() { return 2; }}, | 213 {toString: function() { return 2; }}, |
| 214 'one', 'two'); | 214 'one', 'two'); |
| 215 assertEquals([2, 3], spliced); | 215 assertEquals([2, 3], spliced); |
| 216 assertEquals([1, 'one', 'two'], array); | 216 assertEquals([1, 'one', 'two'], array); |
| 217 } | 217 } |
| 218 })(); | 218 })(); |
| 219 | 219 |
| 220 | 220 |
| 221 // Check behavior on significant part spliced. |
| 222 (function() { |
| 223 var array, spliced; |
| 224 for (var i = 0; i < 7; i++) { |
| 225 array = [1, 2, 3, 4, 5, 6, 7]; |
| 226 spliced = array.splice(-100, 100, 9); |
| 227 assertEquals([9], array); |
| 228 assertEquals([1, 2, 3, 4, 5, 6, 7], spliced); |
| 229 } |
| 230 |
| 231 for (var i = 0; i < 7; i++) { |
| 232 array = [1, 2, 3, 4, 5, 6, 7]; |
| 233 spliced = array.splice(0, 6, 9); |
| 234 assertEquals([9, 7], array); |
| 235 assertEquals([1, 2, 3, 4, 5, 6], spliced); |
| 236 } |
| 237 |
| 238 for (var i = 0; i < 7; i++) { |
| 239 array = [1, 2, 3, 4, 5, 6, 7]; |
| 240 spliced = array.splice(1, 5, 9); |
| 241 assertEquals([1, 9, 7], array); |
| 242 assertEquals([2, 3, 4, 5, 6], spliced); |
| 243 } |
| 244 |
| 245 for (var i = 0; i < 7; i++) { |
| 246 array = [1, 2, 3, 4, 5, 6, 7]; |
| 247 spliced = array.splice(1, 100, 9); |
| 248 assertEquals([1, 9], array); |
| 249 assertEquals([2, 3, 4, 5, 6, 7], spliced); |
| 250 } |
| 251 |
| 252 })(); |
| 253 |
| 254 |
| 221 // Nasty: modify the array in ToInteger. | 255 // Nasty: modify the array in ToInteger. |
| 222 (function() { | 256 (function() { |
| 223 var array = []; | 257 var array = []; |
| 224 var spliced; | 258 var spliced; |
| 225 | 259 |
| 226 for (var i = 0; i < 13; i++) { | 260 for (var i = 0; i < 13; i++) { |
| 227 bad_start = { valueOf: function() { array.push(2*i); return -1; } }; | 261 bad_start = { valueOf: function() { array.push(2*i); return -1; } }; |
| 228 bad_count = { valueOf: function() { array.push(2*i + 1); return 1; } }; | 262 bad_count = { valueOf: function() { array.push(2*i + 1); return 1; } }; |
| 229 spliced = array.splice(bad_start, bad_count); | 263 spliced = array.splice(bad_start, bad_count); |
| 230 // According to the spec (15.4.4.12), length is calculated before | 264 // According to the spec (15.4.4.12), length is calculated before |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 345 |
| 312 (function() { | 346 (function() { |
| 313 for (var i = 0; i < 7; i++) { | 347 for (var i = 0; i < 7; i++) { |
| 314 var a = [7, 8, 9]; | 348 var a = [7, 8, 9]; |
| 315 a.splice(0, 0, 1, 2, 3, 4, 5, 6); | 349 a.splice(0, 0, 1, 2, 3, 4, 5, 6); |
| 316 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); | 350 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); |
| 317 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); | 351 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); |
| 318 assertEquals(undefined, a[10]); | 352 assertEquals(undefined, a[10]); |
| 319 } | 353 } |
| 320 })(); | 354 })(); |
| OLD | NEW |