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 16 matching lines...) Expand all Loading... |
27 var InstallFunctions = utils.InstallFunctions; | 27 var InstallFunctions = utils.InstallFunctions; |
28 var InstallGetter = utils.InstallGetter; | 28 var InstallGetter = utils.InstallGetter; |
29 var InternalArray = utils.InternalArray; | 29 var InternalArray = utils.InternalArray; |
30 var InternalRegExpMatch; | 30 var InternalRegExpMatch; |
31 var InternalRegExpReplace | 31 var InternalRegExpReplace |
32 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); | 32 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); |
33 var OverrideFunction = utils.OverrideFunction; | 33 var OverrideFunction = utils.OverrideFunction; |
34 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); | 34 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); |
35 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); | 35 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); |
36 var SetFunctionName = utils.SetFunctionName; | 36 var SetFunctionName = utils.SetFunctionName; |
37 var StringIndexOf; | |
38 var StringSubstr; | 37 var StringSubstr; |
39 var StringSubstring; | 38 var StringSubstring; |
40 | 39 |
41 utils.Import(function(from) { | 40 utils.Import(function(from) { |
42 ArrayJoin = from.ArrayJoin; | 41 ArrayJoin = from.ArrayJoin; |
43 ArrayPush = from.ArrayPush; | 42 ArrayPush = from.ArrayPush; |
44 InternalRegExpMatch = from.InternalRegExpMatch; | 43 InternalRegExpMatch = from.InternalRegExpMatch; |
45 InternalRegExpReplace = from.InternalRegExpReplace; | 44 InternalRegExpReplace = from.InternalRegExpReplace; |
46 StringIndexOf = from.StringIndexOf; | |
47 StringSubstr = from.StringSubstr; | 45 StringSubstr = from.StringSubstr; |
48 StringSubstring = from.StringSubstring; | 46 StringSubstring = from.StringSubstring; |
49 }); | 47 }); |
50 | 48 |
51 utils.ImportFromExperimental(function(from) { | 49 utils.ImportFromExperimental(function(from) { |
52 FLAG_intl_extra = from.FLAG_intl_extra; | 50 FLAG_intl_extra = from.FLAG_intl_extra; |
53 }); | 51 }); |
54 | 52 |
55 // Utilities for definitions | 53 // Utilities for definitions |
56 | 54 |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 * | 825 * |
828 * Returns false if the language tag is invalid. | 826 * Returns false if the language tag is invalid. |
829 */ | 827 */ |
830 function isStructuallyValidLanguageTag(locale) { | 828 function isStructuallyValidLanguageTag(locale) { |
831 // Check if it's well-formed, including grandfadered tags. | 829 // Check if it's well-formed, including grandfadered tags. |
832 if (IS_NULL(InternalRegExpMatch(GetLanguageTagRE(), locale))) { | 830 if (IS_NULL(InternalRegExpMatch(GetLanguageTagRE(), locale))) { |
833 return false; | 831 return false; |
834 } | 832 } |
835 | 833 |
836 // Just return if it's a x- form. It's all private. | 834 // Just return if it's a x- form. It's all private. |
837 if (%_Call(StringIndexOf, locale, 'x-') === 0) { | 835 if (%StringIndexOf(locale, 'x-', 0) === 0) { |
838 return true; | 836 return true; |
839 } | 837 } |
840 | 838 |
841 // Check if there are any duplicate variants or singletons (extensions). | 839 // Check if there are any duplicate variants or singletons (extensions). |
842 | 840 |
843 // Remove private use section. | 841 // Remove private use section. |
844 locale = %StringSplit(locale, '-x-', kMaxUint32)[0]; | 842 locale = %StringSplit(locale, '-x-', kMaxUint32)[0]; |
845 | 843 |
846 // Skip language since it can match variant regex, so we start from 1. | 844 // Skip language since it can match variant regex, so we start from 1. |
847 // We are matching i-klingon here, but that's ok, since i-klingon-klingon | 845 // We are matching i-klingon here, but that's ok, since i-klingon-klingon |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 if (IS_UNDEFINED(locales)) { | 2090 if (IS_UNDEFINED(locales)) { |
2093 language = GetDefaultICULocaleJS(); | 2091 language = GetDefaultICULocaleJS(); |
2094 } else if (IS_STRING(locales)) { | 2092 } else if (IS_STRING(locales)) { |
2095 language = canonicalizeLanguageTag(locales); | 2093 language = canonicalizeLanguageTag(locales); |
2096 } else { | 2094 } else { |
2097 var locales = initializeLocaleList(locales); | 2095 var locales = initializeLocaleList(locales); |
2098 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS(); | 2096 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS(); |
2099 } | 2097 } |
2100 | 2098 |
2101 // StringSplit is slower than this. | 2099 // StringSplit is slower than this. |
2102 var pos = %_Call(StringIndexOf, language, '-'); | 2100 var pos = %StringIndexOf(language, '-', 0); |
2103 if (pos != -1) { | 2101 if (pos != -1) { |
2104 language = %_Call(StringSubstring, language, 0, pos); | 2102 language = %_Call(StringSubstring, language, 0, pos); |
2105 } | 2103 } |
2106 | 2104 |
2107 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr']; | 2105 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr']; |
2108 var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0); | 2106 var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0); |
2109 if (langIndex == -1) { | 2107 if (langIndex == -1) { |
2110 // language-independent case conversion. | 2108 // language-independent case conversion. |
2111 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s); | 2109 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s); |
2112 } | 2110 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2314 %FunctionRemovePrototype(FormatDateToParts); | 2312 %FunctionRemovePrototype(FormatDateToParts); |
2315 | 2313 |
2316 utils.Export(function(to) { | 2314 utils.Export(function(to) { |
2317 to.AddBoundMethod = AddBoundMethod; | 2315 to.AddBoundMethod = AddBoundMethod; |
2318 to.FormatDateToParts = FormatDateToParts; | 2316 to.FormatDateToParts = FormatDateToParts; |
2319 to.IntlParseDate = IntlParseDate; | 2317 to.IntlParseDate = IntlParseDate; |
2320 to.IntlParseNumber = IntlParseNumber; | 2318 to.IntlParseNumber = IntlParseNumber; |
2321 }); | 2319 }); |
2322 | 2320 |
2323 }) | 2321 }) |
OLD | NEW |