OLD | NEW |
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 Loading... |
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; | 36 var StringSubstr; |
38 var StringSubstring; | 37 var StringSubstring; |
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 StringSubstr = from.StringSubstr; | 44 StringSubstr = from.StringSubstr; |
47 StringSubstring = from.StringSubstring; | 45 StringSubstring = from.StringSubstring; |
48 }); | 46 }); |
49 | 47 |
50 // Utilities for definitions | 48 // Utilities for definitions |
51 | 49 |
52 function InstallFunction(object, name, func) { | 50 function InstallFunction(object, name, func) { |
53 InstallFunctions(object, DONT_ENUM, [name, func]); | 51 InstallFunctions(object, DONT_ENUM, [name, func]); |
54 } | 52 } |
55 | 53 |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 * | 820 * |
823 * Returns false if the language tag is invalid. | 821 * Returns false if the language tag is invalid. |
824 */ | 822 */ |
825 function isStructuallyValidLanguageTag(locale) { | 823 function isStructuallyValidLanguageTag(locale) { |
826 // Check if it's well-formed, including grandfadered tags. | 824 // Check if it's well-formed, including grandfadered tags. |
827 if (IS_NULL(InternalRegExpMatch(GetLanguageTagRE(), locale))) { | 825 if (IS_NULL(InternalRegExpMatch(GetLanguageTagRE(), locale))) { |
828 return false; | 826 return false; |
829 } | 827 } |
830 | 828 |
831 // Just return if it's a x- form. It's all private. | 829 // Just return if it's a x- form. It's all private. |
832 if (%_Call(StringIndexOf, locale, 'x-') === 0) { | 830 if (%StringIndexOf(locale, 'x-', 0) === 0) { |
833 return true; | 831 return true; |
834 } | 832 } |
835 | 833 |
836 // Check if there are any duplicate variants or singletons (extensions). | 834 // Check if there are any duplicate variants or singletons (extensions). |
837 | 835 |
838 // Remove private use section. | 836 // Remove private use section. |
839 locale = %StringSplit(locale, '-x-', kMaxUint32)[0]; | 837 locale = %StringSplit(locale, '-x-', kMaxUint32)[0]; |
840 | 838 |
841 // Skip language since it can match variant regex, so we start from 1. | 839 // Skip language since it can match variant regex, so we start from 1. |
842 // We are matching i-klingon here, but that's ok, since i-klingon-klingon | 840 // 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 Loading... |
2053 if (IS_UNDEFINED(locales)) { | 2051 if (IS_UNDEFINED(locales)) { |
2054 language = GetDefaultICULocaleJS(); | 2052 language = GetDefaultICULocaleJS(); |
2055 } else if (IS_STRING(locales)) { | 2053 } else if (IS_STRING(locales)) { |
2056 language = canonicalizeLanguageTag(locales); | 2054 language = canonicalizeLanguageTag(locales); |
2057 } else { | 2055 } else { |
2058 var locales = initializeLocaleList(locales); | 2056 var locales = initializeLocaleList(locales); |
2059 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS(); | 2057 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS(); |
2060 } | 2058 } |
2061 | 2059 |
2062 // StringSplit is slower than this. | 2060 // StringSplit is slower than this. |
2063 var pos = %_Call(StringIndexOf, language, '-'); | 2061 var pos = %StringIndexOf(language, '-', 0); |
2064 if (pos != -1) { | 2062 if (pos != -1) { |
2065 language = %_Call(StringSubstring, language, 0, pos); | 2063 language = %_Call(StringSubstring, language, 0, pos); |
2066 } | 2064 } |
2067 | 2065 |
2068 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr']; | 2066 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr']; |
2069 var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0); | 2067 var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0); |
2070 if (langIndex == -1) { | 2068 if (langIndex == -1) { |
2071 // language-independent case conversion. | 2069 // language-independent case conversion. |
2072 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s); | 2070 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s); |
2073 } | 2071 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2272 } | 2270 } |
2273 ); | 2271 ); |
2274 | 2272 |
2275 %FunctionRemovePrototype(FormatDateToParts); | 2273 %FunctionRemovePrototype(FormatDateToParts); |
2276 | 2274 |
2277 utils.Export(function(to) { | 2275 utils.Export(function(to) { |
2278 to.FormatDateToParts = FormatDateToParts; | 2276 to.FormatDateToParts = FormatDateToParts; |
2279 }); | 2277 }); |
2280 | 2278 |
2281 }) | 2279 }) |
OLD | NEW |