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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | |
241 // ECMA-262 section 15.5.4.15 | |
242 function StringSubstring(start, end) { | |
243 CHECK_OBJECT_COERCIBLE(this, "String.prototype.subString"); | |
244 | |
245 var s = TO_STRING(this); | |
246 var s_len = s.length; | |
247 | |
248 var start_i = TO_INTEGER(start); | |
249 if (start_i < 0) { | |
250 start_i = 0; | |
251 } else if (start_i > s_len) { | |
252 start_i = s_len; | |
253 } | |
254 | |
255 var end_i = s_len; | |
256 if (!IS_UNDEFINED(end)) { | |
257 end_i = TO_INTEGER(end); | |
258 if (end_i > s_len) { | |
259 end_i = s_len; | |
260 } else { | |
261 if (end_i < 0) end_i = 0; | |
262 if (start_i > end_i) { | |
263 var tmp = end_i; | |
264 end_i = start_i; | |
265 start_i = tmp; | |
266 } | |
267 } | |
268 } | |
269 | |
270 return %_SubString(s, start_i, end_i); | |
271 } | |
272 | |
273 | |
274 // ecma262/#sec-string.prototype.substr | 240 // ecma262/#sec-string.prototype.substr |
275 function StringSubstr(start, length) { | 241 function StringSubstr(start, length) { |
276 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); | 242 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); |
277 var s = TO_STRING(this); | 243 var s = TO_STRING(this); |
278 var size = s.length; | 244 var size = s.length; |
279 start = TO_INTEGER(start); | 245 start = TO_INTEGER(start); |
280 length = IS_UNDEFINED(length) ? size : TO_INTEGER(length); | 246 length = IS_UNDEFINED(length) ? size : TO_INTEGER(length); |
281 | 247 |
282 if (start < 0) start = MaxSimple(size + start, 0); | 248 if (start < 0) start = MaxSimple(size + start, 0); |
283 length = MinSimple(MaxSimple(length, 0), size - start); | 249 length = MinSimple(MaxSimple(length, 0), size - start); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 "concat", StringConcat, | 550 "concat", StringConcat, |
585 "endsWith", StringEndsWith, | 551 "endsWith", StringEndsWith, |
586 "includes", StringIncludes, | 552 "includes", StringIncludes, |
587 "indexOf", StringIndexOf, | 553 "indexOf", StringIndexOf, |
588 "match", StringMatchJS, | 554 "match", StringMatchJS, |
589 "repeat", StringRepeat, | 555 "repeat", StringRepeat, |
590 "replace", StringReplace, | 556 "replace", StringReplace, |
591 "search", StringSearch, | 557 "search", StringSearch, |
592 "slice", StringSlice, | 558 "slice", StringSlice, |
593 "split", StringSplitJS, | 559 "split", StringSplitJS, |
594 "substring", StringSubstring, | |
595 "substr", StringSubstr, | 560 "substr", StringSubstr, |
596 "startsWith", StringStartsWith, | 561 "startsWith", StringStartsWith, |
597 "toLowerCase", StringToLowerCaseJS, | 562 "toLowerCase", StringToLowerCaseJS, |
598 "toLocaleLowerCase", StringToLocaleLowerCase, | 563 "toLocaleLowerCase", StringToLocaleLowerCase, |
599 "toUpperCase", StringToUpperCaseJS, | 564 "toUpperCase", StringToUpperCaseJS, |
600 "toLocaleUpperCase", StringToLocaleUpperCase, | 565 "toLocaleUpperCase", StringToLocaleUpperCase, |
601 | 566 |
602 "link", StringLink, | 567 "link", StringLink, |
603 "anchor", StringAnchor, | 568 "anchor", StringAnchor, |
604 "fontcolor", StringFontcolor, | 569 "fontcolor", StringFontcolor, |
(...skipping 12 matching lines...) Expand all Loading... |
617 // ------------------------------------------------------------------- | 582 // ------------------------------------------------------------------- |
618 // Exports | 583 // Exports |
619 | 584 |
620 utils.Export(function(to) { | 585 utils.Export(function(to) { |
621 to.StringIndexOf = StringIndexOf; | 586 to.StringIndexOf = StringIndexOf; |
622 to.StringMatch = StringMatchJS; | 587 to.StringMatch = StringMatchJS; |
623 to.StringReplace = StringReplace; | 588 to.StringReplace = StringReplace; |
624 to.StringSlice = StringSlice; | 589 to.StringSlice = StringSlice; |
625 to.StringSplit = StringSplitJS; | 590 to.StringSplit = StringSplitJS; |
626 to.StringSubstr = StringSubstr; | 591 to.StringSubstr = StringSubstr; |
627 to.StringSubstring = StringSubstring; | |
628 }); | 592 }); |
629 | 593 |
630 }) | 594 }) |
OLD | NEW |