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