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

Side by Side Diff: src/js/string.js

Issue 2373493002: [stubs] Port String.prototype.substr to TurboFan (Closed)
Patch Set: Additional tests Created 4 years, 2 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 | « src/js/i18n.js ('k') | test/mjsunit/substr.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 // 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (IS_UNDEFINED(separator)) return [subject]; 230 if (IS_UNDEFINED(separator)) return [subject];
231 231
232 var separator_length = separator_string.length; 232 var separator_length = separator_string.length;
233 233
234 // If the separator string is empty then return the elements in the subject. 234 // If the separator string is empty then return the elements in the subject.
235 if (separator_length === 0) return %StringToArray(subject, limit); 235 if (separator_length === 0) return %StringToArray(subject, limit);
236 236
237 return %StringSplit(subject, separator_string, limit); 237 return %StringSplit(subject, separator_string, limit);
238 } 238 }
239 239
240 // ecma262/#sec-string.prototype.substr
241 function StringSubstr(start, length) {
242 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr");
243 var s = TO_STRING(this);
244 var size = s.length;
245 start = TO_INTEGER(start);
246 length = IS_UNDEFINED(length) ? size : TO_INTEGER(length);
247
248 if (start < 0) start = MaxSimple(size + start, 0);
249 length = MinSimple(MaxSimple(length, 0), size - start);
250
251 if (length <= 0) return '';
252 return %_SubString(s, start, start + length);
253 }
254
255 240
256 // ECMA-262, 15.5.4.16 241 // ECMA-262, 15.5.4.16
257 function StringToLowerCaseJS() { 242 function StringToLowerCaseJS() {
258 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); 243 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
259 244
260 return %StringToLowerCase(TO_STRING(this)); 245 return %StringToLowerCase(TO_STRING(this));
261 } 246 }
262 247
263 248
264 // ECMA-262, 15.5.4.17 249 // ECMA-262, 15.5.4.17
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 "concat", StringConcat, 535 "concat", StringConcat,
551 "endsWith", StringEndsWith, 536 "endsWith", StringEndsWith,
552 "includes", StringIncludes, 537 "includes", StringIncludes,
553 "indexOf", StringIndexOf, 538 "indexOf", StringIndexOf,
554 "match", StringMatchJS, 539 "match", StringMatchJS,
555 "repeat", StringRepeat, 540 "repeat", StringRepeat,
556 "replace", StringReplace, 541 "replace", StringReplace,
557 "search", StringSearch, 542 "search", StringSearch,
558 "slice", StringSlice, 543 "slice", StringSlice,
559 "split", StringSplitJS, 544 "split", StringSplitJS,
560 "substr", StringSubstr,
561 "startsWith", StringStartsWith, 545 "startsWith", StringStartsWith,
562 "toLowerCase", StringToLowerCaseJS, 546 "toLowerCase", StringToLowerCaseJS,
563 "toLocaleLowerCase", StringToLocaleLowerCase, 547 "toLocaleLowerCase", StringToLocaleLowerCase,
564 "toUpperCase", StringToUpperCaseJS, 548 "toUpperCase", StringToUpperCaseJS,
565 "toLocaleUpperCase", StringToLocaleUpperCase, 549 "toLocaleUpperCase", StringToLocaleUpperCase,
566 550
567 "link", StringLink, 551 "link", StringLink,
568 "anchor", StringAnchor, 552 "anchor", StringAnchor,
569 "fontcolor", StringFontcolor, 553 "fontcolor", StringFontcolor,
570 "fontsize", StringFontsize, 554 "fontsize", StringFontsize,
(...skipping 10 matching lines...) Expand all
581 565
582 // ------------------------------------------------------------------- 566 // -------------------------------------------------------------------
583 // Exports 567 // Exports
584 568
585 utils.Export(function(to) { 569 utils.Export(function(to) {
586 to.StringIndexOf = StringIndexOf; 570 to.StringIndexOf = StringIndexOf;
587 to.StringMatch = StringMatchJS; 571 to.StringMatch = StringMatchJS;
588 to.StringReplace = StringReplace; 572 to.StringReplace = StringReplace;
589 to.StringSlice = StringSlice; 573 to.StringSlice = StringSlice;
590 to.StringSplit = StringSplitJS; 574 to.StringSplit = StringSplitJS;
591 to.StringSubstr = StringSubstr;
592 }); 575 });
593 576
594 }) 577 })
OLDNEW
« no previous file with comments | « src/js/i18n.js ('k') | test/mjsunit/substr.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698