| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 */ | 225 */ |
| 226 var ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR = | 226 var ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR = |
| 227 'Function object that\'s not a constructor was created with new'; | 227 'Function object that\'s not a constructor was created with new'; |
| 228 | 228 |
| 229 | 229 |
| 230 /** | 230 /** |
| 231 * Adds bound method to the prototype of the given object. | 231 * Adds bound method to the prototype of the given object. |
| 232 */ | 232 */ |
| 233 function addBoundMethod(obj, methodName, implementation, length) { | 233 function addBoundMethod(obj, methodName, implementation, length) { |
| 234 function getter() { | 234 function getter() { |
| 235 if (!%IsInitializedIntlObject(this)) { | 235 if (!this || typeof this !== 'object' || |
| 236 this.__initializedIntlObject === undefined) { |
| 236 throw new $TypeError('Method ' + methodName + ' called on a ' + | 237 throw new $TypeError('Method ' + methodName + ' called on a ' + |
| 237 'non-object or on a wrong type of object.'); | 238 'non-object or on a wrong type of object.'); |
| 238 } | 239 } |
| 239 var internalName = '__bound' + methodName + '__'; | 240 var internalName = '__bound' + methodName + '__'; |
| 240 if (this[internalName] === undefined) { | 241 if (this[internalName] === undefined) { |
| 241 var that = this; | 242 var that = this; |
| 242 var boundMethod; | 243 var boundMethod; |
| 243 if (length === undefined || length === 2) { | 244 if (length === undefined || length === 2) { |
| 244 boundMethod = function(x, y) { | 245 boundMethod = function(x, y) { |
| 245 if (%_IsConstructCall()) { | 246 if (%_IsConstructCall()) { |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 var languageTag = | 889 var languageTag = |
| 889 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; | 890 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; |
| 890 LANGUAGE_TAG_RE = new $RegExp(languageTag, 'i'); | 891 LANGUAGE_TAG_RE = new $RegExp(languageTag, 'i'); |
| 891 } | 892 } |
| 892 | 893 |
| 893 /** | 894 /** |
| 894 * Initializes the given object so it's a valid Collator instance. | 895 * Initializes the given object so it's a valid Collator instance. |
| 895 * Useful for subclassing. | 896 * Useful for subclassing. |
| 896 */ | 897 */ |
| 897 function initializeCollator(collator, locales, options) { | 898 function initializeCollator(collator, locales, options) { |
| 898 if (%IsInitializedIntlObject(collator)) { | 899 if (collator.hasOwnProperty('__initializedIntlObject')) { |
| 899 throw new $TypeError('Trying to re-initialize Collator object.'); | 900 throw new $TypeError('Trying to re-initialize Collator object.'); |
| 900 } | 901 } |
| 901 | 902 |
| 902 if (options === undefined) { | 903 if (options === undefined) { |
| 903 options = {}; | 904 options = {}; |
| 904 } | 905 } |
| 905 | 906 |
| 906 var getOption = getGetOption(options, 'collator'); | 907 var getOption = getGetOption(options, 'collator'); |
| 907 | 908 |
| 908 var internalOptions = {}; | 909 var internalOptions = {}; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 sensitivity: {writable: true}, | 960 sensitivity: {writable: true}, |
| 960 strength: {writable: true}, | 961 strength: {writable: true}, |
| 961 usage: {value: internalOptions.usage, writable: true} | 962 usage: {value: internalOptions.usage, writable: true} |
| 962 }); | 963 }); |
| 963 | 964 |
| 964 var internalCollator = %CreateCollator(requestedLocale, | 965 var internalCollator = %CreateCollator(requestedLocale, |
| 965 internalOptions, | 966 internalOptions, |
| 966 resolved); | 967 resolved); |
| 967 | 968 |
| 968 // Writable, configurable and enumerable are set to false by default. | 969 // Writable, configurable and enumerable are set to false by default. |
| 969 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); | 970 $Object.defineProperty(collator, 'collator', {value: internalCollator}); |
| 971 $Object.defineProperty(collator, '__initializedIntlObject', |
| 972 {value: 'collator'}); |
| 970 $Object.defineProperty(collator, 'resolved', {value: resolved}); | 973 $Object.defineProperty(collator, 'resolved', {value: resolved}); |
| 971 | 974 |
| 972 return collator; | 975 return collator; |
| 973 } | 976 } |
| 974 | 977 |
| 975 | 978 |
| 976 /** | 979 /** |
| 977 * Constructs Intl.Collator object given optional locales and options | 980 * Constructs Intl.Collator object given optional locales and options |
| 978 * parameters. | 981 * parameters. |
| 979 * | 982 * |
| (...skipping 15 matching lines...) Expand all Loading... |
| 995 | 998 |
| 996 | 999 |
| 997 /** | 1000 /** |
| 998 * Collator resolvedOptions method. | 1001 * Collator resolvedOptions method. |
| 999 */ | 1002 */ |
| 1000 %SetProperty(Intl.Collator.prototype, 'resolvedOptions', function() { | 1003 %SetProperty(Intl.Collator.prototype, 'resolvedOptions', function() { |
| 1001 if (%_IsConstructCall()) { | 1004 if (%_IsConstructCall()) { |
| 1002 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | 1005 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
| 1003 } | 1006 } |
| 1004 | 1007 |
| 1005 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { | 1008 if (!this || typeof this !== 'object' || |
| 1009 this.__initializedIntlObject !== 'collator') { |
| 1006 throw new $TypeError('resolvedOptions method called on a non-object ' + | 1010 throw new $TypeError('resolvedOptions method called on a non-object ' + |
| 1007 'or on a object that is not Intl.Collator.'); | 1011 'or on a object that is not Intl.Collator.'); |
| 1008 } | 1012 } |
| 1009 | 1013 |
| 1010 var coll = this; | 1014 var coll = this; |
| 1011 var locale = getOptimalLanguageTag(coll.resolved.requestedLocale, | 1015 var locale = getOptimalLanguageTag(coll.resolved.requestedLocale, |
| 1012 coll.resolved.locale); | 1016 coll.resolved.locale); |
| 1013 | 1017 |
| 1014 return { | 1018 return { |
| 1015 locale: locale, | 1019 locale: locale, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 * When the compare method is called with two arguments x and y, it returns a | 1056 * When the compare method is called with two arguments x and y, it returns a |
| 1053 * Number other than NaN that represents the result of a locale-sensitive | 1057 * Number other than NaN that represents the result of a locale-sensitive |
| 1054 * String comparison of x with y. | 1058 * String comparison of x with y. |
| 1055 * The result is intended to order String values in the sort order specified | 1059 * The result is intended to order String values in the sort order specified |
| 1056 * by the effective locale and collation options computed during construction | 1060 * by the effective locale and collation options computed during construction |
| 1057 * of this Collator object, and will be negative, zero, or positive, depending | 1061 * of this Collator object, and will be negative, zero, or positive, depending |
| 1058 * on whether x comes before y in the sort order, the Strings are equal under | 1062 * on whether x comes before y in the sort order, the Strings are equal under |
| 1059 * the sort order, or x comes after y in the sort order, respectively. | 1063 * the sort order, or x comes after y in the sort order, respectively. |
| 1060 */ | 1064 */ |
| 1061 function compare(collator, x, y) { | 1065 function compare(collator, x, y) { |
| 1062 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), | 1066 return %InternalCompare(collator.collator, $String(x), $String(y)); |
| 1063 $String(x), $String(y)); | |
| 1064 }; | 1067 }; |
| 1065 | 1068 |
| 1066 | 1069 |
| 1067 addBoundMethod(Intl.Collator, 'compare', compare, 2); | 1070 addBoundMethod(Intl.Collator, 'compare', compare, 2); |
| 1068 | 1071 |
| 1069 /** | 1072 /** |
| 1070 * Verifies that the input is a well-formed ISO 4217 currency code. | 1073 * Verifies that the input is a well-formed ISO 4217 currency code. |
| 1071 * Don't uppercase to test. It could convert invalid code into a valid one. | 1074 * Don't uppercase to test. It could convert invalid code into a valid one. |
| 1072 * For example \u00DFP (Eszett+P) becomes SSP. | 1075 * For example \u00DFP (Eszett+P) becomes SSP. |
| 1073 */ | 1076 */ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1094 | 1097 |
| 1095 return fallback; | 1098 return fallback; |
| 1096 } | 1099 } |
| 1097 | 1100 |
| 1098 | 1101 |
| 1099 /** | 1102 /** |
| 1100 * Initializes the given object so it's a valid NumberFormat instance. | 1103 * Initializes the given object so it's a valid NumberFormat instance. |
| 1101 * Useful for subclassing. | 1104 * Useful for subclassing. |
| 1102 */ | 1105 */ |
| 1103 function initializeNumberFormat(numberFormat, locales, options) { | 1106 function initializeNumberFormat(numberFormat, locales, options) { |
| 1104 if (%IsInitializedIntlObject(numberFormat)) { | 1107 if (numberFormat.hasOwnProperty('__initializedIntlObject')) { |
| 1105 throw new $TypeError('Trying to re-initialize NumberFormat object.'); | 1108 throw new $TypeError('Trying to re-initialize NumberFormat object.'); |
| 1106 } | 1109 } |
| 1107 | 1110 |
| 1108 if (options === undefined) { | 1111 if (options === undefined) { |
| 1109 options = {}; | 1112 options = {}; |
| 1110 } | 1113 } |
| 1111 | 1114 |
| 1112 var getOption = getGetOption(options, 'numberformat'); | 1115 var getOption = getGetOption(options, 'numberformat'); |
| 1113 | 1116 |
| 1114 var locale = resolveLocale('numberformat', locales, options); | 1117 var locale = resolveLocale('numberformat', locales, options); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 internalOptions, | 1189 internalOptions, |
| 1187 resolved); | 1190 resolved); |
| 1188 | 1191 |
| 1189 // We can't get information about number or currency style from ICU, so we | 1192 // We can't get information about number or currency style from ICU, so we |
| 1190 // assume user request was fulfilled. | 1193 // assume user request was fulfilled. |
| 1191 if (internalOptions.style === 'currency') { | 1194 if (internalOptions.style === 'currency') { |
| 1192 $Object.defineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, | 1195 $Object.defineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, |
| 1193 writable: true}); | 1196 writable: true}); |
| 1194 } | 1197 } |
| 1195 | 1198 |
| 1196 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); | 1199 $Object.defineProperty(numberFormat, 'formatter', {value: formatter}); |
| 1197 $Object.defineProperty(numberFormat, 'resolved', {value: resolved}); | 1200 $Object.defineProperty(numberFormat, 'resolved', {value: resolved}); |
| 1201 $Object.defineProperty(numberFormat, '__initializedIntlObject', |
| 1202 {value: 'numberformat'}); |
| 1198 | 1203 |
| 1199 return numberFormat; | 1204 return numberFormat; |
| 1200 } | 1205 } |
| 1201 | 1206 |
| 1202 | 1207 |
| 1203 /** | 1208 /** |
| 1204 * Constructs Intl.NumberFormat object given optional locales and options | 1209 * Constructs Intl.NumberFormat object given optional locales and options |
| 1205 * parameters. | 1210 * parameters. |
| 1206 * | 1211 * |
| 1207 * @constructor | 1212 * @constructor |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1222 | 1227 |
| 1223 | 1228 |
| 1224 /** | 1229 /** |
| 1225 * NumberFormat resolvedOptions method. | 1230 * NumberFormat resolvedOptions method. |
| 1226 */ | 1231 */ |
| 1227 %SetProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { | 1232 %SetProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
| 1228 if (%_IsConstructCall()) { | 1233 if (%_IsConstructCall()) { |
| 1229 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | 1234 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
| 1230 } | 1235 } |
| 1231 | 1236 |
| 1232 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { | 1237 if (!this || typeof this !== 'object' || |
| 1238 this.__initializedIntlObject !== 'numberformat') { |
| 1233 throw new $TypeError('resolvedOptions method called on a non-object' + | 1239 throw new $TypeError('resolvedOptions method called on a non-object' + |
| 1234 ' or on a object that is not Intl.NumberFormat.'); | 1240 ' or on a object that is not Intl.NumberFormat.'); |
| 1235 } | 1241 } |
| 1236 | 1242 |
| 1237 var format = this; | 1243 var format = this; |
| 1238 var locale = getOptimalLanguageTag(format.resolved.requestedLocale, | 1244 var locale = getOptimalLanguageTag(format.resolved.requestedLocale, |
| 1239 format.resolved.locale); | 1245 format.resolved.locale); |
| 1240 | 1246 |
| 1241 var result = { | 1247 var result = { |
| 1242 locale: locale, | 1248 locale: locale, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 | 1302 |
| 1297 /** | 1303 /** |
| 1298 * Returns a String value representing the result of calling ToNumber(value) | 1304 * Returns a String value representing the result of calling ToNumber(value) |
| 1299 * according to the effective locale and the formatting options of this | 1305 * according to the effective locale and the formatting options of this |
| 1300 * NumberFormat. | 1306 * NumberFormat. |
| 1301 */ | 1307 */ |
| 1302 function formatNumber(formatter, value) { | 1308 function formatNumber(formatter, value) { |
| 1303 // Spec treats -0 and +0 as 0. | 1309 // Spec treats -0 and +0 as 0. |
| 1304 var number = $Number(value) + 0; | 1310 var number = $Number(value) + 0; |
| 1305 | 1311 |
| 1306 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), | 1312 return %InternalNumberFormat(formatter.formatter, number); |
| 1307 number); | |
| 1308 } | 1313 } |
| 1309 | 1314 |
| 1310 | 1315 |
| 1311 /** | 1316 /** |
| 1312 * Returns a Number that represents string value that was passed in. | 1317 * Returns a Number that represents string value that was passed in. |
| 1313 */ | 1318 */ |
| 1314 function parseNumber(formatter, value) { | 1319 function parseNumber(formatter, value) { |
| 1315 return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), | 1320 return %InternalNumberParse(formatter.formatter, $String(value)); |
| 1316 $String(value)); | |
| 1317 } | 1321 } |
| 1318 | 1322 |
| 1319 | 1323 |
| 1320 addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); | 1324 addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); |
| 1321 addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); | 1325 addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); |
| 1322 | 1326 |
| 1323 /** | 1327 /** |
| 1324 * Returns a string that matches LDML representation of the options object. | 1328 * Returns a string that matches LDML representation of the options object. |
| 1325 */ | 1329 */ |
| 1326 function toLDMLString(options) { | 1330 function toLDMLString(options) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 return options; | 1523 return options; |
| 1520 } | 1524 } |
| 1521 | 1525 |
| 1522 | 1526 |
| 1523 /** | 1527 /** |
| 1524 * Initializes the given object so it's a valid DateTimeFormat instance. | 1528 * Initializes the given object so it's a valid DateTimeFormat instance. |
| 1525 * Useful for subclassing. | 1529 * Useful for subclassing. |
| 1526 */ | 1530 */ |
| 1527 function initializeDateTimeFormat(dateFormat, locales, options) { | 1531 function initializeDateTimeFormat(dateFormat, locales, options) { |
| 1528 | 1532 |
| 1529 if (%IsInitializedIntlObject(dateFormat)) { | 1533 if (dateFormat.hasOwnProperty('__initializedIntlObject')) { |
| 1530 throw new $TypeError('Trying to re-initialize DateTimeFormat object.'); | 1534 throw new $TypeError('Trying to re-initialize DateTimeFormat object.'); |
| 1531 } | 1535 } |
| 1532 | 1536 |
| 1533 if (options === undefined) { | 1537 if (options === undefined) { |
| 1534 options = {}; | 1538 options = {}; |
| 1535 } | 1539 } |
| 1536 | 1540 |
| 1537 var locale = resolveLocale('dateformat', locales, options); | 1541 var locale = resolveLocale('dateformat', locales, options); |
| 1538 | 1542 |
| 1539 options = toDateTimeOptions(options, 'any', 'date'); | 1543 options = toDateTimeOptions(options, 'any', 'date'); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 year: {writable: true} | 1585 year: {writable: true} |
| 1582 }); | 1586 }); |
| 1583 | 1587 |
| 1584 var formatter = %CreateDateTimeFormat( | 1588 var formatter = %CreateDateTimeFormat( |
| 1585 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); | 1589 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); |
| 1586 | 1590 |
| 1587 if (tz !== undefined && tz !== resolved.timeZone) { | 1591 if (tz !== undefined && tz !== resolved.timeZone) { |
| 1588 throw new $RangeError('Unsupported time zone specified ' + tz); | 1592 throw new $RangeError('Unsupported time zone specified ' + tz); |
| 1589 } | 1593 } |
| 1590 | 1594 |
| 1591 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); | 1595 $Object.defineProperty(dateFormat, 'formatter', {value: formatter}); |
| 1592 $Object.defineProperty(dateFormat, 'resolved', {value: resolved}); | 1596 $Object.defineProperty(dateFormat, 'resolved', {value: resolved}); |
| 1597 $Object.defineProperty(dateFormat, '__initializedIntlObject', |
| 1598 {value: 'dateformat'}); |
| 1593 | 1599 |
| 1594 return dateFormat; | 1600 return dateFormat; |
| 1595 } | 1601 } |
| 1596 | 1602 |
| 1597 | 1603 |
| 1598 /** | 1604 /** |
| 1599 * Constructs Intl.DateTimeFormat object given optional locales and options | 1605 * Constructs Intl.DateTimeFormat object given optional locales and options |
| 1600 * parameters. | 1606 * parameters. |
| 1601 * | 1607 * |
| 1602 * @constructor | 1608 * @constructor |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1617 | 1623 |
| 1618 | 1624 |
| 1619 /** | 1625 /** |
| 1620 * DateTimeFormat resolvedOptions method. | 1626 * DateTimeFormat resolvedOptions method. |
| 1621 */ | 1627 */ |
| 1622 %SetProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { | 1628 %SetProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
| 1623 if (%_IsConstructCall()) { | 1629 if (%_IsConstructCall()) { |
| 1624 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | 1630 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
| 1625 } | 1631 } |
| 1626 | 1632 |
| 1627 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { | 1633 if (!this || typeof this !== 'object' || |
| 1634 this.__initializedIntlObject !== 'dateformat') { |
| 1628 throw new $TypeError('resolvedOptions method called on a non-object or ' + | 1635 throw new $TypeError('resolvedOptions method called on a non-object or ' + |
| 1629 'on a object that is not Intl.DateTimeFormat.'); | 1636 'on a object that is not Intl.DateTimeFormat.'); |
| 1630 } | 1637 } |
| 1631 | 1638 |
| 1632 var format = this; | 1639 var format = this; |
| 1633 var fromPattern = fromLDMLString(format.resolved.pattern); | 1640 var fromPattern = fromLDMLString(format.resolved.pattern); |
| 1634 var userCalendar = ICU_CALENDAR_MAP[format.resolved.calendar]; | 1641 var userCalendar = ICU_CALENDAR_MAP[format.resolved.calendar]; |
| 1635 if (userCalendar === undefined) { | 1642 if (userCalendar === undefined) { |
| 1636 // Use ICU name if we don't have a match. It shouldn't happen, but | 1643 // Use ICU name if we don't have a match. It shouldn't happen, but |
| 1637 // it would be too strict to throw for this. | 1644 // it would be too strict to throw for this. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 if (dateValue === undefined) { | 1706 if (dateValue === undefined) { |
| 1700 dateMs = $Date.now(); | 1707 dateMs = $Date.now(); |
| 1701 } else { | 1708 } else { |
| 1702 dateMs = $Number(dateValue); | 1709 dateMs = $Number(dateValue); |
| 1703 } | 1710 } |
| 1704 | 1711 |
| 1705 if (!$isFinite(dateMs)) { | 1712 if (!$isFinite(dateMs)) { |
| 1706 throw new $RangeError('Provided date is not in valid range.'); | 1713 throw new $RangeError('Provided date is not in valid range.'); |
| 1707 } | 1714 } |
| 1708 | 1715 |
| 1709 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), | 1716 return %InternalDateFormat(formatter.formatter, new $Date(dateMs)); |
| 1710 new $Date(dateMs)); | |
| 1711 } | 1717 } |
| 1712 | 1718 |
| 1713 | 1719 |
| 1714 /** | 1720 /** |
| 1715 * Returns a Date object representing the result of calling ToString(value) | 1721 * Returns a Date object representing the result of calling ToString(value) |
| 1716 * according to the effective locale and the formatting options of this | 1722 * according to the effective locale and the formatting options of this |
| 1717 * DateTimeFormat. | 1723 * DateTimeFormat. |
| 1718 * Returns undefined if date string cannot be parsed. | 1724 * Returns undefined if date string cannot be parsed. |
| 1719 */ | 1725 */ |
| 1720 function parseDate(formatter, value) { | 1726 function parseDate(formatter, value) { |
| 1721 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), | 1727 return %InternalDateParse(formatter.formatter, $String(value)); |
| 1722 $String(value)); | |
| 1723 } | 1728 } |
| 1724 | 1729 |
| 1725 | 1730 |
| 1726 // 0 because date is optional argument. | 1731 // 0 because date is optional argument. |
| 1727 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); | 1732 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); |
| 1728 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); | 1733 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); |
| 1729 | 1734 |
| 1730 | 1735 |
| 1731 /** | 1736 /** |
| 1732 * Returns canonical Area/Location name, or throws an exception if the zone | 1737 * Returns canonical Area/Location name, or throws an exception if the zone |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1760 } | 1765 } |
| 1761 | 1766 |
| 1762 return result; | 1767 return result; |
| 1763 } | 1768 } |
| 1764 | 1769 |
| 1765 /** | 1770 /** |
| 1766 * Initializes the given object so it's a valid BreakIterator instance. | 1771 * Initializes the given object so it's a valid BreakIterator instance. |
| 1767 * Useful for subclassing. | 1772 * Useful for subclassing. |
| 1768 */ | 1773 */ |
| 1769 function initializeBreakIterator(iterator, locales, options) { | 1774 function initializeBreakIterator(iterator, locales, options) { |
| 1770 if (%IsInitializedIntlObject(iterator)) { | 1775 if (iterator.hasOwnProperty('__initializedIntlObject')) { |
| 1771 throw new $TypeError('Trying to re-initialize v8BreakIterator object.'); | 1776 throw new $TypeError('Trying to re-initialize v8BreakIterator object.'); |
| 1772 } | 1777 } |
| 1773 | 1778 |
| 1774 if (options === undefined) { | 1779 if (options === undefined) { |
| 1775 options = {}; | 1780 options = {}; |
| 1776 } | 1781 } |
| 1777 | 1782 |
| 1778 var getOption = getGetOption(options, 'breakiterator'); | 1783 var getOption = getGetOption(options, 'breakiterator'); |
| 1779 | 1784 |
| 1780 var internalOptions = {}; | 1785 var internalOptions = {}; |
| 1781 | 1786 |
| 1782 defineWEProperty(internalOptions, 'type', getOption( | 1787 defineWEProperty(internalOptions, 'type', getOption( |
| 1783 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); | 1788 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); |
| 1784 | 1789 |
| 1785 var locale = resolveLocale('breakiterator', locales, options); | 1790 var locale = resolveLocale('breakiterator', locales, options); |
| 1786 var resolved = $Object.defineProperties({}, { | 1791 var resolved = $Object.defineProperties({}, { |
| 1787 requestedLocale: {value: locale.locale, writable: true}, | 1792 requestedLocale: {value: locale.locale, writable: true}, |
| 1788 type: {value: internalOptions.type, writable: true}, | 1793 type: {value: internalOptions.type, writable: true}, |
| 1789 locale: {writable: true} | 1794 locale: {writable: true} |
| 1790 }); | 1795 }); |
| 1791 | 1796 |
| 1792 var internalIterator = %CreateBreakIterator(locale.locale, | 1797 var internalIterator = %CreateBreakIterator(locale.locale, |
| 1793 internalOptions, | 1798 internalOptions, |
| 1794 resolved); | 1799 resolved); |
| 1795 | 1800 |
| 1796 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', | 1801 $Object.defineProperty(iterator, 'iterator', {value: internalIterator}); |
| 1797 internalIterator); | |
| 1798 $Object.defineProperty(iterator, 'resolved', {value: resolved}); | 1802 $Object.defineProperty(iterator, 'resolved', {value: resolved}); |
| 1803 $Object.defineProperty(iterator, '__initializedIntlObject', |
| 1804 {value: 'breakiterator'}); |
| 1799 | 1805 |
| 1800 return iterator; | 1806 return iterator; |
| 1801 } | 1807 } |
| 1802 | 1808 |
| 1803 | 1809 |
| 1804 /** | 1810 /** |
| 1805 * Constructs Intl.v8BreakIterator object given optional locales and options | 1811 * Constructs Intl.v8BreakIterator object given optional locales and options |
| 1806 * parameters. | 1812 * parameters. |
| 1807 * | 1813 * |
| 1808 * @constructor | 1814 * @constructor |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1823 | 1829 |
| 1824 | 1830 |
| 1825 /** | 1831 /** |
| 1826 * BreakIterator resolvedOptions method. | 1832 * BreakIterator resolvedOptions method. |
| 1827 */ | 1833 */ |
| 1828 %SetProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', function() { | 1834 %SetProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', function() { |
| 1829 if (%_IsConstructCall()) { | 1835 if (%_IsConstructCall()) { |
| 1830 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | 1836 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
| 1831 } | 1837 } |
| 1832 | 1838 |
| 1833 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { | 1839 if (!this || typeof this !== 'object' || |
| 1840 this.__initializedIntlObject !== 'breakiterator') { |
| 1834 throw new $TypeError('resolvedOptions method called on a non-object or ' + | 1841 throw new $TypeError('resolvedOptions method called on a non-object or ' + |
| 1835 'on a object that is not Intl.v8BreakIterator.'); | 1842 'on a object that is not Intl.v8BreakIterator.'); |
| 1836 } | 1843 } |
| 1837 | 1844 |
| 1838 var segmenter = this; | 1845 var segmenter = this; |
| 1839 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, | 1846 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, |
| 1840 segmenter.resolved.locale); | 1847 segmenter.resolved.locale); |
| 1841 | 1848 |
| 1842 return { | 1849 return { |
| 1843 locale: locale, | 1850 locale: locale, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1870 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); | 1877 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
| 1871 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); | 1878 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
| 1872 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); | 1879 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
| 1873 | 1880 |
| 1874 | 1881 |
| 1875 /** | 1882 /** |
| 1876 * Adopts text to segment using the iterator. Old text, if present, | 1883 * Adopts text to segment using the iterator. Old text, if present, |
| 1877 * gets discarded. | 1884 * gets discarded. |
| 1878 */ | 1885 */ |
| 1879 function adoptText(iterator, text) { | 1886 function adoptText(iterator, text) { |
| 1880 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), | 1887 %BreakIteratorAdoptText(iterator.iterator, $String(text)); |
| 1881 $String(text)); | |
| 1882 } | 1888 } |
| 1883 | 1889 |
| 1884 | 1890 |
| 1885 /** | 1891 /** |
| 1886 * 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. |
| 1887 */ | 1893 */ |
| 1888 function first(iterator) { | 1894 function first(iterator) { |
| 1889 return %BreakIteratorFirst(%GetImplFromInitializedIntlObject(iterator)); | 1895 return %BreakIteratorFirst(iterator.iterator); |
| 1890 } | 1896 } |
| 1891 | 1897 |
| 1892 | 1898 |
| 1893 /** | 1899 /** |
| 1894 * Returns the index of the next break and moves the pointer. | 1900 * Returns the index of the next break and moves the pointer. |
| 1895 */ | 1901 */ |
| 1896 function next(iterator) { | 1902 function next(iterator) { |
| 1897 return %BreakIteratorNext(%GetImplFromInitializedIntlObject(iterator)); | 1903 return %BreakIteratorNext(iterator.iterator); |
| 1898 } | 1904 } |
| 1899 | 1905 |
| 1900 | 1906 |
| 1901 /** | 1907 /** |
| 1902 * Returns index of the current break. | 1908 * Returns index of the current break. |
| 1903 */ | 1909 */ |
| 1904 function current(iterator) { | 1910 function current(iterator) { |
| 1905 return %BreakIteratorCurrent(%GetImplFromInitializedIntlObject(iterator)); | 1911 return %BreakIteratorCurrent(iterator.iterator); |
| 1906 } | 1912 } |
| 1907 | 1913 |
| 1908 | 1914 |
| 1909 /** | 1915 /** |
| 1910 * Returns type of the current break. | 1916 * Returns type of the current break. |
| 1911 */ | 1917 */ |
| 1912 function breakType(iterator) { | 1918 function breakType(iterator) { |
| 1913 return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator)); | 1919 return %BreakIteratorBreakType(iterator.iterator); |
| 1914 } | 1920 } |
| 1915 | 1921 |
| 1916 | 1922 |
| 1917 addBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); | 1923 addBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); |
| 1918 addBoundMethod(Intl.v8BreakIterator, 'first', first, 0); | 1924 addBoundMethod(Intl.v8BreakIterator, 'first', first, 0); |
| 1919 addBoundMethod(Intl.v8BreakIterator, 'next', next, 0); | 1925 addBoundMethod(Intl.v8BreakIterator, 'next', next, 0); |
| 1920 addBoundMethod(Intl.v8BreakIterator, 'current', current, 0); | 1926 addBoundMethod(Intl.v8BreakIterator, 'current', current, 0); |
| 1921 addBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); | 1927 addBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); |
| 1922 | 1928 |
| 1923 // Save references to Intl objects and methods we use, for added security. | 1929 // Save references to Intl objects and methods we use, for added security. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2137 writable: true, | 2143 writable: true, |
| 2138 configurable: true, | 2144 configurable: true, |
| 2139 enumerable: false | 2145 enumerable: false |
| 2140 }); | 2146 }); |
| 2141 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); | 2147 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); |
| 2142 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); | 2148 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); |
| 2143 %SetNativeFlag($Date.prototype.toLocaleTimeString); | 2149 %SetNativeFlag($Date.prototype.toLocaleTimeString); |
| 2144 | 2150 |
| 2145 return Intl; | 2151 return Intl; |
| 2146 }())}); | 2152 }())}); |
| OLD | NEW |