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 |
121 // This has the same size as the RegExpLastMatchInfo array, and can be used | 145 // This has the same size as the RegExpLastMatchInfo array, and can be used |
122 // for functions that expect that structure to be returned. It is used when | 146 // for functions that expect that structure to be returned. It is used when |
123 // the needle is a string rather than a regexp. In this case we can't update | 147 // the needle is a string rather than a regexp. In this case we can't update |
124 // lastMatchArray without erroneously affecting the properties on the global | 148 // lastMatchArray without erroneously affecting the properties on the global |
125 // RegExp object. | 149 // RegExp object. |
126 var reusableMatchInfo = [2, "", "", -1, -1]; | 150 var reusableMatchInfo = [2, "", "", -1, -1]; |
127 | 151 |
128 | 152 |
129 // ES6, section 21.1.3.14 | 153 // ES6, section 21.1.3.14 |
130 function StringReplace(search, replace) { | 154 function StringReplace(search, replace) { |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 // Set up the non-enumerable functions on the String prototype object. | 733 // Set up the non-enumerable functions on the String prototype object. |
710 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 734 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
711 "codePointAt", StringCodePointAt, | 735 "codePointAt", StringCodePointAt, |
712 "concat", StringConcat, | 736 "concat", StringConcat, |
713 "endsWith", StringEndsWith, | 737 "endsWith", StringEndsWith, |
714 "includes", StringIncludes, | 738 "includes", StringIncludes, |
715 "indexOf", StringIndexOf, | 739 "indexOf", StringIndexOf, |
716 "lastIndexOf", StringLastIndexOf, | 740 "lastIndexOf", StringLastIndexOf, |
717 "localeCompare", StringLocaleCompareJS, | 741 "localeCompare", StringLocaleCompareJS, |
718 "match", StringMatchJS, | 742 "match", StringMatchJS, |
| 743 "normalize", StringNormalize, |
719 "repeat", StringRepeat, | 744 "repeat", StringRepeat, |
720 "replace", StringReplace, | 745 "replace", StringReplace, |
721 "search", StringSearch, | 746 "search", StringSearch, |
722 "slice", StringSlice, | 747 "slice", StringSlice, |
723 "split", StringSplitJS, | 748 "split", StringSplitJS, |
724 "substring", StringSubstring, | 749 "substring", StringSubstring, |
725 "substr", StringSubstr, | 750 "substr", StringSubstr, |
726 "startsWith", StringStartsWith, | 751 "startsWith", StringStartsWith, |
727 "toLowerCase", StringToLowerCaseJS, | 752 "toLowerCase", StringToLowerCaseJS, |
728 "toLocaleLowerCase", StringToLocaleLowerCase, | 753 "toLocaleLowerCase", StringToLocaleLowerCase, |
(...skipping 24 matching lines...) Expand all Loading... |
753 to.StringLastIndexOf = StringLastIndexOf; | 778 to.StringLastIndexOf = StringLastIndexOf; |
754 to.StringMatch = StringMatchJS; | 779 to.StringMatch = StringMatchJS; |
755 to.StringReplace = StringReplace; | 780 to.StringReplace = StringReplace; |
756 to.StringSlice = StringSlice; | 781 to.StringSlice = StringSlice; |
757 to.StringSplit = StringSplitJS; | 782 to.StringSplit = StringSplitJS; |
758 to.StringSubstr = StringSubstr; | 783 to.StringSubstr = StringSubstr; |
759 to.StringSubstring = StringSubstring; | 784 to.StringSubstring = StringSubstring; |
760 }); | 785 }); |
761 | 786 |
762 }) | 787 }) |
OLD | NEW |