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 |
11 | 11 |
12 var ArrayJoin; | 12 var ArrayJoin; |
13 var GetSubstitution; | 13 var GetSubstitution; |
14 var GlobalRegExp = global.RegExp; | 14 var GlobalRegExp = global.RegExp; |
15 var GlobalString = global.String; | 15 var GlobalString = global.String; |
16 var IsRegExp; | 16 var IsRegExp; |
17 var MaxSimple; | 17 var MaxSimple; |
18 var MinSimple; | 18 var MinSimple; |
19 var RegExpInitialize; | 19 var RegExpInitialize; |
| 20 var StringSubstring = GlobalString.prototype.substring; |
20 var matchSymbol = utils.ImportNow("match_symbol"); | 21 var matchSymbol = utils.ImportNow("match_symbol"); |
21 var replaceSymbol = utils.ImportNow("replace_symbol"); | 22 var replaceSymbol = utils.ImportNow("replace_symbol"); |
22 var searchSymbol = utils.ImportNow("search_symbol"); | 23 var searchSymbol = utils.ImportNow("search_symbol"); |
23 var splitSymbol = utils.ImportNow("split_symbol"); | 24 var splitSymbol = utils.ImportNow("split_symbol"); |
24 | 25 |
25 utils.Import(function(from) { | 26 utils.Import(function(from) { |
26 ArrayJoin = from.ArrayJoin; | 27 ArrayJoin = from.ArrayJoin; |
27 GetSubstitution = from.GetSubstitution; | 28 GetSubstitution = from.GetSubstitution; |
28 IsRegExp = from.IsRegExp; | 29 IsRegExp = from.IsRegExp; |
29 MaxSimple = from.MaxSimple; | 30 MaxSimple = from.MaxSimple; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (IS_UNDEFINED(separator)) return [subject]; | 231 if (IS_UNDEFINED(separator)) return [subject]; |
231 | 232 |
232 var separator_length = separator_string.length; | 233 var separator_length = separator_string.length; |
233 | 234 |
234 // If the separator string is empty then return the elements in the subject. | 235 // If the separator string is empty then return the elements in the subject. |
235 if (separator_length === 0) return %StringToArray(subject, limit); | 236 if (separator_length === 0) return %StringToArray(subject, limit); |
236 | 237 |
237 return %StringSplit(subject, separator_string, limit); | 238 return %StringSplit(subject, separator_string, limit); |
238 } | 239 } |
239 | 240 |
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 | 241 // ecma262/#sec-string.prototype.substr |
275 function StringSubstr(start, length) { | 242 function StringSubstr(start, length) { |
276 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); | 243 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); |
277 var s = TO_STRING(this); | 244 var s = TO_STRING(this); |
278 var size = s.length; | 245 var size = s.length; |
279 start = TO_INTEGER(start); | 246 start = TO_INTEGER(start); |
280 length = IS_UNDEFINED(length) ? size : TO_INTEGER(length); | 247 length = IS_UNDEFINED(length) ? size : TO_INTEGER(length); |
281 | 248 |
282 if (start < 0) start = MaxSimple(size + start, 0); | 249 if (start < 0) start = MaxSimple(size + start, 0); |
283 length = MinSimple(MaxSimple(length, 0), size - start); | 250 length = MinSimple(MaxSimple(length, 0), size - start); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 "concat", StringConcat, | 551 "concat", StringConcat, |
585 "endsWith", StringEndsWith, | 552 "endsWith", StringEndsWith, |
586 "includes", StringIncludes, | 553 "includes", StringIncludes, |
587 "indexOf", StringIndexOf, | 554 "indexOf", StringIndexOf, |
588 "match", StringMatchJS, | 555 "match", StringMatchJS, |
589 "repeat", StringRepeat, | 556 "repeat", StringRepeat, |
590 "replace", StringReplace, | 557 "replace", StringReplace, |
591 "search", StringSearch, | 558 "search", StringSearch, |
592 "slice", StringSlice, | 559 "slice", StringSlice, |
593 "split", StringSplitJS, | 560 "split", StringSplitJS, |
594 "substring", StringSubstring, | |
595 "substr", StringSubstr, | 561 "substr", StringSubstr, |
596 "startsWith", StringStartsWith, | 562 "startsWith", StringStartsWith, |
597 "toLowerCase", StringToLowerCaseJS, | 563 "toLowerCase", StringToLowerCaseJS, |
598 "toLocaleLowerCase", StringToLocaleLowerCase, | 564 "toLocaleLowerCase", StringToLocaleLowerCase, |
599 "toUpperCase", StringToUpperCaseJS, | 565 "toUpperCase", StringToUpperCaseJS, |
600 "toLocaleUpperCase", StringToLocaleUpperCase, | 566 "toLocaleUpperCase", StringToLocaleUpperCase, |
601 | 567 |
602 "link", StringLink, | 568 "link", StringLink, |
603 "anchor", StringAnchor, | 569 "anchor", StringAnchor, |
604 "fontcolor", StringFontcolor, | 570 "fontcolor", StringFontcolor, |
(...skipping 16 matching lines...) Expand all Loading... |
621 to.StringIndexOf = StringIndexOf; | 587 to.StringIndexOf = StringIndexOf; |
622 to.StringMatch = StringMatchJS; | 588 to.StringMatch = StringMatchJS; |
623 to.StringReplace = StringReplace; | 589 to.StringReplace = StringReplace; |
624 to.StringSlice = StringSlice; | 590 to.StringSlice = StringSlice; |
625 to.StringSplit = StringSplitJS; | 591 to.StringSplit = StringSplitJS; |
626 to.StringSubstr = StringSubstr; | 592 to.StringSubstr = StringSubstr; |
627 to.StringSubstring = StringSubstring; | 593 to.StringSubstring = StringSubstring; |
628 }); | 594 }); |
629 | 595 |
630 }) | 596 }) |
OLD | NEW |