| 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 23 matching lines...) Expand all Loading... |
| 34 var MakeError; | 34 var MakeError; |
| 35 var MakeRangeError; | 35 var MakeRangeError; |
| 36 var MakeTypeError; | 36 var MakeTypeError; |
| 37 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); | 37 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); |
| 38 var OverrideFunction = utils.OverrideFunction; | 38 var OverrideFunction = utils.OverrideFunction; |
| 39 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); | 39 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); |
| 40 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); | 40 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); |
| 41 var SetFunctionName = utils.SetFunctionName; | 41 var SetFunctionName = utils.SetFunctionName; |
| 42 var StringIndexOf; | 42 var StringIndexOf; |
| 43 var StringLastIndexOf; | 43 var StringLastIndexOf; |
| 44 var StringSplit; | |
| 45 var StringSubstr; | 44 var StringSubstr; |
| 46 var StringSubstring; | 45 var StringSubstring; |
| 47 | 46 |
| 48 utils.Import(function(from) { | 47 utils.Import(function(from) { |
| 49 ArrayIndexOf = from.ArrayIndexOf; | 48 ArrayIndexOf = from.ArrayIndexOf; |
| 50 ArrayJoin = from.ArrayJoin; | 49 ArrayJoin = from.ArrayJoin; |
| 51 ArrayPush = from.ArrayPush; | 50 ArrayPush = from.ArrayPush; |
| 52 IsNaN = from.IsNaN; | 51 IsNaN = from.IsNaN; |
| 53 MakeError = from.MakeError; | 52 MakeError = from.MakeError; |
| 54 MakeRangeError = from.MakeRangeError; | 53 MakeRangeError = from.MakeRangeError; |
| 55 MakeTypeError = from.MakeTypeError; | 54 MakeTypeError = from.MakeTypeError; |
| 56 InternalRegExpMatch = from.InternalRegExpMatch; | 55 InternalRegExpMatch = from.InternalRegExpMatch; |
| 57 InternalRegExpReplace = from.InternalRegExpReplace; | 56 InternalRegExpReplace = from.InternalRegExpReplace; |
| 58 StringIndexOf = from.StringIndexOf; | 57 StringIndexOf = from.StringIndexOf; |
| 59 StringLastIndexOf = from.StringLastIndexOf; | 58 StringLastIndexOf = from.StringLastIndexOf; |
| 60 StringSplit = from.StringSplit; | |
| 61 StringSubstr = from.StringSubstr; | 59 StringSubstr = from.StringSubstr; |
| 62 StringSubstring = from.StringSubstring; | 60 StringSubstring = from.StringSubstring; |
| 63 }); | 61 }); |
| 64 | 62 |
| 65 utils.ImportFromExperimental(function(from) { | 63 utils.ImportFromExperimental(function(from) { |
| 66 FLAG_intl_extra = from.FLAG_intl_extra; | 64 FLAG_intl_extra = from.FLAG_intl_extra; |
| 67 }); | 65 }); |
| 68 | 66 |
| 69 // Utilities for definitions | 67 // Utilities for definitions |
| 70 | 68 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 return lookupMatcher(service, requestedLocales); | 468 return lookupMatcher(service, requestedLocales); |
| 471 } | 469 } |
| 472 | 470 |
| 473 | 471 |
| 474 /** | 472 /** |
| 475 * Parses Unicode extension into key - value map. | 473 * Parses Unicode extension into key - value map. |
| 476 * Returns empty object if the extension string is invalid. | 474 * Returns empty object if the extension string is invalid. |
| 477 * We are not concerned with the validity of the values at this point. | 475 * We are not concerned with the validity of the values at this point. |
| 478 */ | 476 */ |
| 479 function parseExtension(extension) { | 477 function parseExtension(extension) { |
| 480 var extensionSplit = %_Call(StringSplit, extension, '-'); | 478 var extensionSplit = %StringSplit(extension, '-', kMaxUint32); |
| 481 | 479 |
| 482 // Assume ['', 'u', ...] input, but don't throw. | 480 // Assume ['', 'u', ...] input, but don't throw. |
| 483 if (extensionSplit.length <= 2 || | 481 if (extensionSplit.length <= 2 || |
| 484 (extensionSplit[0] !== '' && extensionSplit[1] !== 'u')) { | 482 (extensionSplit[0] !== '' && extensionSplit[1] !== 'u')) { |
| 485 return {}; | 483 return {}; |
| 486 } | 484 } |
| 487 | 485 |
| 488 // Key is {2}alphanum, value is {3,8}alphanum. | 486 // Key is {2}alphanum, value is {3,8}alphanum. |
| 489 // Some keys may not have explicit values (booleans). | 487 // Some keys may not have explicit values (booleans). |
| 490 var extensionMap = {}; | 488 var extensionMap = {}; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 */ | 702 */ |
| 705 function toTitleCaseTimezoneLocation(location) { | 703 function toTitleCaseTimezoneLocation(location) { |
| 706 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location) | 704 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location) |
| 707 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, location); | 705 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, location); |
| 708 | 706 |
| 709 var result = toTitleCaseWord(match[1]); | 707 var result = toTitleCaseWord(match[1]); |
| 710 if (!IS_UNDEFINED(match[2]) && 2 < match.length) { | 708 if (!IS_UNDEFINED(match[2]) && 2 < match.length) { |
| 711 // The first character is a separator, '_' or '-'. | 709 // The first character is a separator, '_' or '-'. |
| 712 // None of IANA zone names has both '_' and '-'. | 710 // None of IANA zone names has both '_' and '-'. |
| 713 var separator = %_Call(StringSubstring, match[2], 0, 1); | 711 var separator = %_Call(StringSubstring, match[2], 0, 1); |
| 714 var parts = %_Call(StringSplit, match[2], separator); | 712 var parts = %StringSplit(match[2], separator, kMaxUint32); |
| 715 for (var i = 1; i < parts.length; i++) { | 713 for (var i = 1; i < parts.length; i++) { |
| 716 var part = parts[i] | 714 var part = parts[i] |
| 717 var lowercasedPart = %StringToLowerCase(part); | 715 var lowercasedPart = %StringToLowerCase(part); |
| 718 result = result + separator + | 716 result = result + separator + |
| 719 ((lowercasedPart !== 'es' && | 717 ((lowercasedPart !== 'es' && |
| 720 lowercasedPart !== 'of' && lowercasedPart !== 'au') ? | 718 lowercasedPart !== 'of' && lowercasedPart !== 'au') ? |
| 721 toTitleCaseWord(part) : lowercasedPart); | 719 toTitleCaseWord(part) : lowercasedPart); |
| 722 } | 720 } |
| 723 } | 721 } |
| 724 return result; | 722 return result; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 } | 803 } |
| 806 | 804 |
| 807 // Just return if it's a x- form. It's all private. | 805 // Just return if it's a x- form. It's all private. |
| 808 if (%_Call(StringIndexOf, locale, 'x-') === 0) { | 806 if (%_Call(StringIndexOf, locale, 'x-') === 0) { |
| 809 return true; | 807 return true; |
| 810 } | 808 } |
| 811 | 809 |
| 812 // Check if there are any duplicate variants or singletons (extensions). | 810 // Check if there are any duplicate variants or singletons (extensions). |
| 813 | 811 |
| 814 // Remove private use section. | 812 // Remove private use section. |
| 815 locale = %_Call(StringSplit, locale, '-x-')[0]; | 813 locale = %StringSplit(locale, '-x-', kMaxUint32)[0]; |
| 816 | 814 |
| 817 // Skip language since it can match variant regex, so we start from 1. | 815 // Skip language since it can match variant regex, so we start from 1. |
| 818 // We are matching i-klingon here, but that's ok, since i-klingon-klingon | 816 // We are matching i-klingon here, but that's ok, since i-klingon-klingon |
| 819 // is not valid and would fail LANGUAGE_TAG_RE test. | 817 // is not valid and would fail LANGUAGE_TAG_RE test. |
| 820 var variants = new InternalArray(); | 818 var variants = new InternalArray(); |
| 821 var extensions = new InternalArray(); | 819 var extensions = new InternalArray(); |
| 822 var parts = %_Call(StringSplit, locale, '-'); | 820 var parts = %StringSplit(locale, '-', kMaxUint32); |
| 823 for (var i = 1; i < parts.length; i++) { | 821 for (var i = 1; i < parts.length; i++) { |
| 824 var value = parts[i]; | 822 var value = parts[i]; |
| 825 if (!IS_NULL(InternalRegExpMatch(GetLanguageVariantRE(), value)) && | 823 if (!IS_NULL(InternalRegExpMatch(GetLanguageVariantRE(), value)) && |
| 826 extensions.length === 0) { | 824 extensions.length === 0) { |
| 827 if (%_Call(ArrayIndexOf, variants, value) === -1) { | 825 if (%_Call(ArrayIndexOf, variants, value) === -1) { |
| 828 %_Call(ArrayPush, variants, value); | 826 %_Call(ArrayPush, variants, value); |
| 829 } else { | 827 } else { |
| 830 return false; | 828 return false; |
| 831 } | 829 } |
| 832 } | 830 } |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 | 1796 |
| 1799 // We expect only _, '-' and / beside ASCII letters. | 1797 // We expect only _, '-' and / beside ASCII letters. |
| 1800 // All inputs should conform to Area/Location(/Location)* from now on. | 1798 // All inputs should conform to Area/Location(/Location)* from now on. |
| 1801 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID); | 1799 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID); |
| 1802 if (IS_NULL(match)) throw MakeRangeError(kExpectedTimezoneID, tzID); | 1800 if (IS_NULL(match)) throw MakeRangeError(kExpectedTimezoneID, tzID); |
| 1803 | 1801 |
| 1804 var result = toTitleCaseTimezoneLocation(match[1]) + '/' + | 1802 var result = toTitleCaseTimezoneLocation(match[1]) + '/' + |
| 1805 toTitleCaseTimezoneLocation(match[2]); | 1803 toTitleCaseTimezoneLocation(match[2]); |
| 1806 | 1804 |
| 1807 if (!IS_UNDEFINED(match[3]) && 3 < match.length) { | 1805 if (!IS_UNDEFINED(match[3]) && 3 < match.length) { |
| 1808 var locations = %_Call(StringSplit, match[3], '/'); | 1806 var locations = %StringSplit(match[3], '/', kMaxUint32); |
| 1809 // The 1st element is empty. Starts with i=1. | 1807 // The 1st element is empty. Starts with i=1. |
| 1810 for (var i = 1; i < locations.length; i++) { | 1808 for (var i = 1; i < locations.length; i++) { |
| 1811 result = result + '/' + toTitleCaseTimezoneLocation(locations[i]); | 1809 result = result + '/' + toTitleCaseTimezoneLocation(locations[i]); |
| 1812 } | 1810 } |
| 1813 } | 1811 } |
| 1814 | 1812 |
| 1815 return result; | 1813 return result; |
| 1816 } | 1814 } |
| 1817 | 1815 |
| 1818 /** | 1816 /** |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2251 } | 2249 } |
| 2252 ); | 2250 ); |
| 2253 | 2251 |
| 2254 utils.Export(function(to) { | 2252 utils.Export(function(to) { |
| 2255 to.AddBoundMethod = AddBoundMethod; | 2253 to.AddBoundMethod = AddBoundMethod; |
| 2256 to.IntlParseDate = IntlParseDate; | 2254 to.IntlParseDate = IntlParseDate; |
| 2257 to.IntlParseNumber = IntlParseNumber; | 2255 to.IntlParseNumber = IntlParseNumber; |
| 2258 }); | 2256 }); |
| 2259 | 2257 |
| 2260 }) | 2258 }) |
| OLD | NEW |