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

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

Issue 2351643002: [builtins] Move StringIndexOf to a builtin. (Closed)
Patch Set: Fix signed vs unsigned comparison Created 4 years, 3 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') | src/messages.cc » ('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 26 matching lines...) Expand all
37 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); 37 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat");
38 var s = TO_STRING(this); 38 var s = TO_STRING(this);
39 var len = arguments.length; 39 var len = arguments.length;
40 for (var i = 0; i < len; ++i) { 40 for (var i = 0; i < len; ++i) {
41 s = s + TO_STRING(arguments[i]); 41 s = s + TO_STRING(arguments[i]);
42 } 42 }
43 return s; 43 return s;
44 } 44 }
45 45
46 46
47 // ECMA-262 section 15.5.4.7
48 function StringIndexOf(pattern, position) { // length == 1
49 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf");
50
51 var subject = TO_STRING(this);
52 pattern = TO_STRING(pattern);
53 var index = TO_INTEGER(position);
54 if (index < 0) index = 0;
55 if (index > subject.length) index = subject.length;
56 return %StringIndexOf(subject, pattern, index);
57 }
58
59 %FunctionSetLength(StringIndexOf, 1);
60
61
62 // ES6 21.1.3.11. 47 // ES6 21.1.3.11.
63 function StringMatchJS(pattern) { 48 function StringMatchJS(pattern) {
64 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); 49 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
65 50
66 if (!IS_NULL_OR_UNDEFINED(pattern)) { 51 if (!IS_NULL_OR_UNDEFINED(pattern)) {
67 var matcher = pattern[matchSymbol]; 52 var matcher = pattern[matchSymbol];
68 if (!IS_UNDEFINED(matcher)) { 53 if (!IS_UNDEFINED(matcher)) {
69 return %_Call(matcher, pattern, this); 54 return %_Call(matcher, pattern, this);
70 } 55 }
71 } 56 }
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 utils.InstallFunctions(GlobalString, DONT_ENUM, [ 651 utils.InstallFunctions(GlobalString, DONT_ENUM, [
667 "raw", StringRaw 652 "raw", StringRaw
668 ]); 653 ]);
669 654
670 // Set up the non-enumerable functions on the String prototype object. 655 // Set up the non-enumerable functions on the String prototype object.
671 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ 656 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
672 "codePointAt", StringCodePointAt, 657 "codePointAt", StringCodePointAt,
673 "concat", StringConcat, 658 "concat", StringConcat,
674 "endsWith", StringEndsWith, 659 "endsWith", StringEndsWith,
675 "includes", StringIncludes, 660 "includes", StringIncludes,
676 "indexOf", StringIndexOf,
677 "match", StringMatchJS, 661 "match", StringMatchJS,
678 "repeat", StringRepeat, 662 "repeat", StringRepeat,
679 "replace", StringReplace, 663 "replace", StringReplace,
680 "search", StringSearch, 664 "search", StringSearch,
681 "slice", StringSlice, 665 "slice", StringSlice,
682 "split", StringSplitJS, 666 "split", StringSplitJS,
683 "substring", StringSubstring, 667 "substring", StringSubstring,
684 "substr", StringSubstr, 668 "substr", StringSubstr,
685 "startsWith", StringStartsWith, 669 "startsWith", StringStartsWith,
686 "toLowerCase", StringToLowerCaseJS, 670 "toLowerCase", StringToLowerCaseJS,
(...skipping 14 matching lines...) Expand all
701 "strike", StringStrike, 685 "strike", StringStrike,
702 "sub", StringSub, 686 "sub", StringSub,
703 "sup", StringSup 687 "sup", StringSup
704 ]); 688 ]);
705 689
706 // ------------------------------------------------------------------- 690 // -------------------------------------------------------------------
707 // Exports 691 // Exports
708 692
709 utils.Export(function(to) { 693 utils.Export(function(to) {
710 to.ExpandReplacement = ExpandReplacement; 694 to.ExpandReplacement = ExpandReplacement;
711 to.StringIndexOf = StringIndexOf;
712 to.StringMatch = StringMatchJS; 695 to.StringMatch = StringMatchJS;
713 to.StringReplace = StringReplace; 696 to.StringReplace = StringReplace;
714 to.StringSlice = StringSlice; 697 to.StringSlice = StringSlice;
715 to.StringSplit = StringSplitJS; 698 to.StringSplit = StringSplitJS;
716 to.StringSubstr = StringSubstr; 699 to.StringSubstr = StringSubstr;
717 to.StringSubstring = StringSubstring; 700 to.StringSubstring = StringSubstring;
718 }); 701 });
719 702
720 }) 703 })
OLDNEW
« no previous file with comments | « src/js/i18n.js ('k') | src/messages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698