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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 */ | 244 */ |
245 function supportedLocalesOf(service, locales, options) { | 245 function supportedLocalesOf(service, locales, options) { |
246 if (IS_NULL(%_CallFunction(service, GetServiceRE(), StringMatch))) { | 246 if (IS_NULL(%_CallFunction(service, GetServiceRE(), StringMatch))) { |
247 throw MakeError(kWrongServiceType, service); | 247 throw MakeError(kWrongServiceType, service); |
248 } | 248 } |
249 | 249 |
250 // Provide defaults if matcher was not specified. | 250 // Provide defaults if matcher was not specified. |
251 if (IS_UNDEFINED(options)) { | 251 if (IS_UNDEFINED(options)) { |
252 options = {}; | 252 options = {}; |
253 } else { | 253 } else { |
254 options = $toObject(options); | 254 options = TO_OBJECT(options); |
255 } | 255 } |
256 | 256 |
257 var matcher = options.localeMatcher; | 257 var matcher = options.localeMatcher; |
258 if (!IS_UNDEFINED(matcher)) { | 258 if (!IS_UNDEFINED(matcher)) { |
259 matcher = GlobalString(matcher); | 259 matcher = GlobalString(matcher); |
260 if (matcher !== 'lookup' && matcher !== 'best fit') { | 260 if (matcher !== 'lookup' && matcher !== 'best fit') { |
261 throw MakeRangeError(kLocaleMatcher, matcher); | 261 throw MakeRangeError(kLocaleMatcher, matcher); |
262 } | 262 } |
263 } else { | 263 } else { |
264 matcher = 'best fit'; | 264 matcher = 'best fit'; |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 if (IS_UNDEFINED(locales)) { | 710 if (IS_UNDEFINED(locales)) { |
711 // Constructor is called without arguments. | 711 // Constructor is called without arguments. |
712 seen = []; | 712 seen = []; |
713 } else { | 713 } else { |
714 // We allow single string localeID. | 714 // We allow single string localeID. |
715 if (typeof locales === 'string') { | 715 if (typeof locales === 'string') { |
716 %_CallFunction(seen, canonicalizeLanguageTag(locales), $arrayPush); | 716 %_CallFunction(seen, canonicalizeLanguageTag(locales), $arrayPush); |
717 return freezeArray(seen); | 717 return freezeArray(seen); |
718 } | 718 } |
719 | 719 |
720 var o = $toObject(locales); | 720 var o = TO_OBJECT(locales); |
721 var len = TO_UINT32(o.length); | 721 var len = TO_UINT32(o.length); |
722 | 722 |
723 for (var k = 0; k < len; k++) { | 723 for (var k = 0; k < len; k++) { |
724 if (k in o) { | 724 if (k in o) { |
725 var value = o[k]; | 725 var value = o[k]; |
726 | 726 |
727 var tag = canonicalizeLanguageTag(value); | 727 var tag = canonicalizeLanguageTag(value); |
728 | 728 |
729 if (%_CallFunction(seen, tag, ArrayIndexOf) === -1) { | 729 if (%_CallFunction(seen, tag, ArrayIndexOf) === -1) { |
730 %_CallFunction(seen, tag, $arrayPush); | 730 %_CallFunction(seen, tag, $arrayPush); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 */ | 944 */ |
945 %AddNamedProperty(Intl, 'Collator', function() { | 945 %AddNamedProperty(Intl, 'Collator', function() { |
946 var locales = %_Arguments(0); | 946 var locales = %_Arguments(0); |
947 var options = %_Arguments(1); | 947 var options = %_Arguments(1); |
948 | 948 |
949 if (!this || this === Intl) { | 949 if (!this || this === Intl) { |
950 // Constructor is called as a function. | 950 // Constructor is called as a function. |
951 return new Intl.Collator(locales, options); | 951 return new Intl.Collator(locales, options); |
952 } | 952 } |
953 | 953 |
954 return initializeCollator($toObject(this), locales, options); | 954 return initializeCollator(TO_OBJECT(this), locales, options); |
955 }, | 955 }, |
956 DONT_ENUM | 956 DONT_ENUM |
957 ); | 957 ); |
958 | 958 |
959 | 959 |
960 /** | 960 /** |
961 * Collator resolvedOptions method. | 961 * Collator resolvedOptions method. |
962 */ | 962 */ |
963 %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() { | 963 %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() { |
964 if (%_IsConstructCall()) { | 964 if (%_IsConstructCall()) { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 */ | 1185 */ |
1186 %AddNamedProperty(Intl, 'NumberFormat', function() { | 1186 %AddNamedProperty(Intl, 'NumberFormat', function() { |
1187 var locales = %_Arguments(0); | 1187 var locales = %_Arguments(0); |
1188 var options = %_Arguments(1); | 1188 var options = %_Arguments(1); |
1189 | 1189 |
1190 if (!this || this === Intl) { | 1190 if (!this || this === Intl) { |
1191 // Constructor is called as a function. | 1191 // Constructor is called as a function. |
1192 return new Intl.NumberFormat(locales, options); | 1192 return new Intl.NumberFormat(locales, options); |
1193 } | 1193 } |
1194 | 1194 |
1195 return initializeNumberFormat($toObject(this), locales, options); | 1195 return initializeNumberFormat(TO_OBJECT(this), locales, options); |
1196 }, | 1196 }, |
1197 DONT_ENUM | 1197 DONT_ENUM |
1198 ); | 1198 ); |
1199 | 1199 |
1200 | 1200 |
1201 /** | 1201 /** |
1202 * NumberFormat resolvedOptions method. | 1202 * NumberFormat resolvedOptions method. |
1203 */ | 1203 */ |
1204 %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { | 1204 %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
1205 if (%_IsConstructCall()) { | 1205 if (%_IsConstructCall()) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 } | 1437 } |
1438 | 1438 |
1439 | 1439 |
1440 /** | 1440 /** |
1441 * Returns options with at least default values in it. | 1441 * Returns options with at least default values in it. |
1442 */ | 1442 */ |
1443 function toDateTimeOptions(options, required, defaults) { | 1443 function toDateTimeOptions(options, required, defaults) { |
1444 if (IS_UNDEFINED(options)) { | 1444 if (IS_UNDEFINED(options)) { |
1445 options = {}; | 1445 options = {}; |
1446 } else { | 1446 } else { |
1447 options = TO_OBJECT_INLINE(options); | 1447 options = TO_OBJECT(options); |
1448 } | 1448 } |
1449 | 1449 |
1450 var needsDefault = true; | 1450 var needsDefault = true; |
1451 if ((required === 'date' || required === 'any') && | 1451 if ((required === 'date' || required === 'any') && |
1452 (!IS_UNDEFINED(options.weekday) || !IS_UNDEFINED(options.year) || | 1452 (!IS_UNDEFINED(options.weekday) || !IS_UNDEFINED(options.year) || |
1453 !IS_UNDEFINED(options.month) || !IS_UNDEFINED(options.day))) { | 1453 !IS_UNDEFINED(options.month) || !IS_UNDEFINED(options.day))) { |
1454 needsDefault = false; | 1454 needsDefault = false; |
1455 } | 1455 } |
1456 | 1456 |
1457 if ((required === 'time' || required === 'any') && | 1457 if ((required === 'time' || required === 'any') && |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 */ | 1587 */ |
1588 %AddNamedProperty(Intl, 'DateTimeFormat', function() { | 1588 %AddNamedProperty(Intl, 'DateTimeFormat', function() { |
1589 var locales = %_Arguments(0); | 1589 var locales = %_Arguments(0); |
1590 var options = %_Arguments(1); | 1590 var options = %_Arguments(1); |
1591 | 1591 |
1592 if (!this || this === Intl) { | 1592 if (!this || this === Intl) { |
1593 // Constructor is called as a function. | 1593 // Constructor is called as a function. |
1594 return new Intl.DateTimeFormat(locales, options); | 1594 return new Intl.DateTimeFormat(locales, options); |
1595 } | 1595 } |
1596 | 1596 |
1597 return initializeDateTimeFormat($toObject(this), locales, options); | 1597 return initializeDateTimeFormat(TO_OBJECT(this), locales, options); |
1598 }, | 1598 }, |
1599 DONT_ENUM | 1599 DONT_ENUM |
1600 ); | 1600 ); |
1601 | 1601 |
1602 | 1602 |
1603 /** | 1603 /** |
1604 * DateTimeFormat resolvedOptions method. | 1604 * DateTimeFormat resolvedOptions method. |
1605 */ | 1605 */ |
1606 %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { | 1606 %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
1607 if (%_IsConstructCall()) { | 1607 if (%_IsConstructCall()) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 */ | 1807 */ |
1808 %AddNamedProperty(Intl, 'v8BreakIterator', function() { | 1808 %AddNamedProperty(Intl, 'v8BreakIterator', function() { |
1809 var locales = %_Arguments(0); | 1809 var locales = %_Arguments(0); |
1810 var options = %_Arguments(1); | 1810 var options = %_Arguments(1); |
1811 | 1811 |
1812 if (!this || this === Intl) { | 1812 if (!this || this === Intl) { |
1813 // Constructor is called as a function. | 1813 // Constructor is called as a function. |
1814 return new Intl.v8BreakIterator(locales, options); | 1814 return new Intl.v8BreakIterator(locales, options); |
1815 } | 1815 } |
1816 | 1816 |
1817 return initializeBreakIterator($toObject(this), locales, options); | 1817 return initializeBreakIterator(TO_OBJECT(this), locales, options); |
1818 }, | 1818 }, |
1819 DONT_ENUM | 1819 DONT_ENUM |
1820 ); | 1820 ); |
1821 | 1821 |
1822 | 1822 |
1823 /** | 1823 /** |
1824 * BreakIterator resolvedOptions method. | 1824 * BreakIterator resolvedOptions method. |
1825 */ | 1825 */ |
1826 %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', | 1826 %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', |
1827 function() { | 1827 function() { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 } | 2105 } |
2106 | 2106 |
2107 var locales = %_Arguments(0); | 2107 var locales = %_Arguments(0); |
2108 var options = %_Arguments(1); | 2108 var options = %_Arguments(1); |
2109 return toLocaleDateTime( | 2109 return toLocaleDateTime( |
2110 this, locales, options, 'time', 'time', 'dateformattime'); | 2110 this, locales, options, 'time', 'time', 'dateformattime'); |
2111 } | 2111 } |
2112 ); | 2112 ); |
2113 | 2113 |
2114 }) | 2114 }) |
OLD | NEW |