| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 var subject = TO_STRING(this); | 112 var subject = TO_STRING(this); |
| 113 | 113 |
| 114 // Equivalent to RegExpCreate (ES#sec-regexpcreate) | 114 // Equivalent to RegExpCreate (ES#sec-regexpcreate) |
| 115 var regexp = %_NewObject(GlobalRegExp, GlobalRegExp); | 115 var regexp = %_NewObject(GlobalRegExp, GlobalRegExp); |
| 116 RegExpInitialize(regexp, pattern); | 116 RegExpInitialize(regexp, pattern); |
| 117 return regexp[matchSymbol](subject); | 117 return regexp[matchSymbol](subject); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 // ECMA-262 v6, section 21.1.3.12 | |
| 122 // | |
| 123 // For now we do nothing, as proper normalization requires big tables. | |
| 124 // If Intl is enabled, then i18n.js will override it and provide the the | |
| 125 // proper functionality. | |
| 126 function StringNormalize(formArg) { // length == 0 | |
| 127 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); | |
| 128 var s = TO_STRING(this); | |
| 129 | |
| 130 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg); | |
| 131 | |
| 132 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; | |
| 133 var normalizationForm = %ArrayIndexOf(NORMALIZATION_FORMS, form, 0); | |
| 134 if (normalizationForm === -1) { | |
| 135 throw %make_range_error(kNormalizationForm, | |
| 136 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', ')); | |
| 137 } | |
| 138 | |
| 139 return s; | |
| 140 } | |
| 141 | |
| 142 %FunctionSetLength(StringNormalize, 0); | |
| 143 | |
| 144 | |
| 145 // This has the same size as the RegExpLastMatchInfo array, and can be used | 121 // This has the same size as the RegExpLastMatchInfo array, and can be used |
| 146 // for functions that expect that structure to be returned. It is used when | 122 // for functions that expect that structure to be returned. It is used when |
| 147 // the needle is a string rather than a regexp. In this case we can't update | 123 // the needle is a string rather than a regexp. In this case we can't update |
| 148 // lastMatchArray without erroneously affecting the properties on the global | 124 // lastMatchArray without erroneously affecting the properties on the global |
| 149 // RegExp object. | 125 // RegExp object. |
| 150 var reusableMatchInfo = [2, "", "", -1, -1]; | 126 var reusableMatchInfo = [2, "", "", -1, -1]; |
| 151 | 127 |
| 152 | 128 |
| 153 // ES6, section 21.1.3.14 | 129 // ES6, section 21.1.3.14 |
| 154 function StringReplace(search, replace) { | 130 function StringReplace(search, replace) { |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 // Set up the non-enumerable functions on the String prototype object. | 709 // Set up the non-enumerable functions on the String prototype object. |
| 734 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 710 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
| 735 "codePointAt", StringCodePointAt, | 711 "codePointAt", StringCodePointAt, |
| 736 "concat", StringConcat, | 712 "concat", StringConcat, |
| 737 "endsWith", StringEndsWith, | 713 "endsWith", StringEndsWith, |
| 738 "includes", StringIncludes, | 714 "includes", StringIncludes, |
| 739 "indexOf", StringIndexOf, | 715 "indexOf", StringIndexOf, |
| 740 "lastIndexOf", StringLastIndexOf, | 716 "lastIndexOf", StringLastIndexOf, |
| 741 "localeCompare", StringLocaleCompareJS, | 717 "localeCompare", StringLocaleCompareJS, |
| 742 "match", StringMatchJS, | 718 "match", StringMatchJS, |
| 743 "normalize", StringNormalize, | |
| 744 "repeat", StringRepeat, | 719 "repeat", StringRepeat, |
| 745 "replace", StringReplace, | 720 "replace", StringReplace, |
| 746 "search", StringSearch, | 721 "search", StringSearch, |
| 747 "slice", StringSlice, | 722 "slice", StringSlice, |
| 748 "split", StringSplitJS, | 723 "split", StringSplitJS, |
| 749 "substring", StringSubstring, | 724 "substring", StringSubstring, |
| 750 "substr", StringSubstr, | 725 "substr", StringSubstr, |
| 751 "startsWith", StringStartsWith, | 726 "startsWith", StringStartsWith, |
| 752 "toLowerCase", StringToLowerCaseJS, | 727 "toLowerCase", StringToLowerCaseJS, |
| 753 "toLocaleLowerCase", StringToLocaleLowerCase, | 728 "toLocaleLowerCase", StringToLocaleLowerCase, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 778 to.StringLastIndexOf = StringLastIndexOf; | 753 to.StringLastIndexOf = StringLastIndexOf; |
| 779 to.StringMatch = StringMatchJS; | 754 to.StringMatch = StringMatchJS; |
| 780 to.StringReplace = StringReplace; | 755 to.StringReplace = StringReplace; |
| 781 to.StringSlice = StringSlice; | 756 to.StringSlice = StringSlice; |
| 782 to.StringSplit = StringSplitJS; | 757 to.StringSplit = StringSplitJS; |
| 783 to.StringSubstr = StringSubstr; | 758 to.StringSubstr = StringSubstr; |
| 784 to.StringSubstring = StringSubstring; | 759 to.StringSubstring = StringSubstring; |
| 785 }); | 760 }); |
| 786 | 761 |
| 787 }) | 762 }) |
| OLD | NEW |