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

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

Issue 2339123002: [builtins] Move StringLastIndexOf to a builtin. (Closed)
Patch Set: Test natives callable from extensions with str compare instead 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/objects.h » ('j') | src/objects.h » ('J')
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 pattern = TO_STRING(pattern); 52 pattern = TO_STRING(pattern);
53 var index = TO_INTEGER(position); 53 var index = TO_INTEGER(position);
54 if (index < 0) index = 0; 54 if (index < 0) index = 0;
55 if (index > subject.length) index = subject.length; 55 if (index > subject.length) index = subject.length;
56 return %StringIndexOf(subject, pattern, index); 56 return %StringIndexOf(subject, pattern, index);
57 } 57 }
58 58
59 %FunctionSetLength(StringIndexOf, 1); 59 %FunctionSetLength(StringIndexOf, 1);
60 60
61 61
62 // ECMA-262 section 15.5.4.8
63 function StringLastIndexOf(pat, pos) { // length == 1
64 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf");
65
66 var sub = TO_STRING(this);
67 var subLength = sub.length;
68 var pat = TO_STRING(pat);
69 var patLength = pat.length;
70 var index = subLength - patLength;
71 var position = TO_NUMBER(pos);
72 if (!NUMBER_IS_NAN(position)) {
73 position = TO_INTEGER(position);
74 if (position < 0) {
75 position = 0;
76 }
77 if (position + patLength < subLength) {
78 index = position;
79 }
80 }
81 if (index < 0) {
82 return -1;
83 }
84 return %StringLastIndexOf(sub, pat, index);
85 }
86
87 %FunctionSetLength(StringLastIndexOf, 1);
88
89
90 // ES6 21.1.3.11. 62 // ES6 21.1.3.11.
91 function StringMatchJS(pattern) { 63 function StringMatchJS(pattern) {
92 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); 64 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
93 65
94 if (!IS_NULL_OR_UNDEFINED(pattern)) { 66 if (!IS_NULL_OR_UNDEFINED(pattern)) {
95 var matcher = pattern[matchSymbol]; 67 var matcher = pattern[matchSymbol];
96 if (!IS_UNDEFINED(matcher)) { 68 if (!IS_UNDEFINED(matcher)) {
97 return %_Call(matcher, pattern, this); 69 return %_Call(matcher, pattern, this);
98 } 70 }
99 } 71 }
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 "raw", StringRaw 667 "raw", StringRaw
696 ]); 668 ]);
697 669
698 // Set up the non-enumerable functions on the String prototype object. 670 // Set up the non-enumerable functions on the String prototype object.
699 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ 671 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
700 "codePointAt", StringCodePointAt, 672 "codePointAt", StringCodePointAt,
701 "concat", StringConcat, 673 "concat", StringConcat,
702 "endsWith", StringEndsWith, 674 "endsWith", StringEndsWith,
703 "includes", StringIncludes, 675 "includes", StringIncludes,
704 "indexOf", StringIndexOf, 676 "indexOf", StringIndexOf,
705 "lastIndexOf", StringLastIndexOf,
706 "match", StringMatchJS, 677 "match", StringMatchJS,
707 "repeat", StringRepeat, 678 "repeat", StringRepeat,
708 "replace", StringReplace, 679 "replace", StringReplace,
709 "search", StringSearch, 680 "search", StringSearch,
710 "slice", StringSlice, 681 "slice", StringSlice,
711 "split", StringSplitJS, 682 "split", StringSplitJS,
712 "substring", StringSubstring, 683 "substring", StringSubstring,
713 "substr", StringSubstr, 684 "substr", StringSubstr,
714 "startsWith", StringStartsWith, 685 "startsWith", StringStartsWith,
715 "toLowerCase", StringToLowerCaseJS, 686 "toLowerCase", StringToLowerCaseJS,
(...skipping 15 matching lines...) Expand all
731 "sub", StringSub, 702 "sub", StringSub,
732 "sup", StringSup 703 "sup", StringSup
733 ]); 704 ]);
734 705
735 // ------------------------------------------------------------------- 706 // -------------------------------------------------------------------
736 // Exports 707 // Exports
737 708
738 utils.Export(function(to) { 709 utils.Export(function(to) {
739 to.ExpandReplacement = ExpandReplacement; 710 to.ExpandReplacement = ExpandReplacement;
740 to.StringIndexOf = StringIndexOf; 711 to.StringIndexOf = StringIndexOf;
741 to.StringLastIndexOf = StringLastIndexOf;
742 to.StringMatch = StringMatchJS; 712 to.StringMatch = StringMatchJS;
743 to.StringReplace = StringReplace; 713 to.StringReplace = StringReplace;
744 to.StringSlice = StringSlice; 714 to.StringSlice = StringSlice;
745 to.StringSplit = StringSplitJS; 715 to.StringSplit = StringSplitJS;
746 to.StringSubstr = StringSubstr; 716 to.StringSubstr = StringSubstr;
747 to.StringSubstring = StringSubstring; 717 to.StringSubstring = StringSubstring;
748 }); 718 });
749 719
750 }) 720 })
OLDNEW
« no previous file with comments | « src/js/i18n.js ('k') | src/objects.h » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698