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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 */ | 295 */ |
296 function supportedLocalesOf(service, locales, options) { | 296 function supportedLocalesOf(service, locales, options) { |
297 if (IS_NULL(service.match(GetServiceRE()))) { | 297 if (IS_NULL(service.match(GetServiceRE()))) { |
298 throw new $Error('Internal error, wrong service type: ' + service); | 298 throw new $Error('Internal error, wrong service type: ' + service); |
299 } | 299 } |
300 | 300 |
301 // Provide defaults if matcher was not specified. | 301 // Provide defaults if matcher was not specified. |
302 if (options === undefined) { | 302 if (options === undefined) { |
303 options = {}; | 303 options = {}; |
304 } else { | 304 } else { |
305 options = toObject(options); | 305 options = ToObject(options); |
306 } | 306 } |
307 | 307 |
308 var matcher = options.localeMatcher; | 308 var matcher = options.localeMatcher; |
309 if (matcher !== undefined) { | 309 if (matcher !== undefined) { |
310 matcher = $String(matcher); | 310 matcher = $String(matcher); |
311 if (matcher !== 'lookup' && matcher !== 'best fit') { | 311 if (matcher !== 'lookup' && matcher !== 'best fit') { |
312 throw new $RangeError('Illegal value for localeMatcher:' + matcher); | 312 throw new $RangeError('Illegal value for localeMatcher:' + matcher); |
313 } | 313 } |
314 } else { | 314 } else { |
315 matcher = 'best fit'; | 315 matcher = 'best fit'; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 // There is a value that's too long, or that doesn't have a key. | 529 // There is a value that's too long, or that doesn't have a key. |
530 return {}; | 530 return {}; |
531 } | 531 } |
532 } | 532 } |
533 | 533 |
534 return extensionMap; | 534 return extensionMap; |
535 } | 535 } |
536 | 536 |
537 | 537 |
538 /** | 538 /** |
539 * Converts parameter to an Object if possible. | |
540 */ | |
541 function toObject(value) { | |
542 if (IS_NULL_OR_UNDEFINED(value)) { | |
543 throw new $TypeError('Value cannot be converted to an Object.'); | |
544 } | |
545 | |
546 return $Object(value); | |
547 } | |
548 | |
549 | |
550 /** | |
551 * Populates internalOptions object with boolean key-value pairs | 539 * Populates internalOptions object with boolean key-value pairs |
552 * from extensionMap and options. | 540 * from extensionMap and options. |
553 * Returns filtered extension (number and date format constructors use | 541 * Returns filtered extension (number and date format constructors use |
554 * Unicode extensions for passing parameters to ICU). | 542 * Unicode extensions for passing parameters to ICU). |
555 * It's used for extension-option pairs only, e.g. kn-normalization, but not | 543 * It's used for extension-option pairs only, e.g. kn-normalization, but not |
556 * for 'sensitivity' since it doesn't have extension equivalent. | 544 * for 'sensitivity' since it doesn't have extension equivalent. |
557 * Extensions like nu and ca don't have options equivalent, so we place | 545 * Extensions like nu and ca don't have options equivalent, so we place |
558 * undefined in the map.property to denote that. | 546 * undefined in the map.property to denote that. |
559 */ | 547 */ |
560 function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) { | 548 function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 if (locales === undefined) { | 757 if (locales === undefined) { |
770 // Constructor is called without arguments. | 758 // Constructor is called without arguments. |
771 seen = []; | 759 seen = []; |
772 } else { | 760 } else { |
773 // We allow single string localeID. | 761 // We allow single string localeID. |
774 if (typeof locales === 'string') { | 762 if (typeof locales === 'string') { |
775 seen.push(canonicalizeLanguageTag(locales)); | 763 seen.push(canonicalizeLanguageTag(locales)); |
776 return freezeArray(seen); | 764 return freezeArray(seen); |
777 } | 765 } |
778 | 766 |
779 var o = toObject(locales); | 767 var o = ToObject(locales); |
780 // Converts it to UInt32 (>>> is shr on 32bit integers). | 768 // Converts it to UInt32 (>>> is shr on 32bit integers). |
781 var len = o.length >>> 0; | 769 var len = o.length >>> 0; |
782 | 770 |
783 for (var k = 0; k < len; k++) { | 771 for (var k = 0; k < len; k++) { |
784 if (k in o) { | 772 if (k in o) { |
785 var value = o[k]; | 773 var value = o[k]; |
786 | 774 |
787 var tag = canonicalizeLanguageTag(value); | 775 var tag = canonicalizeLanguageTag(value); |
788 | 776 |
789 if (seen.indexOf(tag) === -1) { | 777 if (seen.indexOf(tag) === -1) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 */ | 969 */ |
982 %SetProperty(Intl, 'Collator', function() { | 970 %SetProperty(Intl, 'Collator', function() { |
983 var locales = %_Arguments(0); | 971 var locales = %_Arguments(0); |
984 var options = %_Arguments(1); | 972 var options = %_Arguments(1); |
985 | 973 |
986 if (!this || this === Intl) { | 974 if (!this || this === Intl) { |
987 // Constructor is called as a function. | 975 // Constructor is called as a function. |
988 return new Intl.Collator(locales, options); | 976 return new Intl.Collator(locales, options); |
989 } | 977 } |
990 | 978 |
991 return initializeCollator(toObject(this), locales, options); | 979 return initializeCollator(ToObject(this), locales, options); |
992 }, | 980 }, |
993 DONT_ENUM | 981 DONT_ENUM |
994 ); | 982 ); |
995 | 983 |
996 | 984 |
997 /** | 985 /** |
998 * Collator resolvedOptions method. | 986 * Collator resolvedOptions method. |
999 */ | 987 */ |
1000 %SetProperty(Intl.Collator.prototype, 'resolvedOptions', function() { | 988 %SetProperty(Intl.Collator.prototype, 'resolvedOptions', function() { |
1001 if (%_IsConstructCall()) { | 989 if (%_IsConstructCall()) { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 */ | 1196 */ |
1209 %SetProperty(Intl, 'NumberFormat', function() { | 1197 %SetProperty(Intl, 'NumberFormat', function() { |
1210 var locales = %_Arguments(0); | 1198 var locales = %_Arguments(0); |
1211 var options = %_Arguments(1); | 1199 var options = %_Arguments(1); |
1212 | 1200 |
1213 if (!this || this === Intl) { | 1201 if (!this || this === Intl) { |
1214 // Constructor is called as a function. | 1202 // Constructor is called as a function. |
1215 return new Intl.NumberFormat(locales, options); | 1203 return new Intl.NumberFormat(locales, options); |
1216 } | 1204 } |
1217 | 1205 |
1218 return initializeNumberFormat(toObject(this), locales, options); | 1206 return initializeNumberFormat(ToObject(this), locales, options); |
1219 }, | 1207 }, |
1220 DONT_ENUM | 1208 DONT_ENUM |
1221 ); | 1209 ); |
1222 | 1210 |
1223 | 1211 |
1224 /** | 1212 /** |
1225 * NumberFormat resolvedOptions method. | 1213 * NumberFormat resolvedOptions method. |
1226 */ | 1214 */ |
1227 %SetProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { | 1215 %SetProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
1228 if (%_IsConstructCall()) { | 1216 if (%_IsConstructCall()) { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 } | 1449 } |
1462 | 1450 |
1463 | 1451 |
1464 /** | 1452 /** |
1465 * Returns options with at least default values in it. | 1453 * Returns options with at least default values in it. |
1466 */ | 1454 */ |
1467 function toDateTimeOptions(options, required, defaults) { | 1455 function toDateTimeOptions(options, required, defaults) { |
1468 if (options === undefined) { | 1456 if (options === undefined) { |
1469 options = null; | 1457 options = null; |
1470 } else { | 1458 } else { |
1471 options = toObject(options); | 1459 options = ToObject(options); |
1472 } | 1460 } |
1473 | 1461 |
1474 options = $Object.apply(this, [options]); | 1462 options = $Object.apply(this, [options]); |
1475 | 1463 |
1476 var needsDefault = true; | 1464 var needsDefault = true; |
1477 if ((required === 'date' || required === 'any') && | 1465 if ((required === 'date' || required === 'any') && |
1478 (options.weekday !== undefined || options.year !== undefined || | 1466 (options.weekday !== undefined || options.year !== undefined || |
1479 options.month !== undefined || options.day !== undefined)) { | 1467 options.month !== undefined || options.day !== undefined)) { |
1480 needsDefault = false; | 1468 needsDefault = false; |
1481 } | 1469 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 */ | 1591 */ |
1604 %SetProperty(Intl, 'DateTimeFormat', function() { | 1592 %SetProperty(Intl, 'DateTimeFormat', function() { |
1605 var locales = %_Arguments(0); | 1593 var locales = %_Arguments(0); |
1606 var options = %_Arguments(1); | 1594 var options = %_Arguments(1); |
1607 | 1595 |
1608 if (!this || this === Intl) { | 1596 if (!this || this === Intl) { |
1609 // Constructor is called as a function. | 1597 // Constructor is called as a function. |
1610 return new Intl.DateTimeFormat(locales, options); | 1598 return new Intl.DateTimeFormat(locales, options); |
1611 } | 1599 } |
1612 | 1600 |
1613 return initializeDateTimeFormat(toObject(this), locales, options); | 1601 return initializeDateTimeFormat(ToObject(this), locales, options); |
1614 }, | 1602 }, |
1615 DONT_ENUM | 1603 DONT_ENUM |
1616 ); | 1604 ); |
1617 | 1605 |
1618 | 1606 |
1619 /** | 1607 /** |
1620 * DateTimeFormat resolvedOptions method. | 1608 * DateTimeFormat resolvedOptions method. |
1621 */ | 1609 */ |
1622 %SetProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { | 1610 %SetProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
1623 if (%_IsConstructCall()) { | 1611 if (%_IsConstructCall()) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 */ | 1797 */ |
1810 %SetProperty(Intl, 'v8BreakIterator', function() { | 1798 %SetProperty(Intl, 'v8BreakIterator', function() { |
1811 var locales = %_Arguments(0); | 1799 var locales = %_Arguments(0); |
1812 var options = %_Arguments(1); | 1800 var options = %_Arguments(1); |
1813 | 1801 |
1814 if (!this || this === Intl) { | 1802 if (!this || this === Intl) { |
1815 // Constructor is called as a function. | 1803 // Constructor is called as a function. |
1816 return new Intl.v8BreakIterator(locales, options); | 1804 return new Intl.v8BreakIterator(locales, options); |
1817 } | 1805 } |
1818 | 1806 |
1819 return initializeBreakIterator(toObject(this), locales, options); | 1807 return initializeBreakIterator(ToObject(this), locales, options); |
1820 }, | 1808 }, |
1821 DONT_ENUM | 1809 DONT_ENUM |
1822 ); | 1810 ); |
1823 | 1811 |
1824 | 1812 |
1825 /** | 1813 /** |
1826 * BreakIterator resolvedOptions method. | 1814 * BreakIterator resolvedOptions method. |
1827 */ | 1815 */ |
1828 %SetProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', function() { | 1816 %SetProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', function() { |
1829 if (%_IsConstructCall()) { | 1817 if (%_IsConstructCall()) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2137 writable: true, | 2125 writable: true, |
2138 configurable: true, | 2126 configurable: true, |
2139 enumerable: false | 2127 enumerable: false |
2140 }); | 2128 }); |
2141 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); | 2129 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); |
2142 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); | 2130 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); |
2143 %SetNativeFlag($Date.prototype.toLocaleTimeString); | 2131 %SetNativeFlag($Date.prototype.toLocaleTimeString); |
2144 | 2132 |
2145 return Intl; | 2133 return Intl; |
2146 }())}); | 2134 }())}); |
OLD | NEW |