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

Side by Side Diff: src/string.js

Issue 113838: Fix for issue 351 - lastIndexOf. (Closed)
Patch Set: Added more tests, as requested. Created 11 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-351.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (index < 0) index = 0; 113 if (index < 0) index = 0;
114 if (index > subject_str_len) index = subject_str_len; 114 if (index > subject_str_len) index = subject_str_len;
115 if (pattern_str_len + index > subject_str_len) return -1; 115 if (pattern_str_len + index > subject_str_len) return -1;
116 return %StringIndexOf(subject_str, pattern_str, index); 116 return %StringIndexOf(subject_str, pattern_str, index);
117 } 117 }
118 118
119 119
120 // ECMA-262 section 15.5.4.8 120 // ECMA-262 section 15.5.4.8
121 function StringLastIndexOf(searchString /* position */) { // length == 1 121 function StringLastIndexOf(searchString /* position */) { // length == 1
122 var sub = ToString(this); 122 var sub = ToString(this);
123 var subLength = sub.length;
123 var pat = ToString(searchString); 124 var pat = ToString(searchString);
124 var index = (%_ArgumentsLength() > 1) 125 var patLength = pat.length;
125 ? ToNumber(%_Arguments(1) /* position */) 126 var index = subLength - patLength;
126 : $NaN; 127 if (%_ArgumentsLength() > 1) {
127 var firstIndex; 128 var position = ToNumber(%_Arguments(1));
128 if ($isNaN(index)) { 129 if (!$isNaN(position)) {
129 firstIndex = sub.length - pat.length; 130 position = TO_INTEGER(position);
130 } else { 131 if (position < 0) {
131 firstIndex = TO_INTEGER(index); 132 position = 0;
132 if (firstIndex + pat.length > sub.length) { 133 }
133 firstIndex = sub.length - pat.length; 134 if (position + patLength < subLength) {
135 index = position
136 }
134 } 137 }
135 } 138 }
136 return %StringLastIndexOf(sub, pat, firstIndex); 139 if (index < 0) {
140 return -1;
141 }
142 return %StringLastIndexOf(sub, pat, index);
137 } 143 }
138 144
139 145
140 // ECMA-262 section 15.5.4.9 146 // ECMA-262 section 15.5.4.9
141 // 147 //
142 // This function is implementation specific. For now, we do not 148 // This function is implementation specific. For now, we do not
143 // do anything locale specific. 149 // do anything locale specific.
144 function StringLocaleCompare(other) { 150 function StringLocaleCompare(other) {
145 if (%_ArgumentsLength() === 0) return 0; 151 if (%_ArgumentsLength() === 0) return 0;
146 152
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 "small", StringSmall, 869 "small", StringSmall,
864 "strike", StringStrike, 870 "strike", StringStrike,
865 "sub", StringSub, 871 "sub", StringSub,
866 "sup", StringSup, 872 "sup", StringSup,
867 "toJSON", StringToJSON 873 "toJSON", StringToJSON
868 )); 874 ));
869 } 875 }
870 876
871 877
872 SetupString(); 878 SetupString();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-351.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698