Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: src/js/i18n.js

Issue 2350963004: [builtins] Move StringIndexOf to a C++ builtin. (Closed)
Patch Set: Fix formatting errors Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-string.cc ('k') | src/js/string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 // ECMAScript 402 API implementation. 5 // ECMAScript 402 API implementation.
6 6
7 /** 7 /**
8 * Intl object is a single object that has some named properties, 8 * Intl object is a single object that has some named properties,
9 * all of which are constructors. 9 * all of which are constructors.
10 */ 10 */
(...skipping 15 matching lines...) Expand all
26 var InstallFunctions = utils.InstallFunctions; 26 var InstallFunctions = utils.InstallFunctions;
27 var InstallGetter = utils.InstallGetter; 27 var InstallGetter = utils.InstallGetter;
28 var InternalArray = utils.InternalArray; 28 var InternalArray = utils.InternalArray;
29 var InternalRegExpMatch; 29 var InternalRegExpMatch;
30 var InternalRegExpReplace 30 var InternalRegExpReplace
31 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); 31 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty");
32 var OverrideFunction = utils.OverrideFunction; 32 var OverrideFunction = utils.OverrideFunction;
33 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); 33 var patternSymbol = utils.ImportNow("intl_pattern_symbol");
34 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); 34 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol");
35 var SetFunctionName = utils.SetFunctionName; 35 var SetFunctionName = utils.SetFunctionName;
36 var StringIndexOf;
37 var StringSubstr = GlobalString.prototype.substr; 36 var StringSubstr = GlobalString.prototype.substr;
38 var StringSubstring = GlobalString.prototype.substring; 37 var StringSubstring = GlobalString.prototype.substring;
39 38
40 utils.Import(function(from) { 39 utils.Import(function(from) {
41 ArrayJoin = from.ArrayJoin; 40 ArrayJoin = from.ArrayJoin;
42 ArrayPush = from.ArrayPush; 41 ArrayPush = from.ArrayPush;
43 InternalRegExpMatch = from.InternalRegExpMatch; 42 InternalRegExpMatch = from.InternalRegExpMatch;
44 InternalRegExpReplace = from.InternalRegExpReplace; 43 InternalRegExpReplace = from.InternalRegExpReplace;
45 StringIndexOf = from.StringIndexOf;
46 }); 44 });
47 45
48 // Utilities for definitions 46 // Utilities for definitions
49 47
50 function InstallFunction(object, name, func) { 48 function InstallFunction(object, name, func) {
51 InstallFunctions(object, DONT_ENUM, [name, func]); 49 InstallFunctions(object, DONT_ENUM, [name, func]);
52 } 50 }
53 51
54 52
55 function InstallConstructor(object, name, func) { 53 function InstallConstructor(object, name, func) {
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 * 818 *
821 * Returns false if the language tag is invalid. 819 * Returns false if the language tag is invalid.
822 */ 820 */
823 function isStructuallyValidLanguageTag(locale) { 821 function isStructuallyValidLanguageTag(locale) {
824 // Check if it's well-formed, including grandfadered tags. 822 // Check if it's well-formed, including grandfadered tags.
825 if (IS_NULL(InternalRegExpMatch(GetLanguageTagRE(), locale))) { 823 if (IS_NULL(InternalRegExpMatch(GetLanguageTagRE(), locale))) {
826 return false; 824 return false;
827 } 825 }
828 826
829 // Just return if it's a x- form. It's all private. 827 // Just return if it's a x- form. It's all private.
830 if (%_Call(StringIndexOf, locale, 'x-') === 0) { 828 if (%StringIndexOf(locale, 'x-', 0) === 0) {
831 return true; 829 return true;
832 } 830 }
833 831
834 // Check if there are any duplicate variants or singletons (extensions). 832 // Check if there are any duplicate variants or singletons (extensions).
835 833
836 // Remove private use section. 834 // Remove private use section.
837 locale = %StringSplit(locale, '-x-', kMaxUint32)[0]; 835 locale = %StringSplit(locale, '-x-', kMaxUint32)[0];
838 836
839 // Skip language since it can match variant regex, so we start from 1. 837 // Skip language since it can match variant regex, so we start from 1.
840 // We are matching i-klingon here, but that's ok, since i-klingon-klingon 838 // We are matching i-klingon here, but that's ok, since i-klingon-klingon
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 if (IS_UNDEFINED(locales)) { 2049 if (IS_UNDEFINED(locales)) {
2052 language = GetDefaultICULocaleJS(); 2050 language = GetDefaultICULocaleJS();
2053 } else if (IS_STRING(locales)) { 2051 } else if (IS_STRING(locales)) {
2054 language = canonicalizeLanguageTag(locales); 2052 language = canonicalizeLanguageTag(locales);
2055 } else { 2053 } else {
2056 var locales = initializeLocaleList(locales); 2054 var locales = initializeLocaleList(locales);
2057 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS(); 2055 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS();
2058 } 2056 }
2059 2057
2060 // StringSplit is slower than this. 2058 // StringSplit is slower than this.
2061 var pos = %_Call(StringIndexOf, language, '-'); 2059 var pos = %StringIndexOf(language, '-', 0);
2062 if (pos != -1) { 2060 if (pos != -1) {
2063 language = %_Call(StringSubstring, language, 0, pos); 2061 language = %_Call(StringSubstring, language, 0, pos);
2064 } 2062 }
2065 2063
2066 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr']; 2064 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr'];
2067 var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0); 2065 var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0);
2068 if (langIndex == -1) { 2066 if (langIndex == -1) {
2069 // language-independent case conversion. 2067 // language-independent case conversion.
2070 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s); 2068 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s);
2071 } 2069 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2270 } 2268 }
2271 ); 2269 );
2272 2270
2273 %FunctionRemovePrototype(FormatDateToParts); 2271 %FunctionRemovePrototype(FormatDateToParts);
2274 2272
2275 utils.Export(function(to) { 2273 utils.Export(function(to) {
2276 to.FormatDateToParts = FormatDateToParts; 2274 to.FormatDateToParts = FormatDateToParts;
2277 }); 2275 });
2278 2276
2279 }) 2277 })
OLDNEW
« no previous file with comments | « src/builtins/builtins-string.cc ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698