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

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

Issue 2586763002: [intl] Create the Intl constructors to C++ (Closed)
Patch Set: Fix factory references Created 4 years 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
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 */
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 ArrayJoin; 20 var ArrayJoin;
21 var ArrayPush; 21 var ArrayPush;
22 var GlobalDate = global.Date; 22 var GlobalDate = global.Date;
23 var GlobalIntl = global.Intl;
24 var GlobalIntlDateTimeFormat = GlobalIntl.DateTimeFormat;
25 var GlobalIntlNumberFormat = GlobalIntl.NumberFormat;
26 var GlobalIntlCollator = GlobalIntl.Collator;
27 var GlobalIntlv8BreakIterator = GlobalIntl.v8BreakIterator;
23 var GlobalNumber = global.Number; 28 var GlobalNumber = global.Number;
24 var GlobalRegExp = global.RegExp; 29 var GlobalRegExp = global.RegExp;
25 var GlobalString = global.String; 30 var GlobalString = global.String;
26 var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol"); 31 var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol");
27 var InstallFunctions = utils.InstallFunctions; 32 var InstallFunctions = utils.InstallFunctions;
28 var InstallGetter = utils.InstallGetter; 33 var InstallGetter = utils.InstallGetter;
29 var InternalArray = utils.InternalArray; 34 var InternalArray = utils.InternalArray;
30 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); 35 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty");
31 var OverrideFunction = utils.OverrideFunction; 36 var OverrideFunction = utils.OverrideFunction;
32 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); 37 var patternSymbol = utils.ImportNow("intl_pattern_symbol");
33 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); 38 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol");
34 var SetFunctionName = utils.SetFunctionName; 39 var SetFunctionName = utils.SetFunctionName;
35 var StringSubstr = GlobalString.prototype.substr; 40 var StringSubstr = GlobalString.prototype.substr;
36 var StringSubstring = GlobalString.prototype.substring; 41 var StringSubstring = GlobalString.prototype.substring;
37 42
38 utils.Import(function(from) { 43 utils.Import(function(from) {
39 ArrayJoin = from.ArrayJoin; 44 ArrayJoin = from.ArrayJoin;
40 ArrayPush = from.ArrayPush; 45 ArrayPush = from.ArrayPush;
41 }); 46 });
42 47
43 // Utilities for definitions 48 // Utilities for definitions
44 49
45 function InstallFunction(object, name, func) { 50 function InstallFunction(object, name, func) {
46 InstallFunctions(object, DONT_ENUM, [name, func]); 51 InstallFunctions(object, DONT_ENUM, [name, func]);
47 } 52 }
48 53
49 54
50 function InstallConstructor(object, name, func) {
51 %CheckIsBootstrapping();
52 SetFunctionName(func, name);
53 %AddNamedProperty(object, name, func, DONT_ENUM);
54 %SetNativeFlag(func);
55 %ToFastProperties(object);
56 }
57
58 /** 55 /**
59 * Adds bound method to the prototype of the given object. 56 * Adds bound method to the prototype of the given object.
60 */ 57 */
61 function AddBoundMethod(obj, methodName, implementation, length, typename, compa t) { 58 function AddBoundMethod(obj, methodName, implementation, length, typename, compa t) {
62 %CheckIsBootstrapping(); 59 %CheckIsBootstrapping();
63 var internalName = %CreatePrivateSymbol(methodName); 60 var internalName = %CreatePrivateSymbol(methodName);
64 // Making getter an anonymous function will cause 61 // Making getter an anonymous function will cause
65 // %DefineGetterPropertyUnchecked to properly set the "name" 62 // %DefineGetterPropertyUnchecked to properly set the "name"
66 // property on each JSFunction instance created here, rather 63 // property on each JSFunction instance created here, rather
67 // than (as utils.InstallGetter would) on the SharedFunctionInfo 64 // than (as utils.InstallGetter would) on the SharedFunctionInfo
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 127 }
131 } 128 }
132 throw %make_type_error(kIncompatibleMethodReceiver, method, receiver); 129 throw %make_type_error(kIncompatibleMethodReceiver, method, receiver);
133 } 130 }
134 return receiver; 131 return receiver;
135 } 132 }
136 133
137 134
138 // ------------------------------------------------------------------- 135 // -------------------------------------------------------------------
139 136
140 var Intl = {};
141
142 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM);
143
144 /** 137 /**
145 * Caches available locales for each service. 138 * Caches available locales for each service.
146 */ 139 */
147 var AVAILABLE_LOCALES = { 140 var AVAILABLE_LOCALES = {
148 'collator': UNDEFINED, 141 'collator': UNDEFINED,
149 'numberformat': UNDEFINED, 142 'numberformat': UNDEFINED,
150 'dateformat': UNDEFINED, 143 'dateformat': UNDEFINED,
151 'breakiterator': UNDEFINED 144 'breakiterator': UNDEFINED
152 }; 145 };
153 146
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 get() { 933 get() {
941 %IncrementUseCounter(kIntlResolved); 934 %IncrementUseCounter(kIntlResolved);
942 return this[resolvedSymbol]; 935 return this[resolvedSymbol];
943 }, 936 },
944 set(value) { 937 set(value) {
945 this[resolvedSymbol] = value; 938 this[resolvedSymbol] = value;
946 } 939 }
947 }; 940 };
948 941
949 // ECMA 402 section 8.2.1 942 // ECMA 402 section 8.2.1
950 InstallFunction(Intl, 'getCanonicalLocales', function(locales) { 943 InstallFunction(GlobalIntl, 'getCanonicalLocales', function(locales) {
951 return makeArray(canonicalizeLocaleList(locales)); 944 return makeArray(canonicalizeLocaleList(locales));
952 } 945 }
953 ); 946 );
954 947
955 /** 948 /**
956 * Initializes the given object so it's a valid Collator instance. 949 * Initializes the given object so it's a valid Collator instance.
957 * Useful for subclassing. 950 * Useful for subclassing.
958 */ 951 */
959 function initializeCollator(collator, locales, options) { 952 function initializeCollator(collator, locales, options) {
960 if (%IsInitializedIntlObject(collator)) { 953 if (%IsInitializedIntlObject(collator)) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 return collator; 1051 return collator;
1059 } 1052 }
1060 1053
1061 1054
1062 /** 1055 /**
1063 * Constructs Intl.Collator object given optional locales and options 1056 * Constructs Intl.Collator object given optional locales and options
1064 * parameters. 1057 * parameters.
1065 * 1058 *
1066 * @constructor 1059 * @constructor
1067 */ 1060 */
1068 function Collator() { 1061 function CollatorConstructor() {
1069 return IntlConstruct(this, Collator, initializeCollator, new.target, 1062 return IntlConstruct(this, GlobalIntlCollator, initializeCollator, new.target,
1070 arguments); 1063 arguments);
1071 } 1064 }
1072 InstallConstructor(Intl, 'Collator', Collator); 1065 %SetCode(GlobalIntlCollator, CollatorConstructor);
1073 1066
1074 1067
1075 /** 1068 /**
1076 * Collator resolvedOptions method. 1069 * Collator resolvedOptions method.
1077 */ 1070 */
1078 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { 1071 InstallFunction(GlobalIntlCollator.prototype, 'resolvedOptions', function() {
1079 var coll = Unwrap(this, 'collator', Collator, 'resolvedOptions', false); 1072 var coll = Unwrap(this, 'collator', GlobalIntlCollator, 'resolvedOptions',
1073 false);
1080 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, 1074 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale,
1081 coll[resolvedSymbol].locale); 1075 coll[resolvedSymbol].locale);
1082 1076
1083 return { 1077 return {
1084 locale: locale, 1078 locale: locale,
1085 usage: coll[resolvedSymbol].usage, 1079 usage: coll[resolvedSymbol].usage,
1086 sensitivity: coll[resolvedSymbol].sensitivity, 1080 sensitivity: coll[resolvedSymbol].sensitivity,
1087 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, 1081 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation,
1088 numeric: coll[resolvedSymbol].numeric, 1082 numeric: coll[resolvedSymbol].numeric,
1089 caseFirst: coll[resolvedSymbol].caseFirst, 1083 caseFirst: coll[resolvedSymbol].caseFirst,
1090 collation: coll[resolvedSymbol].collation 1084 collation: coll[resolvedSymbol].collation
1091 }; 1085 };
1092 } 1086 }
1093 ); 1087 );
1094 1088
1095 1089
1096 /** 1090 /**
1097 * Returns the subset of the given locale list for which this locale list 1091 * Returns the subset of the given locale list for which this locale list
1098 * has a matching (possibly fallback) locale. Locales appear in the same 1092 * has a matching (possibly fallback) locale. Locales appear in the same
1099 * order in the returned list as in the input list. 1093 * order in the returned list as in the input list.
1100 * Options are optional parameter. 1094 * Options are optional parameter.
1101 */ 1095 */
1102 InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) { 1096 InstallFunction(GlobalIntlCollator, 'supportedLocalesOf', function(locales) {
1103 return supportedLocalesOf('collator', locales, arguments[1]); 1097 return supportedLocalesOf('collator', locales, arguments[1]);
1104 } 1098 }
1105 ); 1099 );
1106 1100
1107 1101
1108 /** 1102 /**
1109 * When the compare method is called with two arguments x and y, it returns a 1103 * When the compare method is called with two arguments x and y, it returns a
1110 * Number other than NaN that represents the result of a locale-sensitive 1104 * Number other than NaN that represents the result of a locale-sensitive
1111 * String comparison of x with y. 1105 * String comparison of x with y.
1112 * The result is intended to order String values in the sort order specified 1106 * The result is intended to order String values in the sort order specified
1113 * by the effective locale and collation options computed during construction 1107 * by the effective locale and collation options computed during construction
1114 * of this Collator object, and will be negative, zero, or positive, depending 1108 * of this Collator object, and will be negative, zero, or positive, depending
1115 * on whether x comes before y in the sort order, the Strings are equal under 1109 * on whether x comes before y in the sort order, the Strings are equal under
1116 * the sort order, or x comes after y in the sort order, respectively. 1110 * the sort order, or x comes after y in the sort order, respectively.
1117 */ 1111 */
1118 function compare(collator, x, y) { 1112 function compare(collator, x, y) {
1119 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), 1113 return %InternalCompare(%GetImplFromInitializedIntlObject(collator),
1120 TO_STRING(x), TO_STRING(y)); 1114 TO_STRING(x), TO_STRING(y));
1121 }; 1115 };
1122 1116
1123 1117
1124 AddBoundMethod(Intl.Collator, 'compare', compare, 2, 'collator', false); 1118 AddBoundMethod(GlobalIntlCollator, 'compare', compare, 2, 'collator', false);
1125 1119
1126 /** 1120 /**
1127 * Verifies that the input is a well-formed ISO 4217 currency code. 1121 * Verifies that the input is a well-formed ISO 4217 currency code.
1128 * Don't uppercase to test. It could convert invalid code into a valid one. 1122 * Don't uppercase to test. It could convert invalid code into a valid one.
1129 * For example \u00DFP (Eszett+P) becomes SSP. 1123 * For example \u00DFP (Eszett+P) becomes SSP.
1130 */ 1124 */
1131 function isWellFormedCurrencyCode(currency) { 1125 function isWellFormedCurrencyCode(currency) {
1132 return typeof currency == "string" && currency.length == 3 && 1126 return typeof currency == "string" && currency.length == 3 &&
1133 IS_NULL(%regexp_internal_match(/[^A-Za-z]/, currency)); 1127 IS_NULL(%regexp_internal_match(/[^A-Za-z]/, currency));
1134 } 1128 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 return numberFormat; 1274 return numberFormat;
1281 } 1275 }
1282 1276
1283 1277
1284 /** 1278 /**
1285 * Constructs Intl.NumberFormat object given optional locales and options 1279 * Constructs Intl.NumberFormat object given optional locales and options
1286 * parameters. 1280 * parameters.
1287 * 1281 *
1288 * @constructor 1282 * @constructor
1289 */ 1283 */
1290 function NumberFormat() { 1284 function NumberFormatConstructor() {
1291 return IntlConstruct(this, NumberFormat, initializeNumberFormat, new.target, 1285 return IntlConstruct(this, GlobalIntlNumberFormat, initializeNumberFormat,
1292 arguments, true); 1286 new.target, arguments, true);
1293 } 1287 }
1294 InstallConstructor(Intl, 'NumberFormat', NumberFormat); 1288 %SetCode(GlobalIntlNumberFormat, NumberFormatConstructor);
1295 1289
1296 1290
1297 /** 1291 /**
1298 * NumberFormat resolvedOptions method. 1292 * NumberFormat resolvedOptions method.
1299 */ 1293 */
1300 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { 1294 InstallFunction(GlobalIntlNumberFormat.prototype, 'resolvedOptions',
1301 var format = Unwrap(this, 'numberformat', NumberFormat, 1295 function() {
1296 var format = Unwrap(this, 'numberformat', GlobalIntlNumberFormat,
1302 'resolvedOptions', true); 1297 'resolvedOptions', true);
1303 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, 1298 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale,
1304 format[resolvedSymbol].locale); 1299 format[resolvedSymbol].locale);
1305 1300
1306 var result = { 1301 var result = {
1307 locale: locale, 1302 locale: locale,
1308 numberingSystem: format[resolvedSymbol].numberingSystem, 1303 numberingSystem: format[resolvedSymbol].numberingSystem,
1309 style: format[resolvedSymbol].style, 1304 style: format[resolvedSymbol].style,
1310 useGrouping: format[resolvedSymbol].useGrouping, 1305 useGrouping: format[resolvedSymbol].useGrouping,
1311 minimumIntegerDigits: format[resolvedSymbol].minimumIntegerDigits, 1306 minimumIntegerDigits: format[resolvedSymbol].minimumIntegerDigits,
(...skipping 21 matching lines...) Expand all
1333 } 1328 }
1334 ); 1329 );
1335 1330
1336 1331
1337 /** 1332 /**
1338 * Returns the subset of the given locale list for which this locale list 1333 * Returns the subset of the given locale list for which this locale list
1339 * has a matching (possibly fallback) locale. Locales appear in the same 1334 * has a matching (possibly fallback) locale. Locales appear in the same
1340 * order in the returned list as in the input list. 1335 * order in the returned list as in the input list.
1341 * Options are optional parameter. 1336 * Options are optional parameter.
1342 */ 1337 */
1343 InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { 1338 InstallFunction(GlobalIntlNumberFormat, 'supportedLocalesOf',
1339 function(locales) {
1344 return supportedLocalesOf('numberformat', locales, arguments[1]); 1340 return supportedLocalesOf('numberformat', locales, arguments[1]);
1345 } 1341 }
1346 ); 1342 );
1347 1343
1348 1344
1349 /** 1345 /**
1350 * Returns a String value representing the result of calling ToNumber(value) 1346 * Returns a String value representing the result of calling ToNumber(value)
1351 * according to the effective locale and the formatting options of this 1347 * according to the effective locale and the formatting options of this
1352 * NumberFormat. 1348 * NumberFormat.
1353 */ 1349 */
1354 function formatNumber(formatter, value) { 1350 function formatNumber(formatter, value) {
1355 // Spec treats -0 and +0 as 0. 1351 // Spec treats -0 and +0 as 0.
1356 var number = TO_NUMBER(value) + 0; 1352 var number = TO_NUMBER(value) + 0;
1357 1353
1358 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), 1354 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter),
1359 number); 1355 number);
1360 } 1356 }
1361 1357
1362 1358
1363 AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1, 'numberformat', tru e); 1359 AddBoundMethod(GlobalIntlNumberFormat, 'format', formatNumber, 1,
1360 'numberformat', true);
1364 1361
1365 /** 1362 /**
1366 * Returns a string that matches LDML representation of the options object. 1363 * Returns a string that matches LDML representation of the options object.
1367 */ 1364 */
1368 function toLDMLString(options) { 1365 function toLDMLString(options) {
1369 var getOption = getGetOption(options, 'dateformat'); 1366 var getOption = getGetOption(options, 'dateformat');
1370 1367
1371 var ldmlString = ''; 1368 var ldmlString = '';
1372 1369
1373 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']); 1370 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 return dateFormat; 1643 return dateFormat;
1647 } 1644 }
1648 1645
1649 1646
1650 /** 1647 /**
1651 * Constructs Intl.DateTimeFormat object given optional locales and options 1648 * Constructs Intl.DateTimeFormat object given optional locales and options
1652 * parameters. 1649 * parameters.
1653 * 1650 *
1654 * @constructor 1651 * @constructor
1655 */ 1652 */
1656 function DateTimeFormat() { 1653 function DateTimeFormatConstructor() {
1657 return IntlConstruct(this, DateTimeFormat, initializeDateTimeFormat, 1654 return IntlConstruct(this, GlobalIntlDateTimeFormat, initializeDateTimeFormat,
1658 new.target, arguments, true); 1655 new.target, arguments, true);
1659 } 1656 }
1660 InstallConstructor(Intl, 'DateTimeFormat', DateTimeFormat); 1657 %SetCode(GlobalIntlDateTimeFormat, DateTimeFormatConstructor);
1661 1658
1662 1659
1663 /** 1660 /**
1664 * DateTimeFormat resolvedOptions method. 1661 * DateTimeFormat resolvedOptions method.
1665 */ 1662 */
1666 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { 1663 InstallFunction(GlobalIntlDateTimeFormat.prototype, 'resolvedOptions',
1667 var format = Unwrap(this, 'dateformat', DateTimeFormat, 1664 function() {
1665 var format = Unwrap(this, 'dateformat', GlobalIntlDateTimeFormat,
1668 'resolvedOptions', true); 1666 'resolvedOptions', true);
1669 1667
1670 /** 1668 /**
1671 * Maps ICU calendar names to LDML/BCP47 types for key 'ca'. 1669 * Maps ICU calendar names to LDML/BCP47 types for key 'ca'.
1672 * See typeMap section in third_party/icu/source/data/misc/keyTypeData.txt 1670 * See typeMap section in third_party/icu/source/data/misc/keyTypeData.txt
1673 * and 1671 * and
1674 * http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml 1672 * http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml
1675 */ 1673 */
1676 var ICU_CALENDAR_MAP = { 1674 var ICU_CALENDAR_MAP = {
1677 'gregorian': 'gregory', 1675 'gregorian': 'gregory',
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 } 1708 }
1711 ); 1709 );
1712 1710
1713 1711
1714 /** 1712 /**
1715 * Returns the subset of the given locale list for which this locale list 1713 * Returns the subset of the given locale list for which this locale list
1716 * has a matching (possibly fallback) locale. Locales appear in the same 1714 * has a matching (possibly fallback) locale. Locales appear in the same
1717 * order in the returned list as in the input list. 1715 * order in the returned list as in the input list.
1718 * Options are optional parameter. 1716 * Options are optional parameter.
1719 */ 1717 */
1720 InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { 1718 InstallFunction(GlobalIntlDateTimeFormat, 'supportedLocalesOf',
1719 function(locales) {
1721 return supportedLocalesOf('dateformat', locales, arguments[1]); 1720 return supportedLocalesOf('dateformat', locales, arguments[1]);
1722 } 1721 }
1723 ); 1722 );
1724 1723
1725 1724
1726 /** 1725 /**
1727 * Returns a String value representing the result of calling ToNumber(date) 1726 * Returns a String value representing the result of calling ToNumber(date)
1728 * according to the effective locale and the formatting options of this 1727 * according to the effective locale and the formatting options of this
1729 * DateTimeFormat. 1728 * DateTimeFormat.
1730 */ 1729 */
(...skipping 26 matching lines...) Expand all
1757 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); 1756 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
1758 1757
1759 return %InternalDateFormatToParts( 1758 return %InternalDateFormatToParts(
1760 %GetImplFromInitializedIntlObject(this), new GlobalDate(dateMs)); 1759 %GetImplFromInitializedIntlObject(this), new GlobalDate(dateMs));
1761 } 1760 }
1762 1761
1763 %FunctionSetLength(FormatDateToParts, 0); 1762 %FunctionSetLength(FormatDateToParts, 0);
1764 1763
1765 1764
1766 // 0 because date is optional argument. 1765 // 0 because date is optional argument.
1767 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0, 'dateformat', true) ; 1766 AddBoundMethod(GlobalIntlDateTimeFormat, 'format', formatDate, 0, 'dateformat',
1767 true);
1768 1768
1769 1769
1770 /** 1770 /**
1771 * Returns canonical Area/Location(/Location) name, or throws an exception 1771 * Returns canonical Area/Location(/Location) name, or throws an exception
1772 * if the zone name is invalid IANA name. 1772 * if the zone name is invalid IANA name.
1773 */ 1773 */
1774 function canonicalizeTimeZoneID(tzID) { 1774 function canonicalizeTimeZoneID(tzID) {
1775 // Skip undefined zones. 1775 // Skip undefined zones.
1776 if (IS_UNDEFINED(tzID)) { 1776 if (IS_UNDEFINED(tzID)) {
1777 return tzID; 1777 return tzID;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 return iterator; 1846 return iterator;
1847 } 1847 }
1848 1848
1849 1849
1850 /** 1850 /**
1851 * Constructs Intl.v8BreakIterator object given optional locales and options 1851 * Constructs Intl.v8BreakIterator object given optional locales and options
1852 * parameters. 1852 * parameters.
1853 * 1853 *
1854 * @constructor 1854 * @constructor
1855 */ 1855 */
1856 function v8BreakIterator() { 1856 function v8BreakIteratorConstructor() {
1857 return IntlConstruct(this, v8BreakIterator, initializeBreakIterator, 1857 return IntlConstruct(this, GlobalIntlv8BreakIterator, initializeBreakIterator,
1858 new.target, arguments); 1858 new.target, arguments);
1859 } 1859 }
1860 InstallConstructor(Intl, 'v8BreakIterator', v8BreakIterator); 1860 %SetCode(GlobalIntlv8BreakIterator, v8BreakIteratorConstructor);
1861 1861
1862 1862
1863 /** 1863 /**
1864 * BreakIterator resolvedOptions method. 1864 * BreakIterator resolvedOptions method.
1865 */ 1865 */
1866 InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions', 1866 InstallFunction(GlobalIntlv8BreakIterator.prototype, 'resolvedOptions',
1867 function() { 1867 function() {
1868 if (!IS_UNDEFINED(new.target)) { 1868 if (!IS_UNDEFINED(new.target)) {
1869 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); 1869 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1870 } 1870 }
1871 1871
1872 var segmenter = Unwrap(this, 'breakiterator', v8BreakIterator, 1872 var segmenter = Unwrap(this, 'breakiterator', GlobalIntlv8BreakIterator,
1873 'resolvedOptions', false); 1873 'resolvedOptions', false);
1874 1874
1875 var locale = 1875 var locale =
1876 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale, 1876 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale,
1877 segmenter[resolvedSymbol].locale); 1877 segmenter[resolvedSymbol].locale);
1878 1878
1879 return { 1879 return {
1880 locale: locale, 1880 locale: locale,
1881 type: segmenter[resolvedSymbol].type 1881 type: segmenter[resolvedSymbol].type
1882 }; 1882 };
1883 } 1883 }
1884 ); 1884 );
1885 1885
1886 1886
1887 /** 1887 /**
1888 * Returns the subset of the given locale list for which this locale list 1888 * Returns the subset of the given locale list for which this locale list
1889 * has a matching (possibly fallback) locale. Locales appear in the same 1889 * has a matching (possibly fallback) locale. Locales appear in the same
1890 * order in the returned list as in the input list. 1890 * order in the returned list as in the input list.
1891 * Options are optional parameter. 1891 * Options are optional parameter.
1892 */ 1892 */
1893 InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf', 1893 InstallFunction(GlobalIntlv8BreakIterator, 'supportedLocalesOf',
1894 function(locales) { 1894 function(locales) {
1895 if (!IS_UNDEFINED(new.target)) { 1895 if (!IS_UNDEFINED(new.target)) {
1896 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); 1896 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1897 } 1897 }
1898 1898
1899 return supportedLocalesOf('breakiterator', locales, arguments[1]); 1899 return supportedLocalesOf('breakiterator', locales, arguments[1]);
1900 } 1900 }
1901 ); 1901 );
1902 1902
1903 1903
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 1936
1937 1937
1938 /** 1938 /**
1939 * Returns type of the current break. 1939 * Returns type of the current break.
1940 */ 1940 */
1941 function breakType(iterator) { 1941 function breakType(iterator) {
1942 return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator)); 1942 return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator));
1943 } 1943 }
1944 1944
1945 1945
1946 AddBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1, 1946 AddBoundMethod(GlobalIntlv8BreakIterator, 'adoptText', adoptText, 1,
1947 'breakiterator'); 1947 'breakiterator');
1948 AddBoundMethod(Intl.v8BreakIterator, 'first', first, 0, 'breakiterator'); 1948 AddBoundMethod(GlobalIntlv8BreakIterator, 'first', first, 0, 'breakiterator');
1949 AddBoundMethod(Intl.v8BreakIterator, 'next', next, 0, 'breakiterator'); 1949 AddBoundMethod(GlobalIntlv8BreakIterator, 'next', next, 0, 'breakiterator');
1950 AddBoundMethod(Intl.v8BreakIterator, 'current', current, 0, 'breakiterator'); 1950 AddBoundMethod(GlobalIntlv8BreakIterator, 'current', current, 0,
1951 AddBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0, 1951 'breakiterator');
1952 AddBoundMethod(GlobalIntlv8BreakIterator, 'breakType', breakType, 0,
1952 'breakiterator'); 1953 'breakiterator');
1953 1954
1954 // Save references to Intl objects and methods we use, for added security. 1955 // Save references to Intl objects and methods we use, for added security.
1955 var savedObjects = { 1956 var savedObjects = {
1956 'collator': Intl.Collator, 1957 'collator': GlobalIntlCollator,
1957 'numberformat': Intl.NumberFormat, 1958 'numberformat': GlobalIntlNumberFormat,
1958 'dateformatall': Intl.DateTimeFormat, 1959 'dateformatall': GlobalIntlDateTimeFormat,
1959 'dateformatdate': Intl.DateTimeFormat, 1960 'dateformatdate': GlobalIntlDateTimeFormat,
1960 'dateformattime': Intl.DateTimeFormat 1961 'dateformattime': GlobalIntlDateTimeFormat
1961 }; 1962 };
1962 1963
1963 1964
1964 // Default (created with undefined locales and options parameters) collator, 1965 // Default (created with undefined locales and options parameters) collator,
1965 // number and date format instances. They'll be created as needed. 1966 // number and date format instances. They'll be created as needed.
1966 var defaultObjects = { 1967 var defaultObjects = {
1967 'collator': UNDEFINED, 1968 'collator': UNDEFINED,
1968 'numberformat': UNDEFINED, 1969 'numberformat': UNDEFINED,
1969 'dateformatall': UNDEFINED, 1970 'dateformatall': UNDEFINED,
1970 'dateformatdate': UNDEFINED, 1971 'dateformatdate': UNDEFINED,
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 } 2196 }
2196 ); 2197 );
2197 2198
2198 %FunctionRemovePrototype(FormatDateToParts); 2199 %FunctionRemovePrototype(FormatDateToParts);
2199 2200
2200 utils.Export(function(to) { 2201 utils.Export(function(to) {
2201 to.FormatDateToParts = FormatDateToParts; 2202 to.FormatDateToParts = FormatDateToParts;
2202 }); 2203 });
2203 2204
2204 }) 2205 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698