Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: src/js/i18n.js

Issue 2601833002: [intl] Remove indirection in Intl objects (Closed)
Patch Set: Fix a dcheck Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/i18n.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 receiver[internalName] = boundMethod; 89 receiver[internalName] = boundMethod;
90 } 90 }
91 return receiver[internalName]; 91 return receiver[internalName];
92 }); 92 });
93 93
94 %FunctionRemovePrototype(getter); 94 %FunctionRemovePrototype(getter);
95 %DefineGetterPropertyUnchecked(obj.prototype, methodName, getter, DONT_ENUM); 95 %DefineGetterPropertyUnchecked(obj.prototype, methodName, getter, DONT_ENUM);
96 %SetNativeFlag(getter); 96 %SetNativeFlag(getter);
97 } 97 }
98 98
99 function IntlConstruct(receiver, constructor, initializer, newTarget, args, 99 function IntlConstruct(receiver, constructor, create, newTarget, args,
100 compat) { 100 compat) {
101 var locales = args[0]; 101 var locales = args[0];
102 var options = args[1]; 102 var options = args[1];
103 103
104 if (IS_UNDEFINED(newTarget)) { 104 if (IS_UNDEFINED(newTarget)) {
105 if (compat && receiver instanceof constructor) { 105 if (compat && receiver instanceof constructor) {
106 let success = %object_define_property(receiver, IntlFallbackSymbol, 106 let success = %object_define_property(receiver, IntlFallbackSymbol,
107 { value: new constructor(locales, options) }); 107 { value: new constructor(locales, options) });
108 if (!success) { 108 if (!success) {
109 throw %make_type_error(kReinitializeIntl, constructor); 109 throw %make_type_error(kReinitializeIntl, constructor);
110 } 110 }
111 return receiver; 111 return receiver;
112 } 112 }
113 113
114 return new constructor(locales, options); 114 return new constructor(locales, options);
115 } 115 }
116 116
117 return initializer(receiver, locales, options); 117 return create(locales, options);
118 } 118 }
119 119
120 120
121 121
122 function Unwrap(receiver, typename, constructor, method, compat) { 122 function Unwrap(receiver, typename, constructor, method, compat) {
123 if (!%IsInitializedIntlObjectOfType(receiver, typename)) { 123 if (!%IsInitializedIntlObjectOfType(receiver, typename)) {
124 if (compat && receiver instanceof constructor) { 124 if (compat && receiver instanceof constructor) {
125 let fallback = receiver[IntlFallbackSymbol]; 125 let fallback = receiver[IntlFallbackSymbol];
126 if (%IsInitializedIntlObjectOfType(fallback, typename)) { 126 if (%IsInitializedIntlObjectOfType(fallback, typename)) {
127 return fallback; 127 return fallback;
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 // ECMA 402 section 8.2.1 943 // ECMA 402 section 8.2.1
944 InstallFunction(GlobalIntl, 'getCanonicalLocales', function(locales) { 944 InstallFunction(GlobalIntl, 'getCanonicalLocales', function(locales) {
945 return makeArray(canonicalizeLocaleList(locales)); 945 return makeArray(canonicalizeLocaleList(locales));
946 } 946 }
947 ); 947 );
948 948
949 /** 949 /**
950 * Initializes the given object so it's a valid Collator instance. 950 * Initializes the given object so it's a valid Collator instance.
951 * Useful for subclassing. 951 * Useful for subclassing.
952 */ 952 */
953 function initializeCollator(collator, locales, options) { 953 function CreateCollator(locales, options) {
954 if (%IsInitializedIntlObject(collator)) {
955 throw %make_type_error(kReinitializeIntl, "Collator");
956 }
957
958 if (IS_UNDEFINED(options)) { 954 if (IS_UNDEFINED(options)) {
959 options = {}; 955 options = {};
960 } 956 }
961 957
962 var getOption = getGetOption(options, 'collator'); 958 var getOption = getGetOption(options, 'collator');
963 959
964 var internalOptions = {}; 960 var internalOptions = {};
965 961
966 defineWEProperty(internalOptions, 'usage', getOption( 962 defineWEProperty(internalOptions, 'usage', getOption(
967 'usage', 'string', ['sort', 'search'], 'sort')); 963 'usage', 'string', ['sort', 'search'], 'sort'));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 collation: {value: internalOptions.collation, writable: true}, 1030 collation: {value: internalOptions.collation, writable: true},
1035 ignorePunctuation: {writable: true}, 1031 ignorePunctuation: {writable: true},
1036 locale: {writable: true}, 1032 locale: {writable: true},
1037 numeric: {writable: true}, 1033 numeric: {writable: true},
1038 requestedLocale: {value: requestedLocale, writable: true}, 1034 requestedLocale: {value: requestedLocale, writable: true},
1039 sensitivity: {writable: true}, 1035 sensitivity: {writable: true},
1040 strength: {writable: true}, 1036 strength: {writable: true},
1041 usage: {value: internalOptions.usage, writable: true} 1037 usage: {value: internalOptions.usage, writable: true}
1042 }); 1038 });
1043 1039
1044 var internalCollator = %CreateCollator(requestedLocale, 1040 var collator = %CreateCollator(requestedLocale, internalOptions, resolved);
1045 internalOptions,
1046 resolved);
1047 1041
1048 // Writable, configurable and enumerable are set to false by default. 1042 %MarkAsInitializedIntlObjectOfType(collator, 'collator');
1049 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator);
1050 collator[resolvedSymbol] = resolved; 1043 collator[resolvedSymbol] = resolved;
1051 1044
1052 return collator; 1045 return collator;
1053 } 1046 }
1054 1047
1055 1048
1056 /** 1049 /**
1057 * Constructs Intl.Collator object given optional locales and options 1050 * Constructs Intl.Collator object given optional locales and options
1058 * parameters. 1051 * parameters.
1059 * 1052 *
1060 * @constructor 1053 * @constructor
1061 */ 1054 */
1062 function CollatorConstructor() { 1055 function CollatorConstructor() {
1063 return IntlConstruct(this, GlobalIntlCollator, initializeCollator, new.target, 1056 return IntlConstruct(this, GlobalIntlCollator, CreateCollator, new.target,
1064 arguments); 1057 arguments);
1065 } 1058 }
1066 %SetCode(GlobalIntlCollator, CollatorConstructor); 1059 %SetCode(GlobalIntlCollator, CollatorConstructor);
1067 1060
1068 1061
1069 /** 1062 /**
1070 * Collator resolvedOptions method. 1063 * Collator resolvedOptions method.
1071 */ 1064 */
1072 InstallFunction(GlobalIntlCollator.prototype, 'resolvedOptions', function() { 1065 InstallFunction(GlobalIntlCollator.prototype, 'resolvedOptions', function() {
1073 var coll = Unwrap(this, 'collator', GlobalIntlCollator, 'resolvedOptions', 1066 var coll = Unwrap(this, 'collator', GlobalIntlCollator, 'resolvedOptions',
(...skipping 30 matching lines...) Expand all
1104 * When the compare method is called with two arguments x and y, it returns a 1097 * When the compare method is called with two arguments x and y, it returns a
1105 * Number other than NaN that represents the result of a locale-sensitive 1098 * Number other than NaN that represents the result of a locale-sensitive
1106 * String comparison of x with y. 1099 * String comparison of x with y.
1107 * The result is intended to order String values in the sort order specified 1100 * The result is intended to order String values in the sort order specified
1108 * by the effective locale and collation options computed during construction 1101 * by the effective locale and collation options computed during construction
1109 * of this Collator object, and will be negative, zero, or positive, depending 1102 * of this Collator object, and will be negative, zero, or positive, depending
1110 * on whether x comes before y in the sort order, the Strings are equal under 1103 * on whether x comes before y in the sort order, the Strings are equal under
1111 * the sort order, or x comes after y in the sort order, respectively. 1104 * the sort order, or x comes after y in the sort order, respectively.
1112 */ 1105 */
1113 function compare(collator, x, y) { 1106 function compare(collator, x, y) {
1114 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), 1107 return %InternalCompare(collator, TO_STRING(x), TO_STRING(y));
1115 TO_STRING(x), TO_STRING(y));
1116 }; 1108 };
1117 1109
1118 1110
1119 AddBoundMethod(GlobalIntlCollator, 'compare', compare, 2, 'collator', false); 1111 AddBoundMethod(GlobalIntlCollator, 'compare', compare, 2, 'collator', false);
1120 1112
1121 /** 1113 /**
1122 * Verifies that the input is a well-formed ISO 4217 currency code. 1114 * Verifies that the input is a well-formed ISO 4217 currency code.
1123 * Don't uppercase to test. It could convert invalid code into a valid one. 1115 * Don't uppercase to test. It could convert invalid code into a valid one.
1124 * For example \u00DFP (Eszett+P) becomes SSP. 1116 * For example \u00DFP (Eszett+P) becomes SSP.
1125 */ 1117 */
(...skipping 27 matching lines...) Expand all
1153 }, 1145 },
1154 set(value) { 1146 set(value) {
1155 this[patternSymbol] = value; 1147 this[patternSymbol] = value;
1156 } 1148 }
1157 }; 1149 };
1158 1150
1159 /** 1151 /**
1160 * Initializes the given object so it's a valid NumberFormat instance. 1152 * Initializes the given object so it's a valid NumberFormat instance.
1161 * Useful for subclassing. 1153 * Useful for subclassing.
1162 */ 1154 */
1163 function initializeNumberFormat(numberFormat, locales, options) { 1155 function CreateNumberFormat(locales, options) {
1164 if (%IsInitializedIntlObject(numberFormat)) {
1165 throw %make_type_error(kReinitializeIntl, "NumberFormat");
1166 }
1167
1168 if (IS_UNDEFINED(options)) { 1156 if (IS_UNDEFINED(options)) {
1169 options = {}; 1157 options = {};
1170 } 1158 }
1171 1159
1172 var getOption = getGetOption(options, 'numberformat'); 1160 var getOption = getGetOption(options, 'numberformat');
1173 1161
1174 var locale = resolveLocale('numberformat', locales, options); 1162 var locale = resolveLocale('numberformat', locales, options);
1175 1163
1176 var internalOptions = {}; 1164 var internalOptions = {};
1177 defineWEProperty(internalOptions, 'style', getOption( 1165 defineWEProperty(internalOptions, 'style', getOption(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 requestedLocale: {value: requestedLocale, writable: true}, 1241 requestedLocale: {value: requestedLocale, writable: true},
1254 style: {value: internalOptions.style, writable: true}, 1242 style: {value: internalOptions.style, writable: true},
1255 useGrouping: {writable: true} 1243 useGrouping: {writable: true}
1256 }); 1244 });
1257 if (HAS_OWN_PROPERTY(internalOptions, 'minimumSignificantDigits')) { 1245 if (HAS_OWN_PROPERTY(internalOptions, 'minimumSignificantDigits')) {
1258 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); 1246 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED);
1259 } 1247 }
1260 if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) { 1248 if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) {
1261 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); 1249 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED);
1262 } 1250 }
1263 var formatter = %CreateNumberFormat(requestedLocale, 1251 var numberFormat = %CreateNumberFormat(requestedLocale, internalOptions,
1264 internalOptions, 1252 resolved);
1265 resolved);
1266 1253
1267 if (internalOptions.style === 'currency') { 1254 if (internalOptions.style === 'currency') {
1268 %object_define_property(resolved, 'currencyDisplay', 1255 %object_define_property(resolved, 'currencyDisplay',
1269 {value: currencyDisplay, writable: true}); 1256 {value: currencyDisplay, writable: true});
1270 } 1257 }
1271 1258
1272 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); 1259 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat');
1273 numberFormat[resolvedSymbol] = resolved; 1260 numberFormat[resolvedSymbol] = resolved;
1274 1261
1275 return numberFormat; 1262 return numberFormat;
1276 } 1263 }
1277 1264
1278 1265
1279 /** 1266 /**
1280 * Constructs Intl.NumberFormat object given optional locales and options 1267 * Constructs Intl.NumberFormat object given optional locales and options
1281 * parameters. 1268 * parameters.
1282 * 1269 *
1283 * @constructor 1270 * @constructor
1284 */ 1271 */
1285 function NumberFormatConstructor() { 1272 function NumberFormatConstructor() {
1286 return IntlConstruct(this, GlobalIntlNumberFormat, initializeNumberFormat, 1273 return IntlConstruct(this, GlobalIntlNumberFormat, CreateNumberFormat,
1287 new.target, arguments, true); 1274 new.target, arguments, true);
1288 } 1275 }
1289 %SetCode(GlobalIntlNumberFormat, NumberFormatConstructor); 1276 %SetCode(GlobalIntlNumberFormat, NumberFormatConstructor);
1290 1277
1291 1278
1292 /** 1279 /**
1293 * NumberFormat resolvedOptions method. 1280 * NumberFormat resolvedOptions method.
1294 */ 1281 */
1295 InstallFunction(GlobalIntlNumberFormat.prototype, 'resolvedOptions', 1282 InstallFunction(GlobalIntlNumberFormat.prototype, 'resolvedOptions',
1296 function() { 1283 function() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 1332
1346 /** 1333 /**
1347 * Returns a String value representing the result of calling ToNumber(value) 1334 * Returns a String value representing the result of calling ToNumber(value)
1348 * according to the effective locale and the formatting options of this 1335 * according to the effective locale and the formatting options of this
1349 * NumberFormat. 1336 * NumberFormat.
1350 */ 1337 */
1351 function formatNumber(formatter, value) { 1338 function formatNumber(formatter, value) {
1352 // Spec treats -0 and +0 as 0. 1339 // Spec treats -0 and +0 as 0.
1353 var number = TO_NUMBER(value) + 0; 1340 var number = TO_NUMBER(value) + 0;
1354 1341
1355 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), 1342 return %InternalNumberFormat(formatter, number);
1356 number);
1357 } 1343 }
1358 1344
1359 1345
1360 AddBoundMethod(GlobalIntlNumberFormat, 'format', formatNumber, 1, 1346 AddBoundMethod(GlobalIntlNumberFormat, 'format', formatNumber, 1,
1361 'numberformat', true); 1347 'numberformat', true);
1362 1348
1363 /** 1349 /**
1364 * Returns a string that matches LDML representation of the options object. 1350 * Returns a string that matches LDML representation of the options object.
1365 */ 1351 */
1366 function toLDMLString(options) { 1352 function toLDMLString(options) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 } 1543 }
1558 1544
1559 return options; 1545 return options;
1560 } 1546 }
1561 1547
1562 1548
1563 /** 1549 /**
1564 * Initializes the given object so it's a valid DateTimeFormat instance. 1550 * Initializes the given object so it's a valid DateTimeFormat instance.
1565 * Useful for subclassing. 1551 * Useful for subclassing.
1566 */ 1552 */
1567 function initializeDateTimeFormat(dateFormat, locales, options) { 1553 function CreateDateTimeFormat(locales, options) {
1568
1569 if (%IsInitializedIntlObject(dateFormat)) {
1570 throw %make_type_error(kReinitializeIntl, "DateTimeFormat");
1571 }
1572
1573 if (IS_UNDEFINED(options)) { 1554 if (IS_UNDEFINED(options)) {
1574 options = {}; 1555 options = {};
1575 } 1556 }
1576 1557
1577 var locale = resolveLocale('dateformat', locales, options); 1558 var locale = resolveLocale('dateformat', locales, options);
1578 1559
1579 options = toDateTimeOptions(options, 'any', 'date'); 1560 options = toDateTimeOptions(options, 'any', 'date');
1580 1561
1581 var getOption = getGetOption(options, 'dateformat'); 1562 var getOption = getGetOption(options, 'dateformat');
1582 1563
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 [patternSymbol]: {writable: true}, 1605 [patternSymbol]: {writable: true},
1625 requestedLocale: {value: requestedLocale, writable: true}, 1606 requestedLocale: {value: requestedLocale, writable: true},
1626 second: {writable: true}, 1607 second: {writable: true},
1627 timeZone: {writable: true}, 1608 timeZone: {writable: true},
1628 timeZoneName: {writable: true}, 1609 timeZoneName: {writable: true},
1629 tz: {value: tz, writable: true}, 1610 tz: {value: tz, writable: true},
1630 weekday: {writable: true}, 1611 weekday: {writable: true},
1631 year: {writable: true} 1612 year: {writable: true}
1632 }); 1613 });
1633 1614
1634 var formatter = %CreateDateTimeFormat( 1615 var dateFormat = %CreateDateTimeFormat(
1635 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); 1616 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
1636 1617
1637 if (resolved.timeZone === "Etc/Unknown") { 1618 if (resolved.timeZone === "Etc/Unknown") {
1638 throw %make_range_error(kUnsupportedTimeZone, tz); 1619 throw %make_range_error(kUnsupportedTimeZone, tz);
1639 } 1620 }
1640 1621
1641 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); 1622 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat');
1642 dateFormat[resolvedSymbol] = resolved; 1623 dateFormat[resolvedSymbol] = resolved;
1643 1624
1644 return dateFormat; 1625 return dateFormat;
1645 } 1626 }
1646 1627
1647 1628
1648 /** 1629 /**
1649 * Constructs Intl.DateTimeFormat object given optional locales and options 1630 * Constructs Intl.DateTimeFormat object given optional locales and options
1650 * parameters. 1631 * parameters.
1651 * 1632 *
1652 * @constructor 1633 * @constructor
1653 */ 1634 */
1654 function DateTimeFormatConstructor() { 1635 function DateTimeFormatConstructor() {
1655 return IntlConstruct(this, GlobalIntlDateTimeFormat, initializeDateTimeFormat, 1636 return IntlConstruct(this, GlobalIntlDateTimeFormat, CreateDateTimeFormat,
1656 new.target, arguments, true); 1637 new.target, arguments, true);
1657 } 1638 }
1658 %SetCode(GlobalIntlDateTimeFormat, DateTimeFormatConstructor); 1639 %SetCode(GlobalIntlDateTimeFormat, DateTimeFormatConstructor);
1659 1640
1660 1641
1661 /** 1642 /**
1662 * DateTimeFormat resolvedOptions method. 1643 * DateTimeFormat resolvedOptions method.
1663 */ 1644 */
1664 InstallFunction(GlobalIntlDateTimeFormat.prototype, 'resolvedOptions', 1645 InstallFunction(GlobalIntlDateTimeFormat.prototype, 'resolvedOptions',
1665 function() { 1646 function() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 function formatDate(formatter, dateValue) { 1712 function formatDate(formatter, dateValue) {
1732 var dateMs; 1713 var dateMs;
1733 if (IS_UNDEFINED(dateValue)) { 1714 if (IS_UNDEFINED(dateValue)) {
1734 dateMs = %DateCurrentTime(); 1715 dateMs = %DateCurrentTime();
1735 } else { 1716 } else {
1736 dateMs = TO_NUMBER(dateValue); 1717 dateMs = TO_NUMBER(dateValue);
1737 } 1718 }
1738 1719
1739 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); 1720 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
1740 1721
1741 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), 1722 return %InternalDateFormat(formatter, new GlobalDate(dateMs));
1742 new GlobalDate(dateMs));
1743 } 1723 }
1744 1724
1745 function FormatDateToParts(dateValue) { 1725 function FormatDateToParts(dateValue) {
1746 CHECK_OBJECT_COERCIBLE(this, "Intl.DateTimeFormat.prototype.formatToParts"); 1726 CHECK_OBJECT_COERCIBLE(this, "Intl.DateTimeFormat.prototype.formatToParts");
1747 if (!IS_OBJECT(this)) { 1727 if (!IS_OBJECT(this)) {
1748 throw %make_type_error(kCalledOnNonObject, this); 1728 throw %make_type_error(kCalledOnNonObject, this);
1749 } 1729 }
1750 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { 1730 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
1751 throw %make_type_error(kIncompatibleMethodReceiver, 1731 throw %make_type_error(kIncompatibleMethodReceiver,
1752 'Intl.DateTimeFormat.prototype.formatToParts', 1732 'Intl.DateTimeFormat.prototype.formatToParts',
1753 this); 1733 this);
1754 } 1734 }
1755 var dateMs; 1735 var dateMs;
1756 if (IS_UNDEFINED(dateValue)) { 1736 if (IS_UNDEFINED(dateValue)) {
1757 dateMs = %DateCurrentTime(); 1737 dateMs = %DateCurrentTime();
1758 } else { 1738 } else {
1759 dateMs = TO_NUMBER(dateValue); 1739 dateMs = TO_NUMBER(dateValue);
1760 } 1740 }
1761 1741
1762 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); 1742 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
1763 1743
1764 return %InternalDateFormatToParts( 1744 return %InternalDateFormatToParts(this, new GlobalDate(dateMs));
1765 %GetImplFromInitializedIntlObject(this), new GlobalDate(dateMs));
1766 } 1745 }
1767 1746
1768 %FunctionSetLength(FormatDateToParts, 0); 1747 %FunctionSetLength(FormatDateToParts, 0);
1769 1748
1770 1749
1771 // 0 because date is optional argument. 1750 // 0 because date is optional argument.
1772 AddBoundMethod(GlobalIntlDateTimeFormat, 'format', formatDate, 0, 'dateformat', 1751 AddBoundMethod(GlobalIntlDateTimeFormat, 'format', formatDate, 0, 'dateformat',
1773 true); 1752 true);
1774 1753
1775 1754
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 } 1790 }
1812 } 1791 }
1813 1792
1814 return result; 1793 return result;
1815 } 1794 }
1816 1795
1817 /** 1796 /**
1818 * Initializes the given object so it's a valid BreakIterator instance. 1797 * Initializes the given object so it's a valid BreakIterator instance.
1819 * Useful for subclassing. 1798 * Useful for subclassing.
1820 */ 1799 */
1821 function initializeBreakIterator(iterator, locales, options) { 1800 function CreateBreakIterator(locales, options) {
1822 if (%IsInitializedIntlObject(iterator)) {
1823 throw %make_type_error(kReinitializeIntl, "v8BreakIterator");
1824 }
1825
1826 if (IS_UNDEFINED(options)) { 1801 if (IS_UNDEFINED(options)) {
1827 options = {}; 1802 options = {};
1828 } 1803 }
1829 1804
1830 var getOption = getGetOption(options, 'breakiterator'); 1805 var getOption = getGetOption(options, 'breakiterator');
1831 1806
1832 var internalOptions = {}; 1807 var internalOptions = {};
1833 1808
1834 defineWEProperty(internalOptions, 'type', getOption( 1809 defineWEProperty(internalOptions, 'type', getOption(
1835 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); 1810 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word'));
1836 1811
1837 var locale = resolveLocale('breakiterator', locales, options); 1812 var locale = resolveLocale('breakiterator', locales, options);
1838 var resolved = %object_define_properties({}, { 1813 var resolved = %object_define_properties({}, {
1839 requestedLocale: {value: locale.locale, writable: true}, 1814 requestedLocale: {value: locale.locale, writable: true},
1840 type: {value: internalOptions.type, writable: true}, 1815 type: {value: internalOptions.type, writable: true},
1841 locale: {writable: true} 1816 locale: {writable: true}
1842 }); 1817 });
1843 1818
1844 var internalIterator = %CreateBreakIterator(locale.locale, 1819 var iterator = %CreateBreakIterator(locale.locale, internalOptions, resolved);
1845 internalOptions,
1846 resolved);
1847 1820
1848 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', 1821 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator');
1849 internalIterator);
1850 iterator[resolvedSymbol] = resolved; 1822 iterator[resolvedSymbol] = resolved;
1851 1823
1852 return iterator; 1824 return iterator;
1853 } 1825 }
1854 1826
1855 1827
1856 /** 1828 /**
1857 * Constructs Intl.v8BreakIterator object given optional locales and options 1829 * Constructs Intl.v8BreakIterator object given optional locales and options
1858 * parameters. 1830 * parameters.
1859 * 1831 *
1860 * @constructor 1832 * @constructor
1861 */ 1833 */
1862 function v8BreakIteratorConstructor() { 1834 function v8BreakIteratorConstructor() {
1863 return IntlConstruct(this, GlobalIntlv8BreakIterator, initializeBreakIterator, 1835 return IntlConstruct(this, GlobalIntlv8BreakIterator, CreateBreakIterator,
1864 new.target, arguments); 1836 new.target, arguments);
1865 } 1837 }
1866 %SetCode(GlobalIntlv8BreakIterator, v8BreakIteratorConstructor); 1838 %SetCode(GlobalIntlv8BreakIterator, v8BreakIteratorConstructor);
1867 1839
1868 1840
1869 /** 1841 /**
1870 * BreakIterator resolvedOptions method. 1842 * BreakIterator resolvedOptions method.
1871 */ 1843 */
1872 InstallFunction(GlobalIntlv8BreakIterator.prototype, 'resolvedOptions', 1844 InstallFunction(GlobalIntlv8BreakIterator.prototype, 'resolvedOptions',
1873 function() { 1845 function() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 return supportedLocalesOf('breakiterator', locales, arguments[1]); 1877 return supportedLocalesOf('breakiterator', locales, arguments[1]);
1906 } 1878 }
1907 ); 1879 );
1908 1880
1909 1881
1910 /** 1882 /**
1911 * Adopts text to segment using the iterator. Old text, if present, 1883 * Adopts text to segment using the iterator. Old text, if present,
1912 * gets discarded. 1884 * gets discarded.
1913 */ 1885 */
1914 function adoptText(iterator, text) { 1886 function adoptText(iterator, text) {
1915 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), 1887 %BreakIteratorAdoptText(iterator, TO_STRING(text));
1916 TO_STRING(text));
1917 } 1888 }
1918 1889
1919 1890
1920 /** 1891 /**
1921 * Returns index of the first break in the string and moves current pointer. 1892 * Returns index of the first break in the string and moves current pointer.
1922 */ 1893 */
1923 function first(iterator) { 1894 function first(iterator) {
1924 return %BreakIteratorFirst(%GetImplFromInitializedIntlObject(iterator)); 1895 return %BreakIteratorFirst(iterator);
1925 } 1896 }
1926 1897
1927 1898
1928 /** 1899 /**
1929 * Returns the index of the next break and moves the pointer. 1900 * Returns the index of the next break and moves the pointer.
1930 */ 1901 */
1931 function next(iterator) { 1902 function next(iterator) {
1932 return %BreakIteratorNext(%GetImplFromInitializedIntlObject(iterator)); 1903 return %BreakIteratorNext(iterator);
1933 } 1904 }
1934 1905
1935 1906
1936 /** 1907 /**
1937 * Returns index of the current break. 1908 * Returns index of the current break.
1938 */ 1909 */
1939 function current(iterator) { 1910 function current(iterator) {
1940 return %BreakIteratorCurrent(%GetImplFromInitializedIntlObject(iterator)); 1911 return %BreakIteratorCurrent(iterator);
1941 } 1912 }
1942 1913
1943 1914
1944 /** 1915 /**
1945 * Returns type of the current break. 1916 * Returns type of the current break.
1946 */ 1917 */
1947 function breakType(iterator) { 1918 function breakType(iterator) {
1948 return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator)); 1919 return %BreakIteratorBreakType(iterator);
1949 } 1920 }
1950 1921
1951 1922
1952 AddBoundMethod(GlobalIntlv8BreakIterator, 'adoptText', adoptText, 1, 1923 AddBoundMethod(GlobalIntlv8BreakIterator, 'adoptText', adoptText, 1,
1953 'breakiterator'); 1924 'breakiterator');
1954 AddBoundMethod(GlobalIntlv8BreakIterator, 'first', first, 0, 'breakiterator'); 1925 AddBoundMethod(GlobalIntlv8BreakIterator, 'first', first, 0, 'breakiterator');
1955 AddBoundMethod(GlobalIntlv8BreakIterator, 'next', next, 0, 'breakiterator'); 1926 AddBoundMethod(GlobalIntlv8BreakIterator, 'next', next, 0, 'breakiterator');
1956 AddBoundMethod(GlobalIntlv8BreakIterator, 'current', current, 0, 1927 AddBoundMethod(GlobalIntlv8BreakIterator, 'current', current, 0,
1957 'breakiterator'); 1928 'breakiterator');
1958 AddBoundMethod(GlobalIntlv8BreakIterator, 'breakType', breakType, 0, 1929 AddBoundMethod(GlobalIntlv8BreakIterator, 'breakType', breakType, 0,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 } 2166 }
2196 ); 2167 );
2197 2168
2198 %FunctionRemovePrototype(FormatDateToParts); 2169 %FunctionRemovePrototype(FormatDateToParts);
2199 2170
2200 utils.Export(function(to) { 2171 utils.Export(function(to) {
2201 to.FormatDateToParts = FormatDateToParts; 2172 to.FormatDateToParts = FormatDateToParts;
2202 }); 2173 });
2203 2174
2204 }) 2175 })
OLDNEW
« no previous file with comments | « src/i18n.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698