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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 | 585 |
586 result.length = end_i - start_i; | 586 result.length = end_i - start_i; |
587 | 587 |
588 return result; | 588 return result; |
589 } | 589 } |
590 | 590 |
591 | 591 |
592 function ArraySplice(start, delete_count) { | 592 function ArraySplice(start, delete_count) { |
593 var num_arguments = %_ArgumentsLength(); | 593 var num_arguments = %_ArgumentsLength(); |
594 | 594 |
595 if (num_arguments == 0) return []; | |
596 | |
595 var len = TO_UINT32(this.length); | 597 var len = TO_UINT32(this.length); |
596 var start_i = TO_INTEGER(start); | 598 var start_i = TO_INTEGER(start); |
597 | 599 |
598 if (start_i < 0) { | 600 if (start_i < 0) { |
599 start_i += len; | 601 start_i += len; |
600 if (start_i < 0) start_i = 0; | 602 if (start_i < 0) start_i = 0; |
601 } else { | 603 } else { |
602 if (start_i > len) start_i = len; | 604 if (start_i > len) start_i = len; |
603 } | 605 } |
604 | 606 |
605 // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is | 607 // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is |
606 // given differently from when an undefined delete count is given. | 608 // given differently from when an undefined delete count is given. |
607 // This does not follow ECMA-262, but we do the same for | 609 // This does not follow ECMA-262, but we do the same for |
608 // compatibility. | 610 // compatibility. |
609 var del_count = 0; | 611 var del_count = 0; |
610 if (num_arguments > 1) { | 612 if (num_arguments > 1) { |
Kevin Millikin (Chromium)
2011/01/31 07:55:11
This is pretty weird. It looks like the special c
| |
611 del_count = TO_INTEGER(delete_count); | 613 del_count = TO_INTEGER(delete_count); |
612 if (del_count < 0) del_count = 0; | 614 if (del_count < 0) del_count = 0; |
613 if (del_count > len - start_i) del_count = len - start_i; | 615 if (del_count > len - start_i) del_count = len - start_i; |
614 } else { | 616 } else { |
615 del_count = len - start_i; | 617 del_count = len - start_i; |
616 } | 618 } |
617 | 619 |
618 var deleted_elements = []; | 620 var deleted_elements = []; |
619 deleted_elements.length = del_count; | 621 deleted_elements.length = del_count; |
620 | 622 |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1227 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1229 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
1228 "reduce", getFunction("reduce", ArrayReduce, 1), | 1230 "reduce", getFunction("reduce", ArrayReduce, 1), |
1229 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1231 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
1230 )); | 1232 )); |
1231 | 1233 |
1232 %FinishArrayPrototypeSetup($Array.prototype); | 1234 %FinishArrayPrototypeSetup($Array.prototype); |
1233 } | 1235 } |
1234 | 1236 |
1235 | 1237 |
1236 SetupArray(); | 1238 SetupArray(); |
OLD | NEW |