OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file relies on the fact that the following declaration has been made | 5 // This file relies on the fact that the following declaration has been made |
6 // in runtime.js: | 6 // in runtime.js: |
7 // var $String = global.String; | 7 // var $String = global.String; |
8 | 8 |
9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
10 | 10 |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 return result; | 611 return result; |
612 } | 612 } |
613 | 613 |
614 if (limit === 0) return []; | 614 if (limit === 0) return []; |
615 | 615 |
616 // Separator is a regular expression. | 616 // Separator is a regular expression. |
617 return StringSplitOnRegExp(subject, separator, limit, length); | 617 return StringSplitOnRegExp(subject, separator, limit, length); |
618 } | 618 } |
619 | 619 |
620 | 620 |
621 var ArrayPushBuiltin = $Array.prototype.push; | |
622 | |
623 function StringSplitOnRegExp(subject, separator, limit, length) { | 621 function StringSplitOnRegExp(subject, separator, limit, length) { |
624 if (length === 0) { | 622 if (length === 0) { |
625 if (DoRegExpExec(separator, subject, 0, 0) != null) { | 623 if (DoRegExpExec(separator, subject, 0, 0) != null) { |
626 return []; | 624 return []; |
627 } | 625 } |
628 return [subject]; | 626 return [subject]; |
629 } | 627 } |
630 | 628 |
631 var currentIndex = 0; | 629 var currentIndex = 0; |
632 var startIndex = 0; | 630 var startIndex = 0; |
633 var startMatch = 0; | 631 var startMatch = 0; |
634 var result = new InternalArray(); | 632 var result = new InternalArray(); |
635 | 633 |
636 outer_loop: | 634 outer_loop: |
637 while (true) { | 635 while (true) { |
638 | 636 |
639 if (startIndex === length) { | 637 if (startIndex === length) { |
640 %_CallFunction(result, %_SubString(subject, currentIndex, length), | 638 result[result.length] = %_SubString(subject, currentIndex, length); |
641 ArrayPushBuiltin); | |
642 break; | 639 break; |
643 } | 640 } |
644 | 641 |
645 var matchInfo = DoRegExpExec(separator, subject, startIndex); | 642 var matchInfo = DoRegExpExec(separator, subject, startIndex); |
646 if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) { | 643 if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) { |
647 %_CallFunction(result, %_SubString(subject, currentIndex, length), | 644 result[result.length] = %_SubString(subject, currentIndex, length); |
648 ArrayPushBuiltin); | |
649 break; | 645 break; |
650 } | 646 } |
651 var endIndex = matchInfo[CAPTURE1]; | 647 var endIndex = matchInfo[CAPTURE1]; |
652 | 648 |
653 // We ignore a zero-length match at the currentIndex. | 649 // We ignore a zero-length match at the currentIndex. |
654 if (startIndex === endIndex && endIndex === currentIndex) { | 650 if (startIndex === endIndex && endIndex === currentIndex) { |
655 startIndex++; | 651 startIndex++; |
656 continue; | 652 continue; |
657 } | 653 } |
658 | 654 |
659 %_CallFunction(result, %_SubString(subject, currentIndex, startMatch), | 655 result[result.length] = %_SubString(subject, currentIndex, startMatch); |
660 ArrayPushBuiltin); | |
661 | 656 |
662 if (result.length === limit) break; | 657 if (result.length === limit) break; |
663 | 658 |
664 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; | 659 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; |
665 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { | 660 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { |
666 var start = matchInfo[i++]; | 661 var start = matchInfo[i++]; |
667 var end = matchInfo[i++]; | 662 var end = matchInfo[i++]; |
668 if (end != -1) { | 663 if (end != -1) { |
669 %_CallFunction(result, %_SubString(subject, start, end), | 664 result[result.length] = %_SubString(subject, start, end); |
670 ArrayPushBuiltin); | |
671 } else { | 665 } else { |
672 %_CallFunction(result, UNDEFINED, ArrayPushBuiltin); | 666 result[result.length] = UNDEFINED; |
673 } | 667 } |
674 if (result.length === limit) break outer_loop; | 668 if (result.length === limit) break outer_loop; |
675 } | 669 } |
676 | 670 |
677 startIndex = currentIndex = endIndex; | 671 startIndex = currentIndex = endIndex; |
678 } | 672 } |
679 var array_result = []; | 673 var array_result = []; |
680 %MoveArrayContents(result, array_result); | 674 %MoveArrayContents(result, array_result); |
681 return array_result; | 675 return array_result; |
682 } | 676 } |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 "fixed", StringFixed, | 957 "fixed", StringFixed, |
964 "italics", StringItalics, | 958 "italics", StringItalics, |
965 "small", StringSmall, | 959 "small", StringSmall, |
966 "strike", StringStrike, | 960 "strike", StringStrike, |
967 "sub", StringSub, | 961 "sub", StringSub, |
968 "sup", StringSup | 962 "sup", StringSup |
969 )); | 963 )); |
970 } | 964 } |
971 | 965 |
972 SetUpString(); | 966 SetUpString(); |
OLD | NEW |