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