Chromium Code Reviews| 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 ArrayJoin; | 20 var ArrayJoin; |
| 21 var ArrayPush; | 21 var ArrayPush; |
| 22 var GlobalDate = global.Date; | 22 var GlobalDate = global.Date; |
| 23 var GlobalNumber = global.Number; | 23 var GlobalNumber = global.Number; |
| 24 var GlobalRegExp = global.RegExp; | 24 var GlobalRegExp = global.RegExp; |
| 25 var GlobalString = global.String; | 25 var GlobalString = global.String; |
| 26 var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol"); | |
| 26 var InstallFunctions = utils.InstallFunctions; | 27 var InstallFunctions = utils.InstallFunctions; |
| 27 var InstallGetter = utils.InstallGetter; | 28 var InstallGetter = utils.InstallGetter; |
| 28 var InternalArray = utils.InternalArray; | 29 var InternalArray = utils.InternalArray; |
| 29 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); | 30 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); |
| 30 var OverrideFunction = utils.OverrideFunction; | 31 var OverrideFunction = utils.OverrideFunction; |
| 31 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); | 32 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); |
| 32 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); | 33 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); |
| 33 var SetFunctionName = utils.SetFunctionName; | 34 var SetFunctionName = utils.SetFunctionName; |
| 34 var StringSubstr = GlobalString.prototype.substr; | 35 var StringSubstr = GlobalString.prototype.substr; |
| 35 var StringSubstring = GlobalString.prototype.substring; | 36 var StringSubstring = GlobalString.prototype.substring; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 50 %CheckIsBootstrapping(); | 51 %CheckIsBootstrapping(); |
| 51 SetFunctionName(func, name); | 52 SetFunctionName(func, name); |
| 52 %AddNamedProperty(object, name, func, DONT_ENUM); | 53 %AddNamedProperty(object, name, func, DONT_ENUM); |
| 53 %SetNativeFlag(func); | 54 %SetNativeFlag(func); |
| 54 %ToFastProperties(object); | 55 %ToFastProperties(object); |
| 55 } | 56 } |
| 56 | 57 |
| 57 /** | 58 /** |
| 58 * Adds bound method to the prototype of the given object. | 59 * Adds bound method to the prototype of the given object. |
| 59 */ | 60 */ |
| 60 function AddBoundMethod(obj, methodName, implementation, length, type) { | 61 function AddBoundMethod(obj, methodName, implementation, length, typename, compa t) { |
|
Yang
2016/12/23 09:05:46
80 char limit
Dan Ehrenberg
2016/12/23 14:01:53
Done.
| |
| 61 %CheckIsBootstrapping(); | 62 %CheckIsBootstrapping(); |
| 62 var internalName = %CreatePrivateSymbol(methodName); | 63 var internalName = %CreatePrivateSymbol(methodName); |
| 63 // Making getter an anonymous function will cause | 64 // Making getter an anonymous function will cause |
| 64 // %DefineGetterPropertyUnchecked to properly set the "name" | 65 // %DefineGetterPropertyUnchecked to properly set the "name" |
| 65 // property on each JSFunction instance created here, rather | 66 // property on each JSFunction instance created here, rather |
| 66 // than (as utils.InstallGetter would) on the SharedFunctionInfo | 67 // than (as utils.InstallGetter would) on the SharedFunctionInfo |
| 67 // associated with all functions returned from AddBoundMethod. | 68 // associated with all functions returned from AddBoundMethod. |
| 68 var getter = ANONYMOUS_FUNCTION(function() { | 69 var getter = ANONYMOUS_FUNCTION(function() { |
| 69 if (!%IsInitializedIntlObjectOfType(this, type)) { | 70 var receiver = Unwrap(this, typename, obj, methodName, compat); |
| 70 throw %make_type_error(kMethodCalledOnWrongObject, methodName); | 71 if (IS_UNDEFINED(receiver[internalName])) { |
| 71 } | |
| 72 if (IS_UNDEFINED(this[internalName])) { | |
| 73 var boundMethod; | 72 var boundMethod; |
| 74 if (IS_UNDEFINED(length) || length === 2) { | 73 if (IS_UNDEFINED(length) || length === 2) { |
| 75 boundMethod = | 74 boundMethod = |
| 76 ANONYMOUS_FUNCTION((fst, snd) => implementation(this, fst, snd)); | 75 ANONYMOUS_FUNCTION((fst, snd) => implementation(receiver, fst, snd)); |
| 77 } else if (length === 1) { | 76 } else if (length === 1) { |
| 78 boundMethod = ANONYMOUS_FUNCTION(fst => implementation(this, fst)); | 77 boundMethod = ANONYMOUS_FUNCTION(fst => implementation(receiver, fst)); |
| 79 } else { | 78 } else { |
| 80 boundMethod = ANONYMOUS_FUNCTION((...args) => { | 79 boundMethod = ANONYMOUS_FUNCTION((...args) => { |
| 81 // DateTimeFormat.format needs to be 0 arg method, but can still | 80 // DateTimeFormat.format needs to be 0 arg method, but can still |
| 82 // receive an optional dateValue param. If one was provided, pass it | 81 // receive an optional dateValue param. If one was provided, pass it |
| 83 // along. | 82 // along. |
| 84 if (args.length > 0) { | 83 if (args.length > 0) { |
| 85 return implementation(this, args[0]); | 84 return implementation(receiver, args[0]); |
| 86 } else { | 85 } else { |
| 87 return implementation(this); | 86 return implementation(receiver); |
| 88 } | 87 } |
| 89 }); | 88 }); |
| 90 } | 89 } |
| 91 %SetNativeFlag(boundMethod); | 90 %SetNativeFlag(boundMethod); |
| 92 this[internalName] = boundMethod; | 91 receiver[internalName] = boundMethod; |
| 93 } | 92 } |
| 94 return this[internalName]; | 93 return receiver[internalName]; |
| 95 }); | 94 }); |
| 96 | 95 |
| 97 %FunctionRemovePrototype(getter); | 96 %FunctionRemovePrototype(getter); |
| 98 %DefineGetterPropertyUnchecked(obj.prototype, methodName, getter, DONT_ENUM); | 97 %DefineGetterPropertyUnchecked(obj.prototype, methodName, getter, DONT_ENUM); |
| 99 %SetNativeFlag(getter); | 98 %SetNativeFlag(getter); |
| 100 } | 99 } |
| 101 | 100 |
| 101 function IntlConstruct(receiver, constructor, initializer, newTarget, args, | |
| 102 compat) { | |
| 103 var locales = args[0]; | |
| 104 var options = args[1]; | |
| 105 | |
| 106 if (IS_UNDEFINED(newTarget)) { | |
| 107 if (compat && receiver instanceof constructor) { | |
| 108 let success = %object_define_property(receiver, IntlFallbackSymbol, | |
| 109 { value: new constructor(locales, options) }); | |
| 110 if (!success) { | |
| 111 throw %make_type_error(kReinitializeIntl, constructor); | |
| 112 } | |
| 113 return receiver; | |
| 114 } | |
| 115 | |
| 116 return new constructor(locales, options); | |
| 117 } | |
| 118 | |
| 119 return initializer(receiver, locales, options); | |
| 120 } | |
| 121 | |
| 122 | |
| 123 | |
| 124 function Unwrap(receiver, typename, constructor, method, compat) { | |
| 125 if (!%IsInitializedIntlObjectOfType(receiver, typename)) { | |
| 126 if (compat && receiver instanceof constructor) { | |
| 127 let fallback = receiver[IntlFallbackSymbol]; | |
| 128 if (%IsInitializedIntlObjectOfType(fallback, typename)) { | |
| 129 return fallback; | |
| 130 } | |
| 131 } | |
| 132 throw %make_type_error(kIncompatibleMethodReceiver, method, receiver); | |
| 133 } | |
| 134 return receiver; | |
| 135 } | |
| 136 | |
| 137 | |
| 102 // ------------------------------------------------------------------- | 138 // ------------------------------------------------------------------- |
| 103 | 139 |
| 104 var Intl = {}; | 140 var Intl = {}; |
| 105 | 141 |
| 106 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); | 142 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
| 107 | 143 |
| 108 /** | 144 /** |
| 109 * Caches available locales for each service. | 145 * Caches available locales for each service. |
| 110 */ | 146 */ |
| 111 var AVAILABLE_LOCALES = { | 147 var AVAILABLE_LOCALES = { |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 return collator; | 1058 return collator; |
| 1023 } | 1059 } |
| 1024 | 1060 |
| 1025 | 1061 |
| 1026 /** | 1062 /** |
| 1027 * Constructs Intl.Collator object given optional locales and options | 1063 * Constructs Intl.Collator object given optional locales and options |
| 1028 * parameters. | 1064 * parameters. |
| 1029 * | 1065 * |
| 1030 * @constructor | 1066 * @constructor |
| 1031 */ | 1067 */ |
| 1032 InstallConstructor(Intl, 'Collator', function() { | 1068 function Collator() { |
| 1033 var locales = arguments[0]; | 1069 return IntlConstruct(this, Collator, initializeCollator, new.target, |
| 1034 var options = arguments[1]; | 1070 arguments); |
| 1035 | 1071 } |
| 1036 if (!this || this === Intl) { | 1072 InstallConstructor(Intl, 'Collator', Collator); |
| 1037 // Constructor is called as a function. | |
| 1038 return new Intl.Collator(locales, options); | |
| 1039 } | |
| 1040 | |
| 1041 return initializeCollator(TO_OBJECT(this), locales, options); | |
| 1042 } | |
| 1043 ); | |
| 1044 | 1073 |
| 1045 | 1074 |
| 1046 /** | 1075 /** |
| 1047 * Collator resolvedOptions method. | 1076 * Collator resolvedOptions method. |
| 1048 */ | 1077 */ |
| 1049 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { | 1078 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { |
| 1050 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { | 1079 var coll = Unwrap(this, 'collator', Collator, 'resolvedOptions', false); |
| 1051 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "Collator"); | |
| 1052 } | |
| 1053 | |
| 1054 var coll = this; | |
| 1055 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, | 1080 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, |
| 1056 coll[resolvedSymbol].locale); | 1081 coll[resolvedSymbol].locale); |
| 1057 | 1082 |
| 1058 return { | 1083 return { |
| 1059 locale: locale, | 1084 locale: locale, |
| 1060 usage: coll[resolvedSymbol].usage, | 1085 usage: coll[resolvedSymbol].usage, |
| 1061 sensitivity: coll[resolvedSymbol].sensitivity, | 1086 sensitivity: coll[resolvedSymbol].sensitivity, |
| 1062 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, | 1087 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, |
| 1063 numeric: coll[resolvedSymbol].numeric, | 1088 numeric: coll[resolvedSymbol].numeric, |
| 1064 caseFirst: coll[resolvedSymbol].caseFirst, | 1089 caseFirst: coll[resolvedSymbol].caseFirst, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1089 * of this Collator object, and will be negative, zero, or positive, depending | 1114 * of this Collator object, and will be negative, zero, or positive, depending |
| 1090 * on whether x comes before y in the sort order, the Strings are equal under | 1115 * on whether x comes before y in the sort order, the Strings are equal under |
| 1091 * the sort order, or x comes after y in the sort order, respectively. | 1116 * the sort order, or x comes after y in the sort order, respectively. |
| 1092 */ | 1117 */ |
| 1093 function compare(collator, x, y) { | 1118 function compare(collator, x, y) { |
| 1094 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), | 1119 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), |
| 1095 TO_STRING(x), TO_STRING(y)); | 1120 TO_STRING(x), TO_STRING(y)); |
| 1096 }; | 1121 }; |
| 1097 | 1122 |
| 1098 | 1123 |
| 1099 AddBoundMethod(Intl.Collator, 'compare', compare, 2, 'collator'); | 1124 AddBoundMethod(Intl.Collator, 'compare', compare, 2, 'collator', false); |
| 1100 | 1125 |
| 1101 /** | 1126 /** |
| 1102 * Verifies that the input is a well-formed ISO 4217 currency code. | 1127 * Verifies that the input is a well-formed ISO 4217 currency code. |
| 1103 * Don't uppercase to test. It could convert invalid code into a valid one. | 1128 * Don't uppercase to test. It could convert invalid code into a valid one. |
| 1104 * For example \u00DFP (Eszett+P) becomes SSP. | 1129 * For example \u00DFP (Eszett+P) becomes SSP. |
| 1105 */ | 1130 */ |
| 1106 function isWellFormedCurrencyCode(currency) { | 1131 function isWellFormedCurrencyCode(currency) { |
| 1107 return typeof currency == "string" && currency.length == 3 && | 1132 return typeof currency == "string" && currency.length == 3 && |
| 1108 IS_NULL(%regexp_internal_match(/[^A-Za-z]/, currency)); | 1133 IS_NULL(%regexp_internal_match(/[^A-Za-z]/, currency)); |
| 1109 } | 1134 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1255 return numberFormat; | 1280 return numberFormat; |
| 1256 } | 1281 } |
| 1257 | 1282 |
| 1258 | 1283 |
| 1259 /** | 1284 /** |
| 1260 * Constructs Intl.NumberFormat object given optional locales and options | 1285 * Constructs Intl.NumberFormat object given optional locales and options |
| 1261 * parameters. | 1286 * parameters. |
| 1262 * | 1287 * |
| 1263 * @constructor | 1288 * @constructor |
| 1264 */ | 1289 */ |
| 1265 InstallConstructor(Intl, 'NumberFormat', function() { | 1290 function NumberFormat() { |
| 1266 var locales = arguments[0]; | 1291 return IntlConstruct(this, NumberFormat, initializeNumberFormat, new.target, |
| 1267 var options = arguments[1]; | 1292 arguments, true); |
| 1268 | 1293 } |
| 1269 if (!this || this === Intl) { | 1294 InstallConstructor(Intl, 'NumberFormat', NumberFormat); |
| 1270 // Constructor is called as a function. | |
| 1271 return new Intl.NumberFormat(locales, options); | |
| 1272 } | |
| 1273 | |
| 1274 return initializeNumberFormat(TO_OBJECT(this), locales, options); | |
| 1275 } | |
| 1276 ); | |
| 1277 | 1295 |
| 1278 | 1296 |
| 1279 /** | 1297 /** |
| 1280 * NumberFormat resolvedOptions method. | 1298 * NumberFormat resolvedOptions method. |
| 1281 */ | 1299 */ |
| 1282 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { | 1300 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
| 1283 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { | 1301 var format = Unwrap(this, 'numberformat', NumberFormat, |
| 1284 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "NumberFormat"); | 1302 'resolvedOptions', true); |
| 1285 } | |
| 1286 | |
| 1287 var format = this; | |
| 1288 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, | 1303 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, |
| 1289 format[resolvedSymbol].locale); | 1304 format[resolvedSymbol].locale); |
| 1290 | 1305 |
| 1291 var result = { | 1306 var result = { |
| 1292 locale: locale, | 1307 locale: locale, |
| 1293 numberingSystem: format[resolvedSymbol].numberingSystem, | 1308 numberingSystem: format[resolvedSymbol].numberingSystem, |
| 1294 style: format[resolvedSymbol].style, | 1309 style: format[resolvedSymbol].style, |
| 1295 useGrouping: format[resolvedSymbol].useGrouping, | 1310 useGrouping: format[resolvedSymbol].useGrouping, |
| 1296 minimumIntegerDigits: format[resolvedSymbol].minimumIntegerDigits, | 1311 minimumIntegerDigits: format[resolvedSymbol].minimumIntegerDigits, |
| 1297 minimumFractionDigits: format[resolvedSymbol].minimumFractionDigits, | 1312 minimumFractionDigits: format[resolvedSymbol].minimumFractionDigits, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 */ | 1353 */ |
| 1339 function formatNumber(formatter, value) { | 1354 function formatNumber(formatter, value) { |
| 1340 // Spec treats -0 and +0 as 0. | 1355 // Spec treats -0 and +0 as 0. |
| 1341 var number = TO_NUMBER(value) + 0; | 1356 var number = TO_NUMBER(value) + 0; |
| 1342 | 1357 |
| 1343 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), | 1358 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), |
| 1344 number); | 1359 number); |
| 1345 } | 1360 } |
| 1346 | 1361 |
| 1347 | 1362 |
| 1348 AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1, 'numberformat'); | 1363 AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1, 'numberformat', tru e); |
| 1349 | 1364 |
| 1350 /** | 1365 /** |
| 1351 * Returns a string that matches LDML representation of the options object. | 1366 * Returns a string that matches LDML representation of the options object. |
| 1352 */ | 1367 */ |
| 1353 function toLDMLString(options) { | 1368 function toLDMLString(options) { |
| 1354 var getOption = getGetOption(options, 'dateformat'); | 1369 var getOption = getGetOption(options, 'dateformat'); |
| 1355 | 1370 |
| 1356 var ldmlString = ''; | 1371 var ldmlString = ''; |
| 1357 | 1372 |
| 1358 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']); | 1373 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1631 return dateFormat; | 1646 return dateFormat; |
| 1632 } | 1647 } |
| 1633 | 1648 |
| 1634 | 1649 |
| 1635 /** | 1650 /** |
| 1636 * Constructs Intl.DateTimeFormat object given optional locales and options | 1651 * Constructs Intl.DateTimeFormat object given optional locales and options |
| 1637 * parameters. | 1652 * parameters. |
| 1638 * | 1653 * |
| 1639 * @constructor | 1654 * @constructor |
| 1640 */ | 1655 */ |
| 1641 InstallConstructor(Intl, 'DateTimeFormat', function() { | 1656 function DateTimeFormat() { |
| 1642 var locales = arguments[0]; | 1657 return IntlConstruct(this, DateTimeFormat, initializeDateTimeFormat, |
| 1643 var options = arguments[1]; | 1658 new.target, arguments, true); |
| 1644 | 1659 } |
| 1645 if (!this || this === Intl) { | 1660 InstallConstructor(Intl, 'DateTimeFormat', DateTimeFormat); |
| 1646 // Constructor is called as a function. | |
| 1647 return new Intl.DateTimeFormat(locales, options); | |
| 1648 } | |
| 1649 | |
| 1650 return initializeDateTimeFormat(TO_OBJECT(this), locales, options); | |
| 1651 } | |
| 1652 ); | |
| 1653 | 1661 |
| 1654 | 1662 |
| 1655 /** | 1663 /** |
| 1656 * DateTimeFormat resolvedOptions method. | 1664 * DateTimeFormat resolvedOptions method. |
| 1657 */ | 1665 */ |
| 1658 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { | 1666 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
| 1659 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { | 1667 var format = Unwrap(this, 'dateformat', DateTimeFormat, |
| 1660 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "DateTimeFormat" ); | 1668 'resolvedOptions', true); |
| 1661 } | |
| 1662 | 1669 |
| 1663 /** | 1670 /** |
| 1664 * Maps ICU calendar names to LDML/BCP47 types for key 'ca'. | 1671 * Maps ICU calendar names to LDML/BCP47 types for key 'ca'. |
| 1665 * See typeMap section in third_party/icu/source/data/misc/keyTypeData.txt | 1672 * See typeMap section in third_party/icu/source/data/misc/keyTypeData.txt |
| 1666 * and | 1673 * and |
| 1667 * http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml | 1674 * http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml |
| 1668 */ | 1675 */ |
| 1669 var ICU_CALENDAR_MAP = { | 1676 var ICU_CALENDAR_MAP = { |
| 1670 'gregorian': 'gregory', | 1677 'gregorian': 'gregory', |
| 1671 'ethiopic-amete-alem': 'ethioaa' | 1678 'ethiopic-amete-alem': 'ethioaa' |
| 1672 }; | 1679 }; |
| 1673 | 1680 |
| 1674 var format = this; | |
| 1675 var fromPattern = fromLDMLString(format[resolvedSymbol][patternSymbol]); | 1681 var fromPattern = fromLDMLString(format[resolvedSymbol][patternSymbol]); |
| 1676 var userCalendar = ICU_CALENDAR_MAP[format[resolvedSymbol].calendar]; | 1682 var userCalendar = ICU_CALENDAR_MAP[format[resolvedSymbol].calendar]; |
| 1677 if (IS_UNDEFINED(userCalendar)) { | 1683 if (IS_UNDEFINED(userCalendar)) { |
| 1678 // No match means that ICU's legacy name is identical to LDML/BCP type. | 1684 // No match means that ICU's legacy name is identical to LDML/BCP type. |
| 1679 userCalendar = format[resolvedSymbol].calendar; | 1685 userCalendar = format[resolvedSymbol].calendar; |
| 1680 } | 1686 } |
| 1681 | 1687 |
| 1682 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, | 1688 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, |
| 1683 format[resolvedSymbol].locale); | 1689 format[resolvedSymbol].locale); |
| 1684 | 1690 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1751 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); | 1757 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); |
| 1752 | 1758 |
| 1753 return %InternalDateFormatToParts( | 1759 return %InternalDateFormatToParts( |
| 1754 %GetImplFromInitializedIntlObject(this), new GlobalDate(dateMs)); | 1760 %GetImplFromInitializedIntlObject(this), new GlobalDate(dateMs)); |
| 1755 } | 1761 } |
| 1756 | 1762 |
| 1757 %FunctionSetLength(FormatDateToParts, 0); | 1763 %FunctionSetLength(FormatDateToParts, 0); |
| 1758 | 1764 |
| 1759 | 1765 |
| 1760 // 0 because date is optional argument. | 1766 // 0 because date is optional argument. |
| 1761 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0, 'dateformat'); | 1767 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0, 'dateformat', true) ; |
| 1762 | 1768 |
| 1763 | 1769 |
| 1764 /** | 1770 /** |
| 1765 * Returns canonical Area/Location(/Location) name, or throws an exception | 1771 * Returns canonical Area/Location(/Location) name, or throws an exception |
| 1766 * if the zone name is invalid IANA name. | 1772 * if the zone name is invalid IANA name. |
| 1767 */ | 1773 */ |
| 1768 function canonicalizeTimeZoneID(tzID) { | 1774 function canonicalizeTimeZoneID(tzID) { |
| 1769 // Skip undefined zones. | 1775 // Skip undefined zones. |
| 1770 if (IS_UNDEFINED(tzID)) { | 1776 if (IS_UNDEFINED(tzID)) { |
| 1771 return tzID; | 1777 return tzID; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1840 return iterator; | 1846 return iterator; |
| 1841 } | 1847 } |
| 1842 | 1848 |
| 1843 | 1849 |
| 1844 /** | 1850 /** |
| 1845 * Constructs Intl.v8BreakIterator object given optional locales and options | 1851 * Constructs Intl.v8BreakIterator object given optional locales and options |
| 1846 * parameters. | 1852 * parameters. |
| 1847 * | 1853 * |
| 1848 * @constructor | 1854 * @constructor |
| 1849 */ | 1855 */ |
| 1850 InstallConstructor(Intl, 'v8BreakIterator', function() { | 1856 function v8BreakIterator() { |
| 1851 var locales = arguments[0]; | 1857 return IntlConstruct(this, v8BreakIterator, initializeBreakIterator, |
| 1852 var options = arguments[1]; | 1858 new.target, arguments); |
| 1853 | 1859 } |
| 1854 if (!this || this === Intl) { | 1860 InstallConstructor(Intl, 'v8BreakIterator', v8BreakIterator); |
| 1855 // Constructor is called as a function. | |
| 1856 return new Intl.v8BreakIterator(locales, options); | |
| 1857 } | |
| 1858 | |
| 1859 return initializeBreakIterator(TO_OBJECT(this), locales, options); | |
| 1860 } | |
| 1861 ); | |
| 1862 | 1861 |
| 1863 | 1862 |
| 1864 /** | 1863 /** |
| 1865 * BreakIterator resolvedOptions method. | 1864 * BreakIterator resolvedOptions method. |
| 1866 */ | 1865 */ |
| 1867 InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions', | 1866 InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions', |
| 1868 function() { | 1867 function() { |
| 1869 if (!IS_UNDEFINED(new.target)) { | 1868 if (!IS_UNDEFINED(new.target)) { |
| 1870 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); | 1869 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
| 1871 } | 1870 } |
| 1872 | 1871 |
| 1873 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { | 1872 var segmenter = Unwrap(this, 'breakiterator', v8BreakIterator, |
| 1874 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "v8BreakIterator "); | 1873 'resolvedOptions', false); |
| 1875 } | |
| 1876 | 1874 |
| 1877 var segmenter = this; | |
| 1878 var locale = | 1875 var locale = |
| 1879 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale, | 1876 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale, |
| 1880 segmenter[resolvedSymbol].locale); | 1877 segmenter[resolvedSymbol].locale); |
| 1881 | 1878 |
| 1882 return { | 1879 return { |
| 1883 locale: locale, | 1880 locale: locale, |
| 1884 type: segmenter[resolvedSymbol].type | 1881 type: segmenter[resolvedSymbol].type |
| 1885 }; | 1882 }; |
| 1886 } | 1883 } |
| 1887 ); | 1884 ); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2198 } | 2195 } |
| 2199 ); | 2196 ); |
| 2200 | 2197 |
| 2201 %FunctionRemovePrototype(FormatDateToParts); | 2198 %FunctionRemovePrototype(FormatDateToParts); |
| 2202 | 2199 |
| 2203 utils.Export(function(to) { | 2200 utils.Export(function(to) { |
| 2204 to.FormatDateToParts = FormatDateToParts; | 2201 to.FormatDateToParts = FormatDateToParts; |
| 2205 }); | 2202 }); |
| 2206 | 2203 |
| 2207 }) | 2204 }) |
| OLD | NEW |