| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 return result; | 637 return result; |
| 638 } | 638 } |
| 639 | 639 |
| 640 if (limit === 0) return []; | 640 if (limit === 0) return []; |
| 641 | 641 |
| 642 // Separator is a regular expression. | 642 // Separator is a regular expression. |
| 643 return StringSplitOnRegExp(subject, separator, limit, length); | 643 return StringSplitOnRegExp(subject, separator, limit, length); |
| 644 } | 644 } |
| 645 | 645 |
| 646 | 646 |
| 647 var ArrayPushBuiltin = $Array.prototype.push; |
| 648 |
| 647 function StringSplitOnRegExp(subject, separator, limit, length) { | 649 function StringSplitOnRegExp(subject, separator, limit, length) { |
| 648 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); | 650 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); |
| 649 | 651 |
| 650 if (length === 0) { | 652 if (length === 0) { |
| 651 if (DoRegExpExec(separator, subject, 0, 0) != null) { | 653 if (DoRegExpExec(separator, subject, 0, 0) != null) { |
| 652 return []; | 654 return []; |
| 653 } | 655 } |
| 654 return [subject]; | 656 return [subject]; |
| 655 } | 657 } |
| 656 | 658 |
| 657 var currentIndex = 0; | 659 var currentIndex = 0; |
| 658 var startIndex = 0; | 660 var startIndex = 0; |
| 659 var startMatch = 0; | 661 var startMatch = 0; |
| 660 var result = new InternalArray(); | 662 var result = []; |
| 661 | 663 |
| 662 outer_loop: | 664 outer_loop: |
| 663 while (true) { | 665 while (true) { |
| 664 | 666 |
| 665 if (startIndex === length) { | 667 if (startIndex === length) { |
| 666 result.push(%_SubString(subject, currentIndex, length)); | 668 %_CallFunction(result, %_SubString(subject, currentIndex, length), |
| 669 ArrayPushBuiltin); |
| 667 break; | 670 break; |
| 668 } | 671 } |
| 669 | 672 |
| 670 var matchInfo = DoRegExpExec(separator, subject, startIndex); | 673 var matchInfo = DoRegExpExec(separator, subject, startIndex); |
| 671 if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) { | 674 if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) { |
| 672 result.push(%_SubString(subject, currentIndex, length)); | 675 %_CallFunction(result, %_SubString(subject, currentIndex, length), |
| 676 ArrayPushBuiltin); |
| 673 break; | 677 break; |
| 674 } | 678 } |
| 675 var endIndex = matchInfo[CAPTURE1]; | 679 var endIndex = matchInfo[CAPTURE1]; |
| 676 | 680 |
| 677 // We ignore a zero-length match at the currentIndex. | 681 // We ignore a zero-length match at the currentIndex. |
| 678 if (startIndex === endIndex && endIndex === currentIndex) { | 682 if (startIndex === endIndex && endIndex === currentIndex) { |
| 679 startIndex++; | 683 startIndex++; |
| 680 continue; | 684 continue; |
| 681 } | 685 } |
| 682 | 686 |
| 683 result.push(%_SubString(subject, currentIndex, startMatch)); | 687 %_CallFunction(result, %_SubString(subject, currentIndex, startMatch), |
| 688 ArrayPushBuiltin); |
| 684 | 689 |
| 685 if (result.length === limit) break; | 690 if (result.length === limit) break; |
| 686 | 691 |
| 687 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; | 692 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; |
| 688 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { | 693 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { |
| 689 var start = matchInfo[i++]; | 694 var start = matchInfo[i++]; |
| 690 var end = matchInfo[i++]; | 695 var end = matchInfo[i++]; |
| 691 if (end != -1) { | 696 if (end != -1) { |
| 692 result.push(%_SubString(subject, start, end)); | 697 %_CallFunction(result, %_SubString(subject, start, end), |
| 698 ArrayPushBuiltin); |
| 693 } else { | 699 } else { |
| 694 result.push(void 0); | 700 %_CallFunction(result, void 0, ArrayPushBuiltin); |
| 695 } | 701 } |
| 696 if (result.length === limit) break outer_loop; | 702 if (result.length === limit) break outer_loop; |
| 697 } | 703 } |
| 698 | 704 |
| 699 startIndex = currentIndex = endIndex; | 705 startIndex = currentIndex = endIndex; |
| 700 } | 706 } |
| 701 return %MoveArrayContents(result, []); | 707 return result; |
| 702 } | 708 } |
| 703 | 709 |
| 704 | 710 |
| 705 // ECMA-262 section 15.5.4.15 | 711 // ECMA-262 section 15.5.4.15 |
| 706 function StringSubstring(start, end) { | 712 function StringSubstring(start, end) { |
| 707 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 713 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 708 throw MakeTypeError("called_on_null_or_undefined", | 714 throw MakeTypeError("called_on_null_or_undefined", |
| 709 ["String.prototype.subString"]); | 715 ["String.prototype.subString"]); |
| 710 } | 716 } |
| 711 var s = TO_STRING_INLINE(this); | 717 var s = TO_STRING_INLINE(this); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 "fixed", StringFixed, | 1006 "fixed", StringFixed, |
| 1001 "italics", StringItalics, | 1007 "italics", StringItalics, |
| 1002 "small", StringSmall, | 1008 "small", StringSmall, |
| 1003 "strike", StringStrike, | 1009 "strike", StringStrike, |
| 1004 "sub", StringSub, | 1010 "sub", StringSub, |
| 1005 "sup", StringSup | 1011 "sup", StringSup |
| 1006 )); | 1012 )); |
| 1007 } | 1013 } |
| 1008 | 1014 |
| 1009 SetUpString(); | 1015 SetUpString(); |
| OLD | NEW |