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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // This is part of the old simple-minded splice. We are using it either | 321 // This is part of the old simple-minded splice. We are using it either |
322 // because the receiver is not an array (so we have no choice) or because we | 322 // because the receiver is not an array (so we have no choice) or because we |
323 // know we are not deleting or moving a lot of elements. | 323 // know we are not deleting or moving a lot of elements. |
324 function SimpleSlice(array, start_i, del_count, len, deleted_elements) { | 324 function SimpleSlice(array, start_i, del_count, len, deleted_elements) { |
325 for (var i = 0; i < del_count; i++) { | 325 for (var i = 0; i < del_count; i++) { |
326 var index = start_i + i; | 326 var index = start_i + i; |
327 // The spec could also be interpreted such that %HasLocalProperty | 327 // The spec could also be interpreted such that %HasLocalProperty |
328 // would be the appropriate test. We follow KJS in consulting the | 328 // would be the appropriate test. We follow KJS in consulting the |
329 // prototype. | 329 // prototype. |
330 var current = array[index]; | 330 var current = array[index]; |
331 if (!IS_UNDEFINED(current) || index in array) | 331 if (!IS_UNDEFINED(current) || index in array) { |
332 deleted_elements[i] = current; | 332 deleted_elements[i] = current; |
| 333 } |
333 } | 334 } |
334 } | 335 } |
335 | 336 |
336 | 337 |
337 function SimpleMove(array, start_i, del_count, len, num_additional_args) { | 338 function SimpleMove(array, start_i, del_count, len, num_additional_args) { |
338 if (num_additional_args !== del_count) { | 339 if (num_additional_args !== del_count) { |
339 // Move the existing elements after the elements to be deleted | 340 // Move the existing elements after the elements to be deleted |
340 // to the right position in the resulting array. | 341 // to the right position in the resulting array. |
341 if (num_additional_args > del_count) { | 342 if (num_additional_args > del_count) { |
342 for (var i = len - del_count; i > start_i; i--) { | 343 for (var i = len - del_count; i > start_i; i--) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 | 570 |
570 var len = TO_UINT32(this.length); | 571 var len = TO_UINT32(this.length); |
571 | 572 |
572 if (len === 0) { | 573 if (len === 0) { |
573 this.length = 0; | 574 this.length = 0; |
574 return; | 575 return; |
575 } | 576 } |
576 | 577 |
577 var first = this[0]; | 578 var first = this[0]; |
578 | 579 |
579 if (IS_ARRAY(this)) | 580 if (IS_ARRAY(this)) { |
580 SmartMove(this, 0, 1, len, 0); | 581 SmartMove(this, 0, 1, len, 0); |
581 else | 582 } else { |
582 SimpleMove(this, 0, 1, len, 0); | 583 SimpleMove(this, 0, 1, len, 0); |
| 584 } |
583 | 585 |
584 this.length = len - 1; | 586 this.length = len - 1; |
585 | 587 |
586 return first; | 588 return first; |
587 } | 589 } |
588 | 590 |
589 | 591 |
590 function ArrayUnshift(arg1) { // length == 1 | 592 function ArrayUnshift(arg1) { // length == 1 |
591 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 593 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
592 throw MakeTypeError("called_on_null_or_undefined", | 594 throw MakeTypeError("called_on_null_or_undefined", |
593 ["Array.prototype.unshift"]); | 595 ["Array.prototype.unshift"]); |
594 } | 596 } |
595 | 597 |
596 var len = TO_UINT32(this.length); | 598 var len = TO_UINT32(this.length); |
597 var num_arguments = %_ArgumentsLength(); | 599 var num_arguments = %_ArgumentsLength(); |
598 | 600 |
599 if (IS_ARRAY(this)) | 601 if (IS_ARRAY(this)) { |
600 SmartMove(this, 0, 0, len, num_arguments); | 602 SmartMove(this, 0, 0, len, num_arguments); |
601 else | 603 } else { |
602 SimpleMove(this, 0, 0, len, num_arguments); | 604 SimpleMove(this, 0, 0, len, num_arguments); |
| 605 } |
603 | 606 |
604 for (var i = 0; i < num_arguments; i++) { | 607 for (var i = 0; i < num_arguments; i++) { |
605 this[i] = %_Arguments(i); | 608 this[i] = %_Arguments(i); |
606 } | 609 } |
607 | 610 |
608 this.length = len + num_arguments; | 611 this.length = len + num_arguments; |
609 | 612 |
610 return len + num_arguments; | 613 return len + num_arguments; |
611 } | 614 } |
612 | 615 |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 // exposed to user code. | 1418 // exposed to user code. |
1416 // Adding only the functions that are actually used. | 1419 // Adding only the functions that are actually used. |
1417 SetUpLockedPrototype(InternalArray, $Array(), $Array( | 1420 SetUpLockedPrototype(InternalArray, $Array(), $Array( |
1418 "join", getFunction("join", ArrayJoin), | 1421 "join", getFunction("join", ArrayJoin), |
1419 "pop", getFunction("pop", ArrayPop), | 1422 "pop", getFunction("pop", ArrayPop), |
1420 "push", getFunction("push", ArrayPush) | 1423 "push", getFunction("push", ArrayPush) |
1421 )); | 1424 )); |
1422 } | 1425 } |
1423 | 1426 |
1424 SetUpArray(); | 1427 SetUpArray(); |
OLD | NEW |