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 */ |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 */ | 280 */ |
281 function supportedLocalesOf(service, locales, options) { | 281 function supportedLocalesOf(service, locales, options) { |
282 if (IS_NULL(service.match(GetServiceRE()))) { | 282 if (IS_NULL(service.match(GetServiceRE()))) { |
283 throw MakeError(kWrongServiceType, service); | 283 throw MakeError(kWrongServiceType, service); |
284 } | 284 } |
285 | 285 |
286 // Provide defaults if matcher was not specified. | 286 // Provide defaults if matcher was not specified. |
287 if (options === undefined) { | 287 if (options === undefined) { |
288 options = {}; | 288 options = {}; |
289 } else { | 289 } else { |
290 options = $toObject(options); | 290 options = ToObject(options); |
291 } | 291 } |
292 | 292 |
293 var matcher = options.localeMatcher; | 293 var matcher = options.localeMatcher; |
294 if (matcher !== undefined) { | 294 if (matcher !== undefined) { |
295 matcher = GlobalString(matcher); | 295 matcher = GlobalString(matcher); |
296 if (matcher !== 'lookup' && matcher !== 'best fit') { | 296 if (matcher !== 'lookup' && matcher !== 'best fit') { |
297 throw MakeRangeError(kLocaleMatcher, matcher); | 297 throw MakeRangeError(kLocaleMatcher, matcher); |
298 } | 298 } |
299 } else { | 299 } else { |
300 matcher = 'best fit'; | 300 matcher = 'best fit'; |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 if (locales === undefined) { | 736 if (locales === undefined) { |
737 // Constructor is called without arguments. | 737 // Constructor is called without arguments. |
738 seen = []; | 738 seen = []; |
739 } else { | 739 } else { |
740 // We allow single string localeID. | 740 // We allow single string localeID. |
741 if (typeof locales === 'string') { | 741 if (typeof locales === 'string') { |
742 seen.push(canonicalizeLanguageTag(locales)); | 742 seen.push(canonicalizeLanguageTag(locales)); |
743 return freezeArray(seen); | 743 return freezeArray(seen); |
744 } | 744 } |
745 | 745 |
746 var o = $toObject(locales); | 746 var o = ToObject(locales); |
747 // Converts it to UInt32 (>>> is shr on 32bit integers). | 747 // Converts it to UInt32 (>>> is shr on 32bit integers). |
748 var len = o.length >>> 0; | 748 var len = o.length >>> 0; |
749 | 749 |
750 for (var k = 0; k < len; k++) { | 750 for (var k = 0; k < len; k++) { |
751 if (k in o) { | 751 if (k in o) { |
752 var value = o[k]; | 752 var value = o[k]; |
753 | 753 |
754 var tag = canonicalizeLanguageTag(value); | 754 var tag = canonicalizeLanguageTag(value); |
755 | 755 |
756 if (seen.indexOf(tag) === -1) { | 756 if (seen.indexOf(tag) === -1) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 */ | 948 */ |
949 %AddNamedProperty(Intl, 'Collator', function() { | 949 %AddNamedProperty(Intl, 'Collator', function() { |
950 var locales = %_Arguments(0); | 950 var locales = %_Arguments(0); |
951 var options = %_Arguments(1); | 951 var options = %_Arguments(1); |
952 | 952 |
953 if (!this || this === Intl) { | 953 if (!this || this === Intl) { |
954 // Constructor is called as a function. | 954 // Constructor is called as a function. |
955 return new Intl.Collator(locales, options); | 955 return new Intl.Collator(locales, options); |
956 } | 956 } |
957 | 957 |
958 return initializeCollator($toObject(this), locales, options); | 958 return initializeCollator(ToObject(this), locales, options); |
959 }, | 959 }, |
960 DONT_ENUM | 960 DONT_ENUM |
961 ); | 961 ); |
962 | 962 |
963 | 963 |
964 /** | 964 /** |
965 * Collator resolvedOptions method. | 965 * Collator resolvedOptions method. |
966 */ | 966 */ |
967 %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() { | 967 %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() { |
968 if (%_IsConstructCall()) { | 968 if (%_IsConstructCall()) { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 */ | 1174 */ |
1175 %AddNamedProperty(Intl, 'NumberFormat', function() { | 1175 %AddNamedProperty(Intl, 'NumberFormat', function() { |
1176 var locales = %_Arguments(0); | 1176 var locales = %_Arguments(0); |
1177 var options = %_Arguments(1); | 1177 var options = %_Arguments(1); |
1178 | 1178 |
1179 if (!this || this === Intl) { | 1179 if (!this || this === Intl) { |
1180 // Constructor is called as a function. | 1180 // Constructor is called as a function. |
1181 return new Intl.NumberFormat(locales, options); | 1181 return new Intl.NumberFormat(locales, options); |
1182 } | 1182 } |
1183 | 1183 |
1184 return initializeNumberFormat($toObject(this), locales, options); | 1184 return initializeNumberFormat(ToObject(this), locales, options); |
1185 }, | 1185 }, |
1186 DONT_ENUM | 1186 DONT_ENUM |
1187 ); | 1187 ); |
1188 | 1188 |
1189 | 1189 |
1190 /** | 1190 /** |
1191 * NumberFormat resolvedOptions method. | 1191 * NumberFormat resolvedOptions method. |
1192 */ | 1192 */ |
1193 %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { | 1193 %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
1194 if (%_IsConstructCall()) { | 1194 if (%_IsConstructCall()) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); | 1259 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
1260 | 1260 |
1261 | 1261 |
1262 /** | 1262 /** |
1263 * Returns a String value representing the result of calling ToNumber(value) | 1263 * Returns a String value representing the result of calling ToNumber(value) |
1264 * according to the effective locale and the formatting options of this | 1264 * according to the effective locale and the formatting options of this |
1265 * NumberFormat. | 1265 * NumberFormat. |
1266 */ | 1266 */ |
1267 function formatNumber(formatter, value) { | 1267 function formatNumber(formatter, value) { |
1268 // Spec treats -0 and +0 as 0. | 1268 // Spec treats -0 and +0 as 0. |
1269 var number = $toNumber(value) + 0; | 1269 var number = GlobalNumber(value) + 0; |
1270 | 1270 |
1271 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), | 1271 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), |
1272 number); | 1272 number); |
1273 } | 1273 } |
1274 | 1274 |
1275 | 1275 |
1276 /** | 1276 /** |
1277 * Returns a Number that represents string value that was passed in. | 1277 * Returns a Number that represents string value that was passed in. |
1278 */ | 1278 */ |
1279 function parseNumber(formatter, value) { | 1279 function parseNumber(formatter, value) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 */ | 1566 */ |
1567 %AddNamedProperty(Intl, 'DateTimeFormat', function() { | 1567 %AddNamedProperty(Intl, 'DateTimeFormat', function() { |
1568 var locales = %_Arguments(0); | 1568 var locales = %_Arguments(0); |
1569 var options = %_Arguments(1); | 1569 var options = %_Arguments(1); |
1570 | 1570 |
1571 if (!this || this === Intl) { | 1571 if (!this || this === Intl) { |
1572 // Constructor is called as a function. | 1572 // Constructor is called as a function. |
1573 return new Intl.DateTimeFormat(locales, options); | 1573 return new Intl.DateTimeFormat(locales, options); |
1574 } | 1574 } |
1575 | 1575 |
1576 return initializeDateTimeFormat($toObject(this), locales, options); | 1576 return initializeDateTimeFormat(ToObject(this), locales, options); |
1577 }, | 1577 }, |
1578 DONT_ENUM | 1578 DONT_ENUM |
1579 ); | 1579 ); |
1580 | 1580 |
1581 | 1581 |
1582 /** | 1582 /** |
1583 * DateTimeFormat resolvedOptions method. | 1583 * DateTimeFormat resolvedOptions method. |
1584 */ | 1584 */ |
1585 %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { | 1585 %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
1586 if (%_IsConstructCall()) { | 1586 if (%_IsConstructCall()) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 /** | 1654 /** |
1655 * Returns a String value representing the result of calling ToNumber(date) | 1655 * Returns a String value representing the result of calling ToNumber(date) |
1656 * according to the effective locale and the formatting options of this | 1656 * according to the effective locale and the formatting options of this |
1657 * DateTimeFormat. | 1657 * DateTimeFormat. |
1658 */ | 1658 */ |
1659 function formatDate(formatter, dateValue) { | 1659 function formatDate(formatter, dateValue) { |
1660 var dateMs; | 1660 var dateMs; |
1661 if (dateValue === undefined) { | 1661 if (dateValue === undefined) { |
1662 dateMs = GlobalDate.now(); | 1662 dateMs = GlobalDate.now(); |
1663 } else { | 1663 } else { |
1664 dateMs = $toNumber(dateValue); | 1664 dateMs = GlobalNumber(dateValue); |
1665 } | 1665 } |
1666 | 1666 |
1667 if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange); | 1667 if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange); |
1668 | 1668 |
1669 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), | 1669 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), |
1670 new GlobalDate(dateMs)); | 1670 new GlobalDate(dateMs)); |
1671 } | 1671 } |
1672 | 1672 |
1673 | 1673 |
1674 /** | 1674 /** |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1767 */ | 1767 */ |
1768 %AddNamedProperty(Intl, 'v8BreakIterator', function() { | 1768 %AddNamedProperty(Intl, 'v8BreakIterator', function() { |
1769 var locales = %_Arguments(0); | 1769 var locales = %_Arguments(0); |
1770 var options = %_Arguments(1); | 1770 var options = %_Arguments(1); |
1771 | 1771 |
1772 if (!this || this === Intl) { | 1772 if (!this || this === Intl) { |
1773 // Constructor is called as a function. | 1773 // Constructor is called as a function. |
1774 return new Intl.v8BreakIterator(locales, options); | 1774 return new Intl.v8BreakIterator(locales, options); |
1775 } | 1775 } |
1776 | 1776 |
1777 return initializeBreakIterator($toObject(this), locales, options); | 1777 return initializeBreakIterator(ToObject(this), locales, options); |
1778 }, | 1778 }, |
1779 DONT_ENUM | 1779 DONT_ENUM |
1780 ); | 1780 ); |
1781 | 1781 |
1782 | 1782 |
1783 /** | 1783 /** |
1784 * BreakIterator resolvedOptions method. | 1784 * BreakIterator resolvedOptions method. |
1785 */ | 1785 */ |
1786 %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', | 1786 %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', |
1787 function() { | 1787 function() { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2052 } | 2052 } |
2053 | 2053 |
2054 var locales = %_Arguments(0); | 2054 var locales = %_Arguments(0); |
2055 var options = %_Arguments(1); | 2055 var options = %_Arguments(1); |
2056 return toLocaleDateTime( | 2056 return toLocaleDateTime( |
2057 this, locales, options, 'time', 'time', 'dateformattime'); | 2057 this, locales, options, 'time', 'time', 'dateformattime'); |
2058 } | 2058 } |
2059 ); | 2059 ); |
2060 | 2060 |
2061 })(); | 2061 })(); |
OLD | NEW |