| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 for (var k = 0; k < length; k++) { | 226 for (var k = 0; k < length; k++) { |
| 227 var key = intervals[k]; | 227 var key = intervals[k]; |
| 228 if (key < 0) { | 228 if (key < 0) { |
| 229 var j = -1 - key; | 229 var j = -1 - key; |
| 230 var interval_limit = j + intervals[++k]; | 230 var interval_limit = j + intervals[++k]; |
| 231 if (j < start_i) { | 231 if (j < start_i) { |
| 232 j = start_i; | 232 j = start_i; |
| 233 } | 233 } |
| 234 for (; j < interval_limit; j++) { | 234 for (; j < interval_limit; j++) { |
| 235 // ECMA-262 15.4.4.12 line 10. The spec could also be | 235 // ECMA-262 15.4.4.12 line 10. The spec could also be |
| 236 // interpreted such that %HasLocalProperty would be the | 236 // interpreted such that %HasOwnProperty would be the |
| 237 // appropriate test. We follow KJS in consulting the | 237 // appropriate test. We follow KJS in consulting the |
| 238 // prototype. | 238 // prototype. |
| 239 var current = array[j]; | 239 var current = array[j]; |
| 240 if (!IS_UNDEFINED(current) || j in array) { | 240 if (!IS_UNDEFINED(current) || j in array) { |
| 241 deleted_elements[j - start_i] = current; | 241 deleted_elements[j - start_i] = current; |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 } else { | 244 } else { |
| 245 if (!IS_UNDEFINED(key)) { | 245 if (!IS_UNDEFINED(key)) { |
| 246 if (key >= start_i) { | 246 if (key >= start_i) { |
| 247 // ECMA-262 15.4.4.12 line 10. The spec could also be | 247 // ECMA-262 15.4.4.12 line 10. The spec could also be |
| 248 // interpreted such that %HasLocalProperty would be the | 248 // interpreted such that %HasOwnProperty would be the |
| 249 // appropriate test. We follow KJS in consulting the | 249 // appropriate test. We follow KJS in consulting the |
| 250 // prototype. | 250 // prototype. |
| 251 var current = array[key]; | 251 var current = array[key]; |
| 252 if (!IS_UNDEFINED(current) || key in array) { | 252 if (!IS_UNDEFINED(current) || key in array) { |
| 253 deleted_elements[key - start_i] = current; | 253 deleted_elements[key - start_i] = current; |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 | 261 |
| 262 // This function implements the optimized splice implementation that can use | 262 // This function implements the optimized splice implementation that can use |
| 263 // special array operations to handle sparse arrays in a sensible fashion. | 263 // special array operations to handle sparse arrays in a sensible fashion. |
| 264 function SmartMove(array, start_i, del_count, len, num_additional_args) { | 264 function SmartMove(array, start_i, del_count, len, num_additional_args) { |
| 265 // Move data to new array. | 265 // Move data to new array. |
| 266 var new_array = new InternalArray(len - del_count + num_additional_args); | 266 var new_array = new InternalArray(len - del_count + num_additional_args); |
| 267 var intervals = %GetArrayKeys(array, len); | 267 var intervals = %GetArrayKeys(array, len); |
| 268 var length = intervals.length; | 268 var length = intervals.length; |
| 269 for (var k = 0; k < length; k++) { | 269 for (var k = 0; k < length; k++) { |
| 270 var key = intervals[k]; | 270 var key = intervals[k]; |
| 271 if (key < 0) { | 271 if (key < 0) { |
| 272 var j = -1 - key; | 272 var j = -1 - key; |
| 273 var interval_limit = j + intervals[++k]; | 273 var interval_limit = j + intervals[++k]; |
| 274 while (j < start_i && j < interval_limit) { | 274 while (j < start_i && j < interval_limit) { |
| 275 // The spec could also be interpreted such that | 275 // The spec could also be interpreted such that |
| 276 // %HasLocalProperty would be the appropriate test. We follow | 276 // %HasOwnProperty would be the appropriate test. We follow |
| 277 // KJS in consulting the prototype. | 277 // KJS in consulting the prototype. |
| 278 var current = array[j]; | 278 var current = array[j]; |
| 279 if (!IS_UNDEFINED(current) || j in array) { | 279 if (!IS_UNDEFINED(current) || j in array) { |
| 280 new_array[j] = current; | 280 new_array[j] = current; |
| 281 } | 281 } |
| 282 j++; | 282 j++; |
| 283 } | 283 } |
| 284 j = start_i + del_count; | 284 j = start_i + del_count; |
| 285 while (j < interval_limit) { | 285 while (j < interval_limit) { |
| 286 // ECMA-262 15.4.4.12 lines 24 and 41. The spec could also be | 286 // ECMA-262 15.4.4.12 lines 24 and 41. The spec could also be |
| 287 // interpreted such that %HasLocalProperty would be the | 287 // interpreted such that %HasOwnProperty would be the |
| 288 // appropriate test. We follow KJS in consulting the | 288 // appropriate test. We follow KJS in consulting the |
| 289 // prototype. | 289 // prototype. |
| 290 var current = array[j]; | 290 var current = array[j]; |
| 291 if (!IS_UNDEFINED(current) || j in array) { | 291 if (!IS_UNDEFINED(current) || j in array) { |
| 292 new_array[j - del_count + num_additional_args] = current; | 292 new_array[j - del_count + num_additional_args] = current; |
| 293 } | 293 } |
| 294 j++; | 294 j++; |
| 295 } | 295 } |
| 296 } else { | 296 } else { |
| 297 if (!IS_UNDEFINED(key)) { | 297 if (!IS_UNDEFINED(key)) { |
| 298 if (key < start_i) { | 298 if (key < start_i) { |
| 299 // The spec could also be interpreted such that | 299 // The spec could also be interpreted such that |
| 300 // %HasLocalProperty would be the appropriate test. We follow | 300 // %HasOwnProperty would be the appropriate test. We follow |
| 301 // KJS in consulting the prototype. | 301 // KJS in consulting the prototype. |
| 302 var current = array[key]; | 302 var current = array[key]; |
| 303 if (!IS_UNDEFINED(current) || key in array) { | 303 if (!IS_UNDEFINED(current) || key in array) { |
| 304 new_array[key] = current; | 304 new_array[key] = current; |
| 305 } | 305 } |
| 306 } else if (key >= start_i + del_count) { | 306 } else if (key >= start_i + del_count) { |
| 307 // ECMA-262 15.4.4.12 lines 24 and 41. The spec could also | 307 // ECMA-262 15.4.4.12 lines 24 and 41. The spec could also |
| 308 // be interpreted such that %HasLocalProperty would be the | 308 // be interpreted such that %HasOwnProperty would be the |
| 309 // appropriate test. We follow KJS in consulting the | 309 // appropriate test. We follow KJS in consulting the |
| 310 // prototype. | 310 // prototype. |
| 311 var current = array[key]; | 311 var current = array[key]; |
| 312 if (!IS_UNDEFINED(current) || key in array) { | 312 if (!IS_UNDEFINED(current) || key in array) { |
| 313 new_array[key - del_count + num_additional_args] = current; | 313 new_array[key - del_count + num_additional_args] = current; |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 // Move contents of new_array into this array | 319 // Move contents of new_array into this array |
| 320 %MoveArrayContents(new_array, array); | 320 %MoveArrayContents(new_array, array); |
| 321 } | 321 } |
| 322 | 322 |
| 323 | 323 |
| 324 // This is part of the old simple-minded splice. We are using it either | 324 // This is part of the old simple-minded splice. We are using it either |
| 325 // because the receiver is not an array (so we have no choice) or because we | 325 // because the receiver is not an array (so we have no choice) or because we |
| 326 // know we are not deleting or moving a lot of elements. | 326 // know we are not deleting or moving a lot of elements. |
| 327 function SimpleSlice(array, start_i, del_count, len, deleted_elements) { | 327 function SimpleSlice(array, start_i, del_count, len, deleted_elements) { |
| 328 for (var i = 0; i < del_count; i++) { | 328 for (var i = 0; i < del_count; i++) { |
| 329 var index = start_i + i; | 329 var index = start_i + i; |
| 330 // The spec could also be interpreted such that %HasLocalProperty | 330 // The spec could also be interpreted such that %HasOwnProperty |
| 331 // would be the appropriate test. We follow KJS in consulting the | 331 // would be the appropriate test. We follow KJS in consulting the |
| 332 // prototype. | 332 // prototype. |
| 333 var current = array[index]; | 333 var current = array[index]; |
| 334 if (!IS_UNDEFINED(current) || index in array) | 334 if (!IS_UNDEFINED(current) || index in array) |
| 335 deleted_elements[i] = current; | 335 deleted_elements[i] = current; |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 | 339 |
| 340 function SimpleMove(array, start_i, del_count, len, num_additional_args) { | 340 function SimpleMove(array, start_i, del_count, len, num_additional_args) { |
| 341 if (num_additional_args !== del_count) { | 341 if (num_additional_args !== del_count) { |
| 342 // Move the existing elements after the elements to be deleted | 342 // Move the existing elements after the elements to be deleted |
| 343 // to the right position in the resulting array. | 343 // to the right position in the resulting array. |
| 344 if (num_additional_args > del_count) { | 344 if (num_additional_args > del_count) { |
| 345 for (var i = len - del_count; i > start_i; i--) { | 345 for (var i = len - del_count; i > start_i; i--) { |
| 346 var from_index = i + del_count - 1; | 346 var from_index = i + del_count - 1; |
| 347 var to_index = i + num_additional_args - 1; | 347 var to_index = i + num_additional_args - 1; |
| 348 // The spec could also be interpreted such that | 348 // The spec could also be interpreted such that |
| 349 // %HasLocalProperty would be the appropriate test. We follow | 349 // %HasOwnProperty would be the appropriate test. We follow |
| 350 // KJS in consulting the prototype. | 350 // KJS in consulting the prototype. |
| 351 var current = array[from_index]; | 351 var current = array[from_index]; |
| 352 if (!IS_UNDEFINED(current) || from_index in array) { | 352 if (!IS_UNDEFINED(current) || from_index in array) { |
| 353 array[to_index] = current; | 353 array[to_index] = current; |
| 354 } else { | 354 } else { |
| 355 delete array[to_index]; | 355 delete array[to_index]; |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 } else { | 358 } else { |
| 359 for (var i = start_i; i < len - del_count; i++) { | 359 for (var i = start_i; i < len - del_count; i++) { |
| 360 var from_index = i + del_count; | 360 var from_index = i + del_count; |
| 361 var to_index = i + num_additional_args; | 361 var to_index = i + num_additional_args; |
| 362 // The spec could also be interpreted such that | 362 // The spec could also be interpreted such that |
| 363 // %HasLocalProperty would be the appropriate test. We follow | 363 // %HasOwnProperty would be the appropriate test. We follow |
| 364 // KJS in consulting the prototype. | 364 // KJS in consulting the prototype. |
| 365 var current = array[from_index]; | 365 var current = array[from_index]; |
| 366 if (!IS_UNDEFINED(current) || from_index in array) { | 366 if (!IS_UNDEFINED(current) || from_index in array) { |
| 367 array[to_index] = current; | 367 array[to_index] = current; |
| 368 } else { | 368 } else { |
| 369 delete array[to_index]; | 369 delete array[to_index]; |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 for (var i = len; i > len - del_count + num_additional_args; i--) { | 372 for (var i = len; i > len - del_count + num_additional_args; i--) { |
| 373 delete array[i - 1]; | 373 delete array[i - 1]; |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 InternalArray.prototype.join = getFunction("join", ArrayJoin); | 1360 InternalArray.prototype.join = getFunction("join", ArrayJoin); |
| 1361 InternalArray.prototype.pop = getFunction("pop", ArrayPop); | 1361 InternalArray.prototype.pop = getFunction("pop", ArrayPop); |
| 1362 InternalArray.prototype.push = getFunction("push", ArrayPush); | 1362 InternalArray.prototype.push = getFunction("push", ArrayPush); |
| 1363 InternalArray.prototype.toString = function() { | 1363 InternalArray.prototype.toString = function() { |
| 1364 return "Internal Array, length " + this.length; | 1364 return "Internal Array, length " + this.length; |
| 1365 }; | 1365 }; |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 | 1368 |
| 1369 SetupArray(); | 1369 SetupArray(); |
| OLD | NEW |