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 28 matching lines...) Expand all Loading... |
39 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); | 39 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); |
40 var OverrideFunction = utils.OverrideFunction; | 40 var OverrideFunction = utils.OverrideFunction; |
41 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); | 41 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); |
42 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); | 42 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); |
43 var SetFunctionName = utils.SetFunctionName; | 43 var SetFunctionName = utils.SetFunctionName; |
44 var StringIndexOf; | 44 var StringIndexOf; |
45 var StringLastIndexOf; | 45 var StringLastIndexOf; |
46 var StringSplit; | 46 var StringSplit; |
47 var StringSubstr; | 47 var StringSubstr; |
48 var StringSubstring; | 48 var StringSubstring; |
| 49 var StringToLowerCase = GlobalString.prototype.toLowerCase; |
| 50 var StringToUpperCase = GlobalString.prototype.toUpperCase; |
49 | 51 |
50 utils.Import(function(from) { | 52 utils.Import(function(from) { |
51 ArrayIndexOf = from.ArrayIndexOf; | 53 ArrayIndexOf = from.ArrayIndexOf; |
52 ArrayJoin = from.ArrayJoin; | 54 ArrayJoin = from.ArrayJoin; |
53 ArrayPush = from.ArrayPush; | 55 ArrayPush = from.ArrayPush; |
54 IsFinite = from.IsFinite; | 56 IsFinite = from.IsFinite; |
55 IsNaN = from.IsNaN; | 57 IsNaN = from.IsNaN; |
56 MakeError = from.MakeError; | 58 MakeError = from.MakeError; |
57 MakeRangeError = from.MakeRangeError; | 59 MakeRangeError = from.MakeRangeError; |
58 MakeTypeError = from.MakeTypeError; | 60 MakeTypeError = from.MakeTypeError; |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 if (!IS_UNDEFINED(value)) { | 688 if (!IS_UNDEFINED(value)) { |
687 defineWECProperty(object, property, value); | 689 defineWECProperty(object, property, value); |
688 } | 690 } |
689 } | 691 } |
690 | 692 |
691 | 693 |
692 /** | 694 /** |
693 * Returns titlecased word, aMeRricA -> America. | 695 * Returns titlecased word, aMeRricA -> America. |
694 */ | 696 */ |
695 function toTitleCaseWord(word) { | 697 function toTitleCaseWord(word) { |
696 return %StringToUpperCase(%_Call(StringSubstr, word, 0, 1)) + | 698 return %_Call(StringToUpperCase, %_Call(StringSubstr, word, 0, 1)) + |
697 %StringToLowerCase(%_Call(StringSubstr, word, 1)); | 699 %_Call(StringToLowerCase, %_Call(StringSubstr, word, 1)); |
698 } | 700 } |
699 | 701 |
700 /** | 702 /** |
701 * Returns titlecased location, bueNos_airES -> Buenos_Aires | 703 * Returns titlecased location, bueNos_airES -> Buenos_Aires |
702 * or ho_cHi_minH -> Ho_Chi_Minh. It is locale-agnostic and only | 704 * or ho_cHi_minH -> Ho_Chi_Minh. It is locale-agnostic and only |
703 * deals with ASCII only characters. | 705 * deals with ASCII only characters. |
704 * 'of', 'au' and 'es' are special-cased and lowercased. | 706 * 'of', 'au' and 'es' are special-cased and lowercased. |
705 */ | 707 */ |
706 function toTitleCaseTimezoneLocation(location) { | 708 function toTitleCaseTimezoneLocation(location) { |
707 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location) | 709 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location) |
708 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, location); | 710 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, location); |
709 | 711 |
710 var result = toTitleCaseWord(match[1]); | 712 var result = toTitleCaseWord(match[1]); |
711 if (!IS_UNDEFINED(match[2]) && 2 < match.length) { | 713 if (!IS_UNDEFINED(match[2]) && 2 < match.length) { |
712 // The first character is a separator, '_' or '-'. | 714 // The first character is a separator, '_' or '-'. |
713 // None of IANA zone names has both '_' and '-'. | 715 // None of IANA zone names has both '_' and '-'. |
714 var separator = %_Call(StringSubstring, match[2], 0, 1); | 716 var separator = %_Call(StringSubstring, match[2], 0, 1); |
715 var parts = %_Call(StringSplit, match[2], separator); | 717 var parts = %_Call(StringSplit, match[2], separator); |
716 for (var i = 1; i < parts.length; i++) { | 718 for (var i = 1; i < parts.length; i++) { |
717 var part = parts[i] | 719 var part = parts[i] |
718 var lowercasedPart = %StringToLowerCase(part); | 720 var lowercasedPart = %_Call(StringToLowerCase, part); |
719 result = result + separator + | 721 result = result + separator + |
720 ((lowercasedPart !== 'es' && | 722 ((lowercasedPart !== 'es' && |
721 lowercasedPart !== 'of' && lowercasedPart !== 'au') ? | 723 lowercasedPart !== 'of' && lowercasedPart !== 'au') ? |
722 toTitleCaseWord(part) : lowercasedPart); | 724 toTitleCaseWord(part) : lowercasedPart); |
723 } | 725 } |
724 } | 726 } |
725 return result; | 727 return result; |
726 } | 728 } |
727 | 729 |
728 /** | 730 /** |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 throw MakeRangeError(kInvalidCurrencyCode, currency); | 1150 throw MakeRangeError(kInvalidCurrencyCode, currency); |
1149 } | 1151 } |
1150 | 1152 |
1151 if (internalOptions.style === 'currency' && IS_UNDEFINED(currency)) { | 1153 if (internalOptions.style === 'currency' && IS_UNDEFINED(currency)) { |
1152 throw MakeTypeError(kCurrencyCode); | 1154 throw MakeTypeError(kCurrencyCode); |
1153 } | 1155 } |
1154 | 1156 |
1155 var currencyDisplay = getOption( | 1157 var currencyDisplay = getOption( |
1156 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol'); | 1158 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol'); |
1157 if (internalOptions.style === 'currency') { | 1159 if (internalOptions.style === 'currency') { |
1158 defineWEProperty(internalOptions, 'currency', %StringToUpperCase(currency)); | 1160 defineWEProperty(internalOptions, 'currency', |
| 1161 %_Call(StringToUpperCase, currency)); |
1159 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay); | 1162 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay); |
1160 } | 1163 } |
1161 | 1164 |
1162 // Digit ranges. | 1165 // Digit ranges. |
1163 var mnid = getNumberOption(options, 'minimumIntegerDigits', 1, 21, 1); | 1166 var mnid = getNumberOption(options, 'minimumIntegerDigits', 1, 21, 1); |
1164 defineWEProperty(internalOptions, 'minimumIntegerDigits', mnid); | 1167 defineWEProperty(internalOptions, 'minimumIntegerDigits', mnid); |
1165 | 1168 |
1166 var mnfd = options['minimumFractionDigits']; | 1169 var mnfd = options['minimumFractionDigits']; |
1167 var mxfd = options['maximumFractionDigits']; | 1170 var mxfd = options['maximumFractionDigits']; |
1168 if (!IS_UNDEFINED(mnfd) || internalOptions.style !== 'currency') { | 1171 if (!IS_UNDEFINED(mnfd) || internalOptions.style !== 'currency') { |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 * Returns canonical Area/Location(/Location) name, or throws an exception | 1785 * Returns canonical Area/Location(/Location) name, or throws an exception |
1783 * if the zone name is invalid IANA name. | 1786 * if the zone name is invalid IANA name. |
1784 */ | 1787 */ |
1785 function canonicalizeTimeZoneID(tzID) { | 1788 function canonicalizeTimeZoneID(tzID) { |
1786 // Skip undefined zones. | 1789 // Skip undefined zones. |
1787 if (IS_UNDEFINED(tzID)) { | 1790 if (IS_UNDEFINED(tzID)) { |
1788 return tzID; | 1791 return tzID; |
1789 } | 1792 } |
1790 | 1793 |
1791 // Special case handling (UTC, GMT). | 1794 // Special case handling (UTC, GMT). |
1792 var upperID = %StringToUpperCase(tzID); | 1795 var upperID = %_Call(StringToUpperCase, tzID); |
1793 if (upperID === 'UTC' || upperID === 'GMT' || | 1796 if (upperID === 'UTC' || upperID === 'GMT' || |
1794 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') { | 1797 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') { |
1795 return 'UTC'; | 1798 return 'UTC'; |
1796 } | 1799 } |
1797 | 1800 |
1798 // TODO(jshin): Add support for Etc/GMT[+-]([1-9]|1[0-2]) | 1801 // TODO(jshin): Add support for Etc/GMT[+-]([1-9]|1[0-2]) |
1799 | 1802 |
1800 // We expect only _, '-' and / beside ASCII letters. | 1803 // We expect only _, '-' and / beside ASCII letters. |
1801 // All inputs should conform to Area/Location(/Location)* from now on. | 1804 // All inputs should conform to Area/Location(/Location)* from now on. |
1802 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID); | 1805 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2252 } | 2255 } |
2253 ); | 2256 ); |
2254 | 2257 |
2255 utils.Export(function(to) { | 2258 utils.Export(function(to) { |
2256 to.AddBoundMethod = AddBoundMethod; | 2259 to.AddBoundMethod = AddBoundMethod; |
2257 to.IntlParseDate = IntlParseDate; | 2260 to.IntlParseDate = IntlParseDate; |
2258 to.IntlParseNumber = IntlParseNumber; | 2261 to.IntlParseNumber = IntlParseNumber; |
2259 }); | 2262 }); |
2260 | 2263 |
2261 }) | 2264 }) |
OLD | NEW |