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 */ |
11 (function(global, utils) { | 11 (function(global, utils) { |
12 | 12 |
13 "use strict"; | 13 "use strict"; |
14 | 14 |
15 %CheckIsBootstrapping(); | 15 %CheckIsBootstrapping(); |
16 | 16 |
17 // ------------------------------------------------------------------- | 17 // ------------------------------------------------------------------- |
18 // Imports | 18 // Imports |
19 | 19 |
20 var ArrayIndexOf; | 20 var ArrayIndexOf; |
21 var ArrayJoin; | 21 var ArrayJoin; |
| 22 var ArrayPush; |
22 var IsFinite; | 23 var IsFinite; |
23 var IsNaN; | 24 var IsNaN; |
24 var GlobalBoolean = global.Boolean; | 25 var GlobalBoolean = global.Boolean; |
25 var GlobalDate = global.Date; | 26 var GlobalDate = global.Date; |
26 var GlobalNumber = global.Number; | 27 var GlobalNumber = global.Number; |
27 var GlobalRegExp = global.RegExp; | 28 var GlobalRegExp = global.RegExp; |
28 var GlobalString = global.String; | 29 var GlobalString = global.String; |
29 var MathFloor; | 30 var MathFloor; |
30 var RegExpTest; | 31 var RegExpTest; |
31 var StringIndexOf; | 32 var StringIndexOf; |
32 var StringLastIndexOf; | 33 var StringLastIndexOf; |
33 var StringMatch; | 34 var StringMatch; |
34 var StringReplace; | 35 var StringReplace; |
35 var StringSplit; | 36 var StringSplit; |
36 var StringSubstr; | 37 var StringSubstr; |
37 var StringSubstring; | 38 var StringSubstring; |
38 | 39 |
39 utils.Import(function(from) { | 40 utils.Import(function(from) { |
40 ArrayIndexOf = from.ArrayIndexOf; | 41 ArrayIndexOf = from.ArrayIndexOf; |
41 ArrayJoin = from.ArrayJoin; | 42 ArrayJoin = from.ArrayJoin; |
| 43 ArrayPush = from.ArrayPush; |
42 IsFinite = from.IsFinite; | 44 IsFinite = from.IsFinite; |
43 IsNaN = from.IsNaN; | 45 IsNaN = from.IsNaN; |
44 MathFloor = from.MathFloor; | 46 MathFloor = from.MathFloor; |
45 RegExpTest = from.RegExpTest; | 47 RegExpTest = from.RegExpTest; |
46 StringIndexOf = from.StringIndexOf; | 48 StringIndexOf = from.StringIndexOf; |
47 StringLastIndexOf = from.StringLastIndexOf; | 49 StringLastIndexOf = from.StringLastIndexOf; |
48 StringMatch = from.StringMatch; | 50 StringMatch = from.StringMatch; |
49 StringReplace = from.StringReplace; | 51 StringReplace = from.StringReplace; |
50 StringSplit = from.StringSplit; | 52 StringSplit = from.StringSplit; |
51 StringSubstr = from.StringSubstr; | 53 StringSubstr = from.StringSubstr; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 */ | 293 */ |
292 function lookupSupportedLocalesOf(requestedLocales, availableLocales) { | 294 function lookupSupportedLocalesOf(requestedLocales, availableLocales) { |
293 var matchedLocales = []; | 295 var matchedLocales = []; |
294 for (var i = 0; i < requestedLocales.length; ++i) { | 296 for (var i = 0; i < requestedLocales.length; ++i) { |
295 // Remove -u- extension. | 297 // Remove -u- extension. |
296 var locale = %_CallFunction(requestedLocales[i], GetUnicodeExtensionRE(), | 298 var locale = %_CallFunction(requestedLocales[i], GetUnicodeExtensionRE(), |
297 '', StringReplace); | 299 '', StringReplace); |
298 do { | 300 do { |
299 if (!IS_UNDEFINED(availableLocales[locale])) { | 301 if (!IS_UNDEFINED(availableLocales[locale])) { |
300 // Push requested locale not the resolved one. | 302 // Push requested locale not the resolved one. |
301 %_CallFunction(matchedLocales, requestedLocales[i], $arrayPush); | 303 %_CallFunction(matchedLocales, requestedLocales[i], ArrayPush); |
302 break; | 304 break; |
303 } | 305 } |
304 // Truncate locale if possible, if not break. | 306 // Truncate locale if possible, if not break. |
305 var pos = %_CallFunction(locale, '-', StringLastIndexOf); | 307 var pos = %_CallFunction(locale, '-', StringLastIndexOf); |
306 if (pos === -1) { | 308 if (pos === -1) { |
307 break; | 309 break; |
308 } | 310 } |
309 locale = %_CallFunction(locale, 0, pos, StringSubstring); | 311 locale = %_CallFunction(locale, 0, pos, StringSubstring); |
310 } while (true); | 312 } while (true); |
311 } | 313 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 * Throws on locales that are not well formed BCP47 tags. | 710 * Throws on locales that are not well formed BCP47 tags. |
709 */ | 711 */ |
710 function initializeLocaleList(locales) { | 712 function initializeLocaleList(locales) { |
711 var seen = []; | 713 var seen = []; |
712 if (IS_UNDEFINED(locales)) { | 714 if (IS_UNDEFINED(locales)) { |
713 // Constructor is called without arguments. | 715 // Constructor is called without arguments. |
714 seen = []; | 716 seen = []; |
715 } else { | 717 } else { |
716 // We allow single string localeID. | 718 // We allow single string localeID. |
717 if (typeof locales === 'string') { | 719 if (typeof locales === 'string') { |
718 %_CallFunction(seen, canonicalizeLanguageTag(locales), $arrayPush); | 720 %_CallFunction(seen, canonicalizeLanguageTag(locales), ArrayPush); |
719 return freezeArray(seen); | 721 return freezeArray(seen); |
720 } | 722 } |
721 | 723 |
722 var o = TO_OBJECT(locales); | 724 var o = TO_OBJECT(locales); |
723 var len = TO_UINT32(o.length); | 725 var len = TO_UINT32(o.length); |
724 | 726 |
725 for (var k = 0; k < len; k++) { | 727 for (var k = 0; k < len; k++) { |
726 if (k in o) { | 728 if (k in o) { |
727 var value = o[k]; | 729 var value = o[k]; |
728 | 730 |
729 var tag = canonicalizeLanguageTag(value); | 731 var tag = canonicalizeLanguageTag(value); |
730 | 732 |
731 if (%_CallFunction(seen, tag, ArrayIndexOf) === -1) { | 733 if (%_CallFunction(seen, tag, ArrayIndexOf) === -1) { |
732 %_CallFunction(seen, tag, $arrayPush); | 734 %_CallFunction(seen, tag, ArrayPush); |
733 } | 735 } |
734 } | 736 } |
735 } | 737 } |
736 } | 738 } |
737 | 739 |
738 return freezeArray(seen); | 740 return freezeArray(seen); |
739 } | 741 } |
740 | 742 |
741 | 743 |
742 /** | 744 /** |
(...skipping 25 matching lines...) Expand all Loading... |
768 // We are matching i-klingon here, but that's ok, since i-klingon-klingon | 770 // We are matching i-klingon here, but that's ok, since i-klingon-klingon |
769 // is not valid and would fail LANGUAGE_TAG_RE test. | 771 // is not valid and would fail LANGUAGE_TAG_RE test. |
770 var variants = []; | 772 var variants = []; |
771 var extensions = []; | 773 var extensions = []; |
772 var parts = %_CallFunction(locale, /-/, StringSplit); | 774 var parts = %_CallFunction(locale, /-/, StringSplit); |
773 for (var i = 1; i < parts.length; i++) { | 775 for (var i = 1; i < parts.length; i++) { |
774 var value = parts[i]; | 776 var value = parts[i]; |
775 if (%_CallFunction(GetLanguageVariantRE(), value, RegExpTest) && | 777 if (%_CallFunction(GetLanguageVariantRE(), value, RegExpTest) && |
776 extensions.length === 0) { | 778 extensions.length === 0) { |
777 if (%_CallFunction(variants, value, ArrayIndexOf) === -1) { | 779 if (%_CallFunction(variants, value, ArrayIndexOf) === -1) { |
778 %_CallFunction(variants, value, $arrayPush); | 780 %_CallFunction(variants, value, ArrayPush); |
779 } else { | 781 } else { |
780 return false; | 782 return false; |
781 } | 783 } |
782 } | 784 } |
783 | 785 |
784 if (%_CallFunction(GetLanguageSingletonRE(), value, RegExpTest)) { | 786 if (%_CallFunction(GetLanguageSingletonRE(), value, RegExpTest)) { |
785 if (%_CallFunction(extensions, value, ArrayIndexOf) === -1) { | 787 if (%_CallFunction(extensions, value, ArrayIndexOf) === -1) { |
786 %_CallFunction(extensions, value, $arrayPush); | 788 %_CallFunction(extensions, value, ArrayPush); |
787 } else { | 789 } else { |
788 return false; | 790 return false; |
789 } | 791 } |
790 } | 792 } |
791 } | 793 } |
792 | 794 |
793 return true; | 795 return true; |
794 } | 796 } |
795 | 797 |
796 | 798 |
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 } | 2113 } |
2112 | 2114 |
2113 var locales = %_Arguments(0); | 2115 var locales = %_Arguments(0); |
2114 var options = %_Arguments(1); | 2116 var options = %_Arguments(1); |
2115 return toLocaleDateTime( | 2117 return toLocaleDateTime( |
2116 this, locales, options, 'time', 'time', 'dateformattime'); | 2118 this, locales, options, 'time', 'time', 'dateformattime'); |
2117 } | 2119 } |
2118 ); | 2120 ); |
2119 | 2121 |
2120 }) | 2122 }) |
OLD | NEW |