OLD | NEW |
---|---|
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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 } | 1024 } |
1025 | 1025 |
1026 return %StringLastIndexOf(s, ss, start) === start; | 1026 return %StringLastIndexOf(s, ss, start) === start; |
1027 } | 1027 } |
1028 | 1028 |
1029 | 1029 |
1030 // ES6 draft 04-05-14, section 21.1.3.6 | 1030 // ES6 draft 04-05-14, section 21.1.3.6 |
1031 function StringIncludes(searchString /* position */) { // length == 1 | 1031 function StringIncludes(searchString /* position */) { // length == 1 |
1032 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); | 1032 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); |
1033 | 1033 |
1034 var s = TO_STRING_INLINE(this); | 1034 var string = TO_STRING_INLINE(this); |
1035 | 1035 |
1036 if (IS_REGEXP(searchString)) { | 1036 if (IS_REGEXP(searchString)) { |
1037 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); | 1037 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); |
1038 } | 1038 } |
1039 | 1039 |
1040 var ss = TO_STRING_INLINE(searchString); | 1040 searchString = TO_STRING_INLINE(searchString); |
thefourtheye_
2015/07/15 01:26:00
Isn't this a DEOPT? Using the argument variable in
| |
1041 var pos = 0; | 1041 var pos = 0; |
1042 if (%_ArgumentsLength() > 1) { | 1042 if (%_ArgumentsLength() > 1) { |
1043 pos = %_Arguments(1); // position | 1043 pos = %_Arguments(1); // position |
1044 pos = $toInteger(pos); | 1044 pos = TO_INTEGER(pos); |
1045 } | 1045 } |
1046 | 1046 |
1047 var s_len = s.length; | 1047 var stringLength = string.length; |
1048 var start = MathMin(MathMax(pos, 0), s_len); | 1048 if (pos < 0) pos = 0; |
1049 var ss_len = ss.length; | 1049 if (pos > stringLength) pos = stringLength; |
1050 if (ss_len + start > s_len) { | 1050 var searchStringLength = searchString.length; |
thefourtheye_
2015/07/15 01:26:00
Very minor optimization, but can we move this abov
| |
1051 | |
1052 if (searchStringLength + pos > stringLength) { | |
1051 return false; | 1053 return false; |
1052 } | 1054 } |
1053 | 1055 |
1054 return %StringIndexOf(s, ss, start) !== -1; | 1056 return %StringIndexOf(string, searchString, pos) !== -1; |
1055 } | 1057 } |
1056 | 1058 |
1057 | 1059 |
1058 // ES6 Draft 05-22-2014, section 21.1.3.3 | 1060 // ES6 Draft 05-22-2014, section 21.1.3.3 |
1059 function StringCodePointAt(pos) { | 1061 function StringCodePointAt(pos) { |
1060 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); | 1062 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); |
1061 | 1063 |
1062 var string = TO_STRING_INLINE(this); | 1064 var string = TO_STRING_INLINE(this); |
1063 var size = string.length; | 1065 var size = string.length; |
1064 pos = TO_INTEGER(pos); | 1066 pos = TO_INTEGER(pos); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1198 to.StringIndexOf = StringIndexOfJS; | 1200 to.StringIndexOf = StringIndexOfJS; |
1199 to.StringLastIndexOf = StringLastIndexOfJS; | 1201 to.StringLastIndexOf = StringLastIndexOfJS; |
1200 to.StringMatch = StringMatchJS; | 1202 to.StringMatch = StringMatchJS; |
1201 to.StringReplace = StringReplace; | 1203 to.StringReplace = StringReplace; |
1202 to.StringSplit = StringSplitJS; | 1204 to.StringSplit = StringSplitJS; |
1203 to.StringSubstr = StringSubstr; | 1205 to.StringSubstr = StringSubstr; |
1204 to.StringSubstring = StringSubstring; | 1206 to.StringSubstring = StringSubstring; |
1205 }); | 1207 }); |
1206 | 1208 |
1207 }) | 1209 }) |
OLD | NEW |