OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $String = global.String; | 9 // var $String = global.String; |
10 // var $Array = global.Array; | 10 // var $Array = global.Array; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 } | 91 } |
92 | 92 |
93 return %StringLastIndexOf(s, ss, start) === start; | 93 return %StringLastIndexOf(s, ss, start) === start; |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 // ES6 draft 04-05-14, section 21.1.3.6 | 97 // ES6 draft 04-05-14, section 21.1.3.6 |
98 function StringIncludes(searchString /* position */) { // length == 1 | 98 function StringIncludes(searchString /* position */) { // length == 1 |
99 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); | 99 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); |
100 | 100 |
101 var s = TO_STRING_INLINE(this); | 101 var string = TO_STRING_INLINE(this); |
102 | 102 |
103 if (IS_REGEXP(searchString)) { | 103 if (IS_REGEXP(searchString)) { |
104 throw MakeTypeError("first_argument_not_regexp", | 104 throw MakeTypeError("first_argument_not_regexp", |
105 ["String.prototype.includes"]); | 105 ["String.prototype.includes"]); |
106 } | 106 } |
107 | 107 |
108 var ss = TO_STRING_INLINE(searchString); | 108 var searchStr = TO_STRING_INLINE(searchString); |
arv (Not doing code reviews)
2015/01/14 16:10:15
searchStr -> searchString
| |
109 var pos = 0; | 109 var pos = ToInteger(%_Arguments(1)); |
110 if (%_ArgumentsLength() > 1) { | 110 var len = string.length; |
111 pos = %_Arguments(1); // position | 111 var searchLen = searchStr.length; |
arv (Not doing code reviews)
2015/01/14 16:10:15
searchLen -> searchLength
| |
112 pos = ToInteger(pos); | |
113 } | |
114 | 112 |
115 var s_len = s.length; | 113 if (pos < 0) pos = 0; |
116 var start = MathMin(MathMax(pos, 0), s_len); | 114 if (pos > len) pos = len; |
arv (Not doing code reviews)
2015/01/14 16:10:15
else if here?
| |
117 var ss_len = ss.length; | 115 if (searchLen + pos > len) return false; |
118 if (ss_len + start > s_len) { | |
119 return false; | |
120 } | |
121 | 116 |
122 return %StringIndexOf(s, ss, start) !== -1; | 117 return %StringIndexOf(string, searchStr, pos) !== -1; |
123 } | 118 } |
124 | 119 |
125 | 120 |
126 // ES6 Draft 05-22-2014, section 21.1.3.3 | 121 // ES6 Draft 05-22-2014, section 21.1.3.3 |
127 function StringCodePointAt(pos) { | 122 function StringCodePointAt(pos) { |
128 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); | 123 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); |
129 | 124 |
130 var string = TO_STRING_INLINE(this); | 125 var string = TO_STRING_INLINE(this); |
131 var size = string.length; | 126 var size = string.length; |
132 pos = TO_INTEGER(pos); | 127 pos = TO_INTEGER(pos); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 InstallFunctions($String.prototype, DONT_ENUM, $Array( | 180 InstallFunctions($String.prototype, DONT_ENUM, $Array( |
186 "codePointAt", StringCodePointAt, | 181 "codePointAt", StringCodePointAt, |
187 "includes", StringIncludes, | 182 "includes", StringIncludes, |
188 "endsWith", StringEndsWith, | 183 "endsWith", StringEndsWith, |
189 "repeat", StringRepeat, | 184 "repeat", StringRepeat, |
190 "startsWith", StringStartsWith | 185 "startsWith", StringStartsWith |
191 )); | 186 )); |
192 } | 187 } |
193 | 188 |
194 ExtendStringPrototype(); | 189 ExtendStringPrototype(); |
OLD | NEW |