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 28 matching lines...) Expand all Loading... |
39 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); | 39 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); |
40 var s = TO_STRING(this); | 40 var s = TO_STRING(this); |
41 var len = arguments.length; | 41 var len = arguments.length; |
42 for (var i = 0; i < len; ++i) { | 42 for (var i = 0; i < len; ++i) { |
43 s = s + TO_STRING(arguments[i]); | 43 s = s + TO_STRING(arguments[i]); |
44 } | 44 } |
45 return s; | 45 return s; |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 // ECMA-262 section 15.5.4.7 | |
50 function StringIndexOf(pattern, position) { // length == 1 | |
51 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf"); | |
52 | |
53 var subject = TO_STRING(this); | |
54 pattern = TO_STRING(pattern); | |
55 var index = TO_INTEGER(position); | |
56 if (index < 0) index = 0; | |
57 if (index > subject.length) index = subject.length; | |
58 return %StringIndexOf(subject, pattern, index); | |
59 } | |
60 | |
61 %FunctionSetLength(StringIndexOf, 1); | |
62 | |
63 | |
64 // ES6 21.1.3.11. | 49 // ES6 21.1.3.11. |
65 function StringMatchJS(pattern) { | 50 function StringMatchJS(pattern) { |
66 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); | 51 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); |
67 | 52 |
68 if (!IS_NULL_OR_UNDEFINED(pattern)) { | 53 if (!IS_NULL_OR_UNDEFINED(pattern)) { |
69 var matcher = pattern[matchSymbol]; | 54 var matcher = pattern[matchSymbol]; |
70 if (!IS_UNDEFINED(matcher)) { | 55 if (!IS_UNDEFINED(matcher)) { |
71 return %_Call(matcher, pattern, this); | 56 return %_Call(matcher, pattern, this); |
72 } | 57 } |
73 } | 58 } |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 utils.InstallFunctions(GlobalString, DONT_ENUM, [ | 562 utils.InstallFunctions(GlobalString, DONT_ENUM, [ |
578 "raw", StringRaw | 563 "raw", StringRaw |
579 ]); | 564 ]); |
580 | 565 |
581 // Set up the non-enumerable functions on the String prototype object. | 566 // Set up the non-enumerable functions on the String prototype object. |
582 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 567 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
583 "codePointAt", StringCodePointAt, | 568 "codePointAt", StringCodePointAt, |
584 "concat", StringConcat, | 569 "concat", StringConcat, |
585 "endsWith", StringEndsWith, | 570 "endsWith", StringEndsWith, |
586 "includes", StringIncludes, | 571 "includes", StringIncludes, |
587 "indexOf", StringIndexOf, | |
588 "match", StringMatchJS, | 572 "match", StringMatchJS, |
589 "repeat", StringRepeat, | 573 "repeat", StringRepeat, |
590 "replace", StringReplace, | 574 "replace", StringReplace, |
591 "search", StringSearch, | 575 "search", StringSearch, |
592 "slice", StringSlice, | 576 "slice", StringSlice, |
593 "split", StringSplitJS, | 577 "split", StringSplitJS, |
594 "substring", StringSubstring, | 578 "substring", StringSubstring, |
595 "substr", StringSubstr, | 579 "substr", StringSubstr, |
596 "startsWith", StringStartsWith, | 580 "startsWith", StringStartsWith, |
597 "toLowerCase", StringToLowerCaseJS, | 581 "toLowerCase", StringToLowerCaseJS, |
(...skipping 13 matching lines...) Expand all Loading... |
611 "small", StringSmall, | 595 "small", StringSmall, |
612 "strike", StringStrike, | 596 "strike", StringStrike, |
613 "sub", StringSub, | 597 "sub", StringSub, |
614 "sup", StringSup | 598 "sup", StringSup |
615 ]); | 599 ]); |
616 | 600 |
617 // ------------------------------------------------------------------- | 601 // ------------------------------------------------------------------- |
618 // Exports | 602 // Exports |
619 | 603 |
620 utils.Export(function(to) { | 604 utils.Export(function(to) { |
621 to.StringIndexOf = StringIndexOf; | |
622 to.StringMatch = StringMatchJS; | 605 to.StringMatch = StringMatchJS; |
623 to.StringReplace = StringReplace; | 606 to.StringReplace = StringReplace; |
624 to.StringSlice = StringSlice; | 607 to.StringSlice = StringSlice; |
625 to.StringSplit = StringSplitJS; | 608 to.StringSplit = StringSplitJS; |
626 to.StringSubstr = StringSubstr; | 609 to.StringSubstr = StringSubstr; |
627 to.StringSubstring = StringSubstring; | 610 to.StringSubstring = StringSubstring; |
628 }); | 611 }); |
629 | 612 |
630 }) | 613 }) |
OLD | NEW |