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 */ |
11 (function(global, utils) { | 11 (function(global, utils) { |
12 | 12 |
13 "use strict"; | 13 "use strict"; |
14 | 14 |
15 %CheckIsBootstrapping(); | 15 %CheckIsBootstrapping(); |
16 | 16 |
17 // ------------------------------------------------------------------- | 17 // ------------------------------------------------------------------- |
18 // Imports | 18 // Imports |
19 | 19 |
20 var ArrayIndexOf; | 20 var ArrayIndexOf; |
21 var ArrayJoin; | 21 var ArrayJoin; |
22 var ArrayPush; | 22 var ArrayPush; |
| 23 var FLAG_intl_extra; |
23 var GlobalBoolean = global.Boolean; | 24 var GlobalBoolean = global.Boolean; |
24 var GlobalDate = global.Date; | 25 var GlobalDate = global.Date; |
25 var GlobalNumber = global.Number; | 26 var GlobalNumber = global.Number; |
26 var GlobalRegExp = global.RegExp; | 27 var GlobalRegExp = global.RegExp; |
27 var GlobalString = global.String; | 28 var GlobalString = global.String; |
28 var InstallFunctions = utils.InstallFunctions; | 29 var InstallFunctions = utils.InstallFunctions; |
29 var InstallGetter = utils.InstallGetter; | 30 var InstallGetter = utils.InstallGetter; |
30 var InternalArray = utils.InternalArray; | 31 var InternalArray = utils.InternalArray; |
31 var InternalRegExpMatch; | 32 var InternalRegExpMatch; |
32 var InternalRegExpReplace | 33 var InternalRegExpReplace |
(...skipping 24 matching lines...) Expand all Loading... |
57 MakeTypeError = from.MakeTypeError; | 58 MakeTypeError = from.MakeTypeError; |
58 InternalRegExpMatch = from.InternalRegExpMatch; | 59 InternalRegExpMatch = from.InternalRegExpMatch; |
59 InternalRegExpReplace = from.InternalRegExpReplace; | 60 InternalRegExpReplace = from.InternalRegExpReplace; |
60 StringIndexOf = from.StringIndexOf; | 61 StringIndexOf = from.StringIndexOf; |
61 StringLastIndexOf = from.StringLastIndexOf; | 62 StringLastIndexOf = from.StringLastIndexOf; |
62 StringSplit = from.StringSplit; | 63 StringSplit = from.StringSplit; |
63 StringSubstr = from.StringSubstr; | 64 StringSubstr = from.StringSubstr; |
64 StringSubstring = from.StringSubstring; | 65 StringSubstring = from.StringSubstring; |
65 }); | 66 }); |
66 | 67 |
| 68 utils.ImportFromExperimental(function(from) { |
| 69 FLAG_intl_extra = from.FLAG_intl_extra; |
| 70 }); |
| 71 |
67 // Utilities for definitions | 72 // Utilities for definitions |
68 | 73 |
69 function InstallFunction(object, name, func) { | 74 function InstallFunction(object, name, func) { |
70 InstallFunctions(object, DONT_ENUM, [name, func]); | 75 InstallFunctions(object, DONT_ENUM, [name, func]); |
71 } | 76 } |
72 | 77 |
73 | 78 |
74 function InstallConstructor(object, name, func) { | 79 function InstallConstructor(object, name, func) { |
75 %CheckIsBootstrapping(); | 80 %CheckIsBootstrapping(); |
76 SetFunctionName(func, name); | 81 SetFunctionName(func, name); |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 usage: {value: internalOptions.usage, writable: true} | 980 usage: {value: internalOptions.usage, writable: true} |
976 }); | 981 }); |
977 | 982 |
978 var internalCollator = %CreateCollator(requestedLocale, | 983 var internalCollator = %CreateCollator(requestedLocale, |
979 internalOptions, | 984 internalOptions, |
980 resolved); | 985 resolved); |
981 | 986 |
982 // Writable, configurable and enumerable are set to false by default. | 987 // Writable, configurable and enumerable are set to false by default. |
983 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); | 988 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); |
984 collator[resolvedSymbol] = resolved; | 989 collator[resolvedSymbol] = resolved; |
985 %object_define_property(collator, 'resolved', resolvedAccessor); | 990 if (FLAG_intl_extra) { |
| 991 %object_define_property(collator, 'resolved', resolvedAccessor); |
| 992 } |
986 | 993 |
987 return collator; | 994 return collator; |
988 } | 995 } |
989 | 996 |
990 | 997 |
991 /** | 998 /** |
992 * Constructs Intl.Collator object given optional locales and options | 999 * Constructs Intl.Collator object given optional locales and options |
993 * parameters. | 1000 * parameters. |
994 * | 1001 * |
995 * @constructor | 1002 * @constructor |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 | 1203 |
1197 var requestedLocale = locale.locale + extension; | 1204 var requestedLocale = locale.locale + extension; |
1198 var resolved = %object_define_properties({}, { | 1205 var resolved = %object_define_properties({}, { |
1199 currency: {writable: true}, | 1206 currency: {writable: true}, |
1200 currencyDisplay: {writable: true}, | 1207 currencyDisplay: {writable: true}, |
1201 locale: {writable: true}, | 1208 locale: {writable: true}, |
1202 maximumFractionDigits: {writable: true}, | 1209 maximumFractionDigits: {writable: true}, |
1203 minimumFractionDigits: {writable: true}, | 1210 minimumFractionDigits: {writable: true}, |
1204 minimumIntegerDigits: {writable: true}, | 1211 minimumIntegerDigits: {writable: true}, |
1205 numberingSystem: {writable: true}, | 1212 numberingSystem: {writable: true}, |
1206 pattern: patternAccessor, | |
1207 requestedLocale: {value: requestedLocale, writable: true}, | 1213 requestedLocale: {value: requestedLocale, writable: true}, |
1208 style: {value: internalOptions.style, writable: true}, | 1214 style: {value: internalOptions.style, writable: true}, |
1209 useGrouping: {writable: true} | 1215 useGrouping: {writable: true} |
1210 }); | 1216 }); |
1211 if (HAS_OWN_PROPERTY(internalOptions, 'minimumSignificantDigits')) { | 1217 if (HAS_OWN_PROPERTY(internalOptions, 'minimumSignificantDigits')) { |
1212 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); | 1218 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); |
1213 } | 1219 } |
1214 if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) { | 1220 if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) { |
1215 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); | 1221 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); |
1216 } | 1222 } |
1217 var formatter = %CreateNumberFormat(requestedLocale, | 1223 var formatter = %CreateNumberFormat(requestedLocale, |
1218 internalOptions, | 1224 internalOptions, |
1219 resolved); | 1225 resolved); |
1220 | 1226 |
1221 if (internalOptions.style === 'currency') { | 1227 if (internalOptions.style === 'currency') { |
1222 %object_define_property(resolved, 'currencyDisplay', | 1228 %object_define_property(resolved, 'currencyDisplay', |
1223 {value: currencyDisplay, writable: true}); | 1229 {value: currencyDisplay, writable: true}); |
1224 } | 1230 } |
1225 | 1231 |
1226 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); | 1232 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); |
1227 numberFormat[resolvedSymbol] = resolved; | 1233 numberFormat[resolvedSymbol] = resolved; |
1228 %object_define_property(numberFormat, 'resolved', resolvedAccessor); | 1234 if (FLAG_intl_extra) { |
| 1235 %object_define_property(resolved, 'pattern', patternAccessor); |
| 1236 %object_define_property(numberFormat, 'resolved', resolvedAccessor); |
| 1237 } |
1229 | 1238 |
1230 return numberFormat; | 1239 return numberFormat; |
1231 } | 1240 } |
1232 | 1241 |
1233 | 1242 |
1234 /** | 1243 /** |
1235 * Constructs Intl.NumberFormat object given optional locales and options | 1244 * Constructs Intl.NumberFormat object given optional locales and options |
1236 * parameters. | 1245 * parameters. |
1237 * | 1246 * |
1238 * @constructor | 1247 * @constructor |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 var number = TO_NUMBER(value) + 0; | 1333 var number = TO_NUMBER(value) + 0; |
1325 | 1334 |
1326 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), | 1335 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), |
1327 number); | 1336 number); |
1328 } | 1337 } |
1329 | 1338 |
1330 | 1339 |
1331 /** | 1340 /** |
1332 * Returns a Number that represents string value that was passed in. | 1341 * Returns a Number that represents string value that was passed in. |
1333 */ | 1342 */ |
1334 function parseNumber(formatter, value) { | 1343 function IntlParseNumber(formatter, value) { |
1335 return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), | 1344 return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), |
1336 GlobalString(value)); | 1345 GlobalString(value)); |
1337 } | 1346 } |
1338 | 1347 |
1339 | |
1340 AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); | 1348 AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); |
1341 AddBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); | |
1342 | 1349 |
1343 /** | 1350 /** |
1344 * Returns a string that matches LDML representation of the options object. | 1351 * Returns a string that matches LDML representation of the options object. |
1345 */ | 1352 */ |
1346 function toLDMLString(options) { | 1353 function toLDMLString(options) { |
1347 var getOption = getGetOption(options, 'dateformat'); | 1354 var getOption = getGetOption(options, 'dateformat'); |
1348 | 1355 |
1349 var ldmlString = ''; | 1356 var ldmlString = ''; |
1350 | 1357 |
1351 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']); | 1358 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 calendar: {writable: true}, | 1600 calendar: {writable: true}, |
1594 day: {writable: true}, | 1601 day: {writable: true}, |
1595 era: {writable: true}, | 1602 era: {writable: true}, |
1596 hour12: {writable: true}, | 1603 hour12: {writable: true}, |
1597 hour: {writable: true}, | 1604 hour: {writable: true}, |
1598 locale: {writable: true}, | 1605 locale: {writable: true}, |
1599 minute: {writable: true}, | 1606 minute: {writable: true}, |
1600 month: {writable: true}, | 1607 month: {writable: true}, |
1601 numberingSystem: {writable: true}, | 1608 numberingSystem: {writable: true}, |
1602 [patternSymbol]: {writable: true}, | 1609 [patternSymbol]: {writable: true}, |
1603 pattern: patternAccessor, | |
1604 requestedLocale: {value: requestedLocale, writable: true}, | 1610 requestedLocale: {value: requestedLocale, writable: true}, |
1605 second: {writable: true}, | 1611 second: {writable: true}, |
1606 timeZone: {writable: true}, | 1612 timeZone: {writable: true}, |
1607 timeZoneName: {writable: true}, | 1613 timeZoneName: {writable: true}, |
1608 tz: {value: tz, writable: true}, | 1614 tz: {value: tz, writable: true}, |
1609 weekday: {writable: true}, | 1615 weekday: {writable: true}, |
1610 year: {writable: true} | 1616 year: {writable: true} |
1611 }); | 1617 }); |
1612 | 1618 |
1613 var formatter = %CreateDateTimeFormat( | 1619 var formatter = %CreateDateTimeFormat( |
1614 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); | 1620 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); |
1615 | 1621 |
1616 if (resolved.timeZone === "Etc/Unknown") { | 1622 if (resolved.timeZone === "Etc/Unknown") { |
1617 throw MakeRangeError(kUnsupportedTimeZone, tz); | 1623 throw MakeRangeError(kUnsupportedTimeZone, tz); |
1618 } | 1624 } |
1619 | 1625 |
1620 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); | 1626 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); |
1621 dateFormat[resolvedSymbol] = resolved; | 1627 dateFormat[resolvedSymbol] = resolved; |
1622 %object_define_property(dateFormat, 'resolved', resolvedAccessor); | 1628 if (FLAG_intl_extra) { |
| 1629 %object_define_property(resolved, 'pattern', patternAccessor); |
| 1630 %object_define_property(dateFormat, 'resolved', resolvedAccessor); |
| 1631 } |
1623 | 1632 |
1624 return dateFormat; | 1633 return dateFormat; |
1625 } | 1634 } |
1626 | 1635 |
1627 | 1636 |
1628 /** | 1637 /** |
1629 * Constructs Intl.DateTimeFormat object given optional locales and options | 1638 * Constructs Intl.DateTimeFormat object given optional locales and options |
1630 * parameters. | 1639 * parameters. |
1631 * | 1640 * |
1632 * @constructor | 1641 * @constructor |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 new GlobalDate(dateMs)); | 1755 new GlobalDate(dateMs)); |
1747 } | 1756 } |
1748 | 1757 |
1749 | 1758 |
1750 /** | 1759 /** |
1751 * Returns a Date object representing the result of calling ToString(value) | 1760 * Returns a Date object representing the result of calling ToString(value) |
1752 * according to the effective locale and the formatting options of this | 1761 * according to the effective locale and the formatting options of this |
1753 * DateTimeFormat. | 1762 * DateTimeFormat. |
1754 * Returns undefined if date string cannot be parsed. | 1763 * Returns undefined if date string cannot be parsed. |
1755 */ | 1764 */ |
1756 function parseDate(formatter, value) { | 1765 function IntlParseDate(formatter, value) { |
1757 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), | 1766 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), |
1758 GlobalString(value)); | 1767 GlobalString(value)); |
1759 } | 1768 } |
1760 | 1769 |
1761 | 1770 |
1762 // 0 because date is optional argument. | 1771 // 0 because date is optional argument. |
1763 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); | 1772 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); |
1764 AddBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); | |
1765 | 1773 |
1766 | 1774 |
1767 /** | 1775 /** |
1768 * Returns canonical Area/Location(/Location) name, or throws an exception | 1776 * Returns canonical Area/Location(/Location) name, or throws an exception |
1769 * if the zone name is invalid IANA name. | 1777 * if the zone name is invalid IANA name. |
1770 */ | 1778 */ |
1771 function canonicalizeTimeZoneID(tzID) { | 1779 function canonicalizeTimeZoneID(tzID) { |
1772 // Skip undefined zones. | 1780 // Skip undefined zones. |
1773 if (IS_UNDEFINED(tzID)) { | 1781 if (IS_UNDEFINED(tzID)) { |
1774 return tzID; | 1782 return tzID; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1829 locale: {writable: true} | 1837 locale: {writable: true} |
1830 }); | 1838 }); |
1831 | 1839 |
1832 var internalIterator = %CreateBreakIterator(locale.locale, | 1840 var internalIterator = %CreateBreakIterator(locale.locale, |
1833 internalOptions, | 1841 internalOptions, |
1834 resolved); | 1842 resolved); |
1835 | 1843 |
1836 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', | 1844 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', |
1837 internalIterator); | 1845 internalIterator); |
1838 iterator[resolvedSymbol] = resolved; | 1846 iterator[resolvedSymbol] = resolved; |
1839 %object_define_property(iterator, 'resolved', resolvedAccessor); | 1847 if (FLAG_intl_extra) { |
| 1848 %object_define_property(iterator, 'resolved', resolvedAccessor); |
| 1849 } |
1840 | 1850 |
1841 return iterator; | 1851 return iterator; |
1842 } | 1852 } |
1843 | 1853 |
1844 | 1854 |
1845 /** | 1855 /** |
1846 * Constructs Intl.v8BreakIterator object given optional locales and options | 1856 * Constructs Intl.v8BreakIterator object given optional locales and options |
1847 * parameters. | 1857 * parameters. |
1848 * | 1858 * |
1849 * @constructor | 1859 * @constructor |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2138 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2129 } | 2139 } |
2130 | 2140 |
2131 var locales = arguments[0]; | 2141 var locales = arguments[0]; |
2132 var options = arguments[1]; | 2142 var options = arguments[1]; |
2133 return toLocaleDateTime( | 2143 return toLocaleDateTime( |
2134 this, locales, options, 'time', 'time', 'dateformattime'); | 2144 this, locales, options, 'time', 'time', 'dateformattime'); |
2135 } | 2145 } |
2136 ); | 2146 ); |
2137 | 2147 |
| 2148 utils.Export(function(to) { |
| 2149 to.AddBoundMethod = AddBoundMethod; |
| 2150 to.IntlParseDate = IntlParseDate; |
| 2151 to.IntlParseNumber = IntlParseNumber; |
| 2152 }); |
| 2153 |
2138 }) | 2154 }) |
OLD | NEW |