Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: src/string.js

Issue 17391016: Avoid relying on monkey-patchable things in String.prototype.split. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/string-split-monkey-patching.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 656
657 var currentIndex = 0; 657 var currentIndex = 0;
658 var startIndex = 0; 658 var startIndex = 0;
659 var startMatch = 0; 659 var startMatch = 0;
660 var result = []; 660 var result = [];
661 661
662 outer_loop: 662 outer_loop:
663 while (true) { 663 while (true) {
664 664
665 if (startIndex === length) { 665 if (startIndex === length) {
666 result.push(%_SubString(subject, currentIndex, length)); 666 result[result.length] = %_SubString(subject, currentIndex, length);
Yang 2013/06/19 10:30:43 Wouldn't it be possible to install an indexed gett
667 break; 667 break;
668 } 668 }
669 669
670 var matchInfo = DoRegExpExec(separator, subject, startIndex); 670 var matchInfo = DoRegExpExec(separator, subject, startIndex);
671 if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) { 671 if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) {
672 result.push(%_SubString(subject, currentIndex, length)); 672 result[result.length] = %_SubString(subject, currentIndex, length);
673 break; 673 break;
674 } 674 }
675 var endIndex = matchInfo[CAPTURE1]; 675 var endIndex = matchInfo[CAPTURE1];
676 676
677 // We ignore a zero-length match at the currentIndex. 677 // We ignore a zero-length match at the currentIndex.
678 if (startIndex === endIndex && endIndex === currentIndex) { 678 if (startIndex === endIndex && endIndex === currentIndex) {
679 startIndex++; 679 startIndex++;
680 continue; 680 continue;
681 } 681 }
682 682
683 result.push(%_SubString(subject, currentIndex, startMatch)); 683 result[result.length] = %_SubString(subject, currentIndex, startMatch);
684 684
685 if (result.length === limit) break; 685 if (result.length === limit) break;
686 686
687 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; 687 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE;
688 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { 688 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) {
689 var start = matchInfo[i++]; 689 var start = matchInfo[i++];
690 var end = matchInfo[i++]; 690 var end = matchInfo[i++];
691 if (end != -1) { 691 if (end != -1) {
692 result.push(%_SubString(subject, start, end)); 692 result[result.length] = %_SubString(subject, start, end);
693 } else { 693 } else {
694 result.push(void 0); 694 result[result.length] = void 0;
695 } 695 }
696 if (result.length === limit) break outer_loop; 696 if (result.length === limit) break outer_loop;
697 } 697 }
698 698
699 startIndex = currentIndex = endIndex; 699 startIndex = currentIndex = endIndex;
700 } 700 }
701 return result; 701 return result;
702 } 702 }
703 703
704 704
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 "fixed", StringFixed, 1000 "fixed", StringFixed,
1001 "italics", StringItalics, 1001 "italics", StringItalics,
1002 "small", StringSmall, 1002 "small", StringSmall,
1003 "strike", StringStrike, 1003 "strike", StringStrike,
1004 "sub", StringSub, 1004 "sub", StringSub,
1005 "sup", StringSup 1005 "sup", StringSup
1006 )); 1006 ));
1007 } 1007 }
1008 1008
1009 SetUpString(); 1009 SetUpString();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/string-split-monkey-patching.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698