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 13 matching lines...) Expand all Loading... |
24 var GlobalDate = global.Date; | 24 var GlobalDate = global.Date; |
25 var GlobalNumber = global.Number; | 25 var GlobalNumber = global.Number; |
26 var GlobalRegExp = global.RegExp; | 26 var GlobalRegExp = global.RegExp; |
27 var GlobalString = global.String; | 27 var GlobalString = global.String; |
28 var InstallFunctions = utils.InstallFunctions; | 28 var InstallFunctions = utils.InstallFunctions; |
29 var InstallGetter = utils.InstallGetter; | 29 var InstallGetter = utils.InstallGetter; |
30 var InternalArray = utils.InternalArray; | 30 var InternalArray = utils.InternalArray; |
31 var InternalRegExpMatch; | 31 var InternalRegExpMatch; |
32 var InternalRegExpReplace | 32 var InternalRegExpReplace |
33 var IsNaN; | 33 var IsNaN; |
34 var MakeError; | |
35 var MakeRangeError; | |
36 var MakeTypeError; | |
37 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); | 34 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); |
38 var OverrideFunction = utils.OverrideFunction; | 35 var OverrideFunction = utils.OverrideFunction; |
39 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); | 36 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); |
40 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); | 37 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); |
41 var SetFunctionName = utils.SetFunctionName; | 38 var SetFunctionName = utils.SetFunctionName; |
42 var StringIndexOf; | 39 var StringIndexOf; |
43 var StringLastIndexOf; | 40 var StringLastIndexOf; |
44 var StringSubstr; | 41 var StringSubstr; |
45 var StringSubstring; | 42 var StringSubstring; |
46 | 43 |
47 utils.Import(function(from) { | 44 utils.Import(function(from) { |
48 ArrayIndexOf = from.ArrayIndexOf; | 45 ArrayIndexOf = from.ArrayIndexOf; |
49 ArrayJoin = from.ArrayJoin; | 46 ArrayJoin = from.ArrayJoin; |
50 ArrayPush = from.ArrayPush; | 47 ArrayPush = from.ArrayPush; |
51 IsNaN = from.IsNaN; | 48 IsNaN = from.IsNaN; |
52 MakeError = from.MakeError; | |
53 MakeRangeError = from.MakeRangeError; | |
54 MakeTypeError = from.MakeTypeError; | |
55 InternalRegExpMatch = from.InternalRegExpMatch; | 49 InternalRegExpMatch = from.InternalRegExpMatch; |
56 InternalRegExpReplace = from.InternalRegExpReplace; | 50 InternalRegExpReplace = from.InternalRegExpReplace; |
57 StringIndexOf = from.StringIndexOf; | 51 StringIndexOf = from.StringIndexOf; |
58 StringLastIndexOf = from.StringLastIndexOf; | 52 StringLastIndexOf = from.StringLastIndexOf; |
59 StringSubstr = from.StringSubstr; | 53 StringSubstr = from.StringSubstr; |
60 StringSubstring = from.StringSubstring; | 54 StringSubstring = from.StringSubstring; |
61 }); | 55 }); |
62 | 56 |
63 utils.ImportFromExperimental(function(from) { | 57 utils.ImportFromExperimental(function(from) { |
64 FLAG_intl_extra = from.FLAG_intl_extra; | 58 FLAG_intl_extra = from.FLAG_intl_extra; |
(...skipping 20 matching lines...) Expand all Loading... |
85 function AddBoundMethod(obj, methodName, implementation, length, type) { | 79 function AddBoundMethod(obj, methodName, implementation, length, type) { |
86 %CheckIsBootstrapping(); | 80 %CheckIsBootstrapping(); |
87 var internalName = %CreatePrivateSymbol(methodName); | 81 var internalName = %CreatePrivateSymbol(methodName); |
88 // Making getter an anonymous function will cause | 82 // Making getter an anonymous function will cause |
89 // %DefineGetterPropertyUnchecked to properly set the "name" | 83 // %DefineGetterPropertyUnchecked to properly set the "name" |
90 // property on each JSFunction instance created here, rather | 84 // property on each JSFunction instance created here, rather |
91 // than (as utils.InstallGetter would) on the SharedFunctionInfo | 85 // than (as utils.InstallGetter would) on the SharedFunctionInfo |
92 // associated with all functions returned from AddBoundMethod. | 86 // associated with all functions returned from AddBoundMethod. |
93 var getter = ANONYMOUS_FUNCTION(function() { | 87 var getter = ANONYMOUS_FUNCTION(function() { |
94 if (!%IsInitializedIntlObjectOfType(this, type)) { | 88 if (!%IsInitializedIntlObjectOfType(this, type)) { |
95 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); | 89 throw %make_type_error(kMethodCalledOnWrongObject, methodName); |
96 } | 90 } |
97 if (IS_UNDEFINED(this[internalName])) { | 91 if (IS_UNDEFINED(this[internalName])) { |
98 var boundMethod; | 92 var boundMethod; |
99 if (IS_UNDEFINED(length) || length === 2) { | 93 if (IS_UNDEFINED(length) || length === 2) { |
100 boundMethod = ANONYMOUS_FUNCTION((x, y) => implementation(this, x, y)); | 94 boundMethod = ANONYMOUS_FUNCTION((x, y) => implementation(this, x, y)); |
101 } else if (length === 1) { | 95 } else if (length === 1) { |
102 boundMethod = ANONYMOUS_FUNCTION(x => implementation(this, x)); | 96 boundMethod = ANONYMOUS_FUNCTION(x => implementation(this, x)); |
103 } else { | 97 } else { |
104 boundMethod = ANONYMOUS_FUNCTION((...args) => { | 98 boundMethod = ANONYMOUS_FUNCTION((...args) => { |
105 // DateTimeFormat.format needs to be 0 arg method, but can still | 99 // DateTimeFormat.format needs to be 0 arg method, but can still |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 return TIMEZONE_NAME_LOCATION_PART_RE; | 257 return TIMEZONE_NAME_LOCATION_PART_RE; |
264 } | 258 } |
265 | 259 |
266 | 260 |
267 /** | 261 /** |
268 * Returns an intersection of locales and service supported locales. | 262 * Returns an intersection of locales and service supported locales. |
269 * Parameter locales is treated as a priority list. | 263 * Parameter locales is treated as a priority list. |
270 */ | 264 */ |
271 function supportedLocalesOf(service, locales, options) { | 265 function supportedLocalesOf(service, locales, options) { |
272 if (IS_NULL(InternalRegExpMatch(GetServiceRE(), service))) { | 266 if (IS_NULL(InternalRegExpMatch(GetServiceRE(), service))) { |
273 throw MakeError(kWrongServiceType, service); | 267 throw %make_error(kWrongServiceType, service); |
274 } | 268 } |
275 | 269 |
276 // Provide defaults if matcher was not specified. | 270 // Provide defaults if matcher was not specified. |
277 if (IS_UNDEFINED(options)) { | 271 if (IS_UNDEFINED(options)) { |
278 options = {}; | 272 options = {}; |
279 } else { | 273 } else { |
280 options = TO_OBJECT(options); | 274 options = TO_OBJECT(options); |
281 } | 275 } |
282 | 276 |
283 var matcher = options.localeMatcher; | 277 var matcher = options.localeMatcher; |
284 if (!IS_UNDEFINED(matcher)) { | 278 if (!IS_UNDEFINED(matcher)) { |
285 matcher = TO_STRING(matcher); | 279 matcher = TO_STRING(matcher); |
286 if (matcher !== 'lookup' && matcher !== 'best fit') { | 280 if (matcher !== 'lookup' && matcher !== 'best fit') { |
287 throw MakeRangeError(kLocaleMatcher, matcher); | 281 throw %make_range_error(kLocaleMatcher, matcher); |
288 } | 282 } |
289 } else { | 283 } else { |
290 matcher = 'best fit'; | 284 matcher = 'best fit'; |
291 } | 285 } |
292 | 286 |
293 var requestedLocales = initializeLocaleList(locales); | 287 var requestedLocales = initializeLocaleList(locales); |
294 | 288 |
295 // Cache these, they don't ever change per service. | 289 // Cache these, they don't ever change per service. |
296 if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) { | 290 if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) { |
297 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); | 291 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 return lookupSupportedLocalesOf(requestedLocales, availableLocales); | 343 return lookupSupportedLocalesOf(requestedLocales, availableLocales); |
350 } | 344 } |
351 | 345 |
352 | 346 |
353 /** | 347 /** |
354 * Returns a getOption function that extracts property value for given | 348 * Returns a getOption function that extracts property value for given |
355 * options object. If property is missing it returns defaultValue. If value | 349 * options object. If property is missing it returns defaultValue. If value |
356 * is out of range for that property it throws RangeError. | 350 * is out of range for that property it throws RangeError. |
357 */ | 351 */ |
358 function getGetOption(options, caller) { | 352 function getGetOption(options, caller) { |
359 if (IS_UNDEFINED(options)) throw MakeError(kDefaultOptionsMissing, caller); | 353 if (IS_UNDEFINED(options)) throw %make_error(kDefaultOptionsMissing, caller); |
360 | 354 |
361 var getOption = function getOption(property, type, values, defaultValue) { | 355 var getOption = function getOption(property, type, values, defaultValue) { |
362 if (!IS_UNDEFINED(options[property])) { | 356 if (!IS_UNDEFINED(options[property])) { |
363 var value = options[property]; | 357 var value = options[property]; |
364 switch (type) { | 358 switch (type) { |
365 case 'boolean': | 359 case 'boolean': |
366 value = TO_BOOLEAN(value); | 360 value = TO_BOOLEAN(value); |
367 break; | 361 break; |
368 case 'string': | 362 case 'string': |
369 value = TO_STRING(value); | 363 value = TO_STRING(value); |
370 break; | 364 break; |
371 case 'number': | 365 case 'number': |
372 value = TO_NUMBER(value); | 366 value = TO_NUMBER(value); |
373 break; | 367 break; |
374 default: | 368 default: |
375 throw MakeError(kWrongValueType); | 369 throw %make_error(kWrongValueType); |
376 } | 370 } |
377 | 371 |
378 if (!IS_UNDEFINED(values) && %_Call(ArrayIndexOf, values, value) === -1) { | 372 if (!IS_UNDEFINED(values) && %_Call(ArrayIndexOf, values, value) === -1) { |
379 throw MakeRangeError(kValueOutOfRange, value, caller, property); | 373 throw %make_range_error(kValueOutOfRange, value, caller, property); |
380 } | 374 } |
381 | 375 |
382 return value; | 376 return value; |
383 } | 377 } |
384 | 378 |
385 return defaultValue; | 379 return defaultValue; |
386 } | 380 } |
387 | 381 |
388 return getOption; | 382 return getOption; |
389 } | 383 } |
(...skipping 28 matching lines...) Expand all Loading... |
418 return resolved; | 412 return resolved; |
419 } | 413 } |
420 | 414 |
421 | 415 |
422 /** | 416 /** |
423 * Returns best matched supported locale and extension info using basic | 417 * Returns best matched supported locale and extension info using basic |
424 * lookup algorithm. | 418 * lookup algorithm. |
425 */ | 419 */ |
426 function lookupMatcher(service, requestedLocales) { | 420 function lookupMatcher(service, requestedLocales) { |
427 if (IS_NULL(InternalRegExpMatch(GetServiceRE(), service))) { | 421 if (IS_NULL(InternalRegExpMatch(GetServiceRE(), service))) { |
428 throw MakeError(kWrongServiceType, service); | 422 throw %make_error(kWrongServiceType, service); |
429 } | 423 } |
430 | 424 |
431 // Cache these, they don't ever change per service. | 425 // Cache these, they don't ever change per service. |
432 if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) { | 426 if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) { |
433 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); | 427 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); |
434 } | 428 } |
435 | 429 |
436 for (var i = 0; i < requestedLocales.length; ++i) { | 430 for (var i = 0; i < requestedLocales.length; ++i) { |
437 // Remove all extensions. | 431 // Remove all extensions. |
438 var locale = InternalRegExpReplace( | 432 var locale = InternalRegExpReplace( |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 } | 689 } |
696 | 690 |
697 /** | 691 /** |
698 * Returns titlecased location, bueNos_airES -> Buenos_Aires | 692 * Returns titlecased location, bueNos_airES -> Buenos_Aires |
699 * or ho_cHi_minH -> Ho_Chi_Minh. It is locale-agnostic and only | 693 * or ho_cHi_minH -> Ho_Chi_Minh. It is locale-agnostic and only |
700 * deals with ASCII only characters. | 694 * deals with ASCII only characters. |
701 * 'of', 'au' and 'es' are special-cased and lowercased. | 695 * 'of', 'au' and 'es' are special-cased and lowercased. |
702 */ | 696 */ |
703 function toTitleCaseTimezoneLocation(location) { | 697 function toTitleCaseTimezoneLocation(location) { |
704 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location) | 698 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location) |
705 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, location); | 699 if (IS_NULL(match)) throw %make_range_error(kExpectedLocation, location); |
706 | 700 |
707 var result = toTitleCaseWord(match[1]); | 701 var result = toTitleCaseWord(match[1]); |
708 if (!IS_UNDEFINED(match[2]) && 2 < match.length) { | 702 if (!IS_UNDEFINED(match[2]) && 2 < match.length) { |
709 // The first character is a separator, '_' or '-'. | 703 // The first character is a separator, '_' or '-'. |
710 // None of IANA zone names has both '_' and '-'. | 704 // None of IANA zone names has both '_' and '-'. |
711 var separator = %_Call(StringSubstring, match[2], 0, 1); | 705 var separator = %_Call(StringSubstring, match[2], 0, 1); |
712 var parts = %StringSplit(match[2], separator, kMaxUint32); | 706 var parts = %StringSplit(match[2], separator, kMaxUint32); |
713 for (var i = 1; i < parts.length; i++) { | 707 for (var i = 1; i < parts.length; i++) { |
714 var part = parts[i] | 708 var part = parts[i] |
715 var lowercasedPart = %StringToLowerCase(part); | 709 var lowercasedPart = %StringToLowerCase(part); |
716 result = result + separator + | 710 result = result + separator + |
717 ((lowercasedPart !== 'es' && | 711 ((lowercasedPart !== 'es' && |
718 lowercasedPart !== 'of' && lowercasedPart !== 'au') ? | 712 lowercasedPart !== 'of' && lowercasedPart !== 'au') ? |
719 toTitleCaseWord(part) : lowercasedPart); | 713 toTitleCaseWord(part) : lowercasedPart); |
720 } | 714 } |
721 } | 715 } |
722 return result; | 716 return result; |
723 } | 717 } |
724 | 718 |
725 /** | 719 /** |
726 * Canonicalizes the language tag, or throws in case the tag is invalid. | 720 * Canonicalizes the language tag, or throws in case the tag is invalid. |
727 */ | 721 */ |
728 function canonicalizeLanguageTag(localeID) { | 722 function canonicalizeLanguageTag(localeID) { |
729 // null is typeof 'object' so we have to do extra check. | 723 // null is typeof 'object' so we have to do extra check. |
730 if ((!IS_STRING(localeID) && !IS_RECEIVER(localeID)) || | 724 if ((!IS_STRING(localeID) && !IS_RECEIVER(localeID)) || |
731 IS_NULL(localeID)) { | 725 IS_NULL(localeID)) { |
732 throw MakeTypeError(kLanguageID); | 726 throw %make_type_error(kLanguageID); |
733 } | 727 } |
734 | 728 |
735 // Optimize for the most common case; a language code alone in | 729 // Optimize for the most common case; a language code alone in |
736 // the canonical form/lowercase (e.g. "en", "fil"). | 730 // the canonical form/lowercase (e.g. "en", "fil"). |
737 if (IS_STRING(localeID) && | 731 if (IS_STRING(localeID) && |
738 !IS_NULL(InternalRegExpMatch(/^[a-z]{2,3}$/, localeID))) { | 732 !IS_NULL(InternalRegExpMatch(/^[a-z]{2,3}$/, localeID))) { |
739 return localeID; | 733 return localeID; |
740 } | 734 } |
741 | 735 |
742 var localeString = TO_STRING(localeID); | 736 var localeString = TO_STRING(localeID); |
743 | 737 |
744 if (isValidLanguageTag(localeString) === false) { | 738 if (isValidLanguageTag(localeString) === false) { |
745 throw MakeRangeError(kInvalidLanguageTag, localeString); | 739 throw %make_range_error(kInvalidLanguageTag, localeString); |
746 } | 740 } |
747 | 741 |
748 var tag = %CanonicalizeLanguageTag(localeString); | 742 var tag = %CanonicalizeLanguageTag(localeString); |
749 if (tag === 'invalid-tag') { | 743 if (tag === 'invalid-tag') { |
750 throw MakeRangeError(kInvalidLanguageTag, localeString); | 744 throw %make_range_error(kInvalidLanguageTag, localeString); |
751 } | 745 } |
752 | 746 |
753 return tag; | 747 return tag; |
754 } | 748 } |
755 | 749 |
756 | 750 |
757 /** | 751 /** |
758 * Returns an array where all locales are canonicalized and duplicates removed. | 752 * Returns an array where all locales are canonicalized and duplicates removed. |
759 * Throws on locales that are not well formed BCP47 tags. | 753 * Throws on locales that are not well formed BCP47 tags. |
760 */ | 754 */ |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 this[resolvedSymbol] = value; | 884 this[resolvedSymbol] = value; |
891 } | 885 } |
892 }; | 886 }; |
893 | 887 |
894 /** | 888 /** |
895 * Initializes the given object so it's a valid Collator instance. | 889 * Initializes the given object so it's a valid Collator instance. |
896 * Useful for subclassing. | 890 * Useful for subclassing. |
897 */ | 891 */ |
898 function initializeCollator(collator, locales, options) { | 892 function initializeCollator(collator, locales, options) { |
899 if (%IsInitializedIntlObject(collator)) { | 893 if (%IsInitializedIntlObject(collator)) { |
900 throw MakeTypeError(kReinitializeIntl, "Collator"); | 894 throw %make_type_error(kReinitializeIntl, "Collator"); |
901 } | 895 } |
902 | 896 |
903 if (IS_UNDEFINED(options)) { | 897 if (IS_UNDEFINED(options)) { |
904 options = {}; | 898 options = {}; |
905 } | 899 } |
906 | 900 |
907 var getOption = getGetOption(options, 'collator'); | 901 var getOption = getGetOption(options, 'collator'); |
908 | 902 |
909 var internalOptions = {}; | 903 var internalOptions = {}; |
910 | 904 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 return initializeCollator(TO_OBJECT(this), locales, options); | 1010 return initializeCollator(TO_OBJECT(this), locales, options); |
1017 } | 1011 } |
1018 ); | 1012 ); |
1019 | 1013 |
1020 | 1014 |
1021 /** | 1015 /** |
1022 * Collator resolvedOptions method. | 1016 * Collator resolvedOptions method. |
1023 */ | 1017 */ |
1024 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { | 1018 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { |
1025 if (!IS_UNDEFINED(new.target)) { | 1019 if (!IS_UNDEFINED(new.target)) { |
1026 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1020 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1027 } | 1021 } |
1028 | 1022 |
1029 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { | 1023 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { |
1030 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "Collator"); | 1024 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "Collator"); |
1031 } | 1025 } |
1032 | 1026 |
1033 var coll = this; | 1027 var coll = this; |
1034 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, | 1028 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, |
1035 coll[resolvedSymbol].locale); | 1029 coll[resolvedSymbol].locale); |
1036 | 1030 |
1037 return { | 1031 return { |
1038 locale: locale, | 1032 locale: locale, |
1039 usage: coll[resolvedSymbol].usage, | 1033 usage: coll[resolvedSymbol].usage, |
1040 sensitivity: coll[resolvedSymbol].sensitivity, | 1034 sensitivity: coll[resolvedSymbol].sensitivity, |
1041 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, | 1035 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, |
1042 numeric: coll[resolvedSymbol].numeric, | 1036 numeric: coll[resolvedSymbol].numeric, |
1043 caseFirst: coll[resolvedSymbol].caseFirst, | 1037 caseFirst: coll[resolvedSymbol].caseFirst, |
1044 collation: coll[resolvedSymbol].collation | 1038 collation: coll[resolvedSymbol].collation |
1045 }; | 1039 }; |
1046 } | 1040 } |
1047 ); | 1041 ); |
1048 | 1042 |
1049 | 1043 |
1050 /** | 1044 /** |
1051 * Returns the subset of the given locale list for which this locale list | 1045 * Returns the subset of the given locale list for which this locale list |
1052 * has a matching (possibly fallback) locale. Locales appear in the same | 1046 * has a matching (possibly fallback) locale. Locales appear in the same |
1053 * order in the returned list as in the input list. | 1047 * order in the returned list as in the input list. |
1054 * Options are optional parameter. | 1048 * Options are optional parameter. |
1055 */ | 1049 */ |
1056 InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) { | 1050 InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) { |
1057 if (!IS_UNDEFINED(new.target)) { | 1051 if (!IS_UNDEFINED(new.target)) { |
1058 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1052 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1059 } | 1053 } |
1060 | 1054 |
1061 return supportedLocalesOf('collator', locales, arguments[1]); | 1055 return supportedLocalesOf('collator', locales, arguments[1]); |
1062 } | 1056 } |
1063 ); | 1057 ); |
1064 | 1058 |
1065 | 1059 |
1066 /** | 1060 /** |
1067 * When the compare method is called with two arguments x and y, it returns a | 1061 * When the compare method is called with two arguments x and y, it returns a |
1068 * Number other than NaN that represents the result of a locale-sensitive | 1062 * Number other than NaN that represents the result of a locale-sensitive |
(...skipping 25 matching lines...) Expand all Loading... |
1094 | 1088 |
1095 /** | 1089 /** |
1096 * Returns the valid digit count for a property, or throws RangeError on | 1090 * Returns the valid digit count for a property, or throws RangeError on |
1097 * a value out of the range. | 1091 * a value out of the range. |
1098 */ | 1092 */ |
1099 function getNumberOption(options, property, min, max, fallback) { | 1093 function getNumberOption(options, property, min, max, fallback) { |
1100 var value = options[property]; | 1094 var value = options[property]; |
1101 if (!IS_UNDEFINED(value)) { | 1095 if (!IS_UNDEFINED(value)) { |
1102 value = TO_NUMBER(value); | 1096 value = TO_NUMBER(value); |
1103 if (NUMBER_IS_NAN(value) || value < min || value > max) { | 1097 if (NUMBER_IS_NAN(value) || value < min || value > max) { |
1104 throw MakeRangeError(kPropertyValueOutOfRange, property); | 1098 throw %make_range_error(kPropertyValueOutOfRange, property); |
1105 } | 1099 } |
1106 return %math_floor(value); | 1100 return %math_floor(value); |
1107 } | 1101 } |
1108 | 1102 |
1109 return fallback; | 1103 return fallback; |
1110 } | 1104 } |
1111 | 1105 |
1112 var patternAccessor = { | 1106 var patternAccessor = { |
1113 get() { | 1107 get() { |
1114 %IncrementUseCounter(kIntlPattern); | 1108 %IncrementUseCounter(kIntlPattern); |
1115 return this[patternSymbol]; | 1109 return this[patternSymbol]; |
1116 }, | 1110 }, |
1117 set(value) { | 1111 set(value) { |
1118 this[patternSymbol] = value; | 1112 this[patternSymbol] = value; |
1119 } | 1113 } |
1120 }; | 1114 }; |
1121 | 1115 |
1122 /** | 1116 /** |
1123 * Initializes the given object so it's a valid NumberFormat instance. | 1117 * Initializes the given object so it's a valid NumberFormat instance. |
1124 * Useful for subclassing. | 1118 * Useful for subclassing. |
1125 */ | 1119 */ |
1126 function initializeNumberFormat(numberFormat, locales, options) { | 1120 function initializeNumberFormat(numberFormat, locales, options) { |
1127 if (%IsInitializedIntlObject(numberFormat)) { | 1121 if (%IsInitializedIntlObject(numberFormat)) { |
1128 throw MakeTypeError(kReinitializeIntl, "NumberFormat"); | 1122 throw %make_type_error(kReinitializeIntl, "NumberFormat"); |
1129 } | 1123 } |
1130 | 1124 |
1131 if (IS_UNDEFINED(options)) { | 1125 if (IS_UNDEFINED(options)) { |
1132 options = {}; | 1126 options = {}; |
1133 } | 1127 } |
1134 | 1128 |
1135 var getOption = getGetOption(options, 'numberformat'); | 1129 var getOption = getGetOption(options, 'numberformat'); |
1136 | 1130 |
1137 var locale = resolveLocale('numberformat', locales, options); | 1131 var locale = resolveLocale('numberformat', locales, options); |
1138 | 1132 |
1139 var internalOptions = {}; | 1133 var internalOptions = {}; |
1140 defineWEProperty(internalOptions, 'style', getOption( | 1134 defineWEProperty(internalOptions, 'style', getOption( |
1141 'style', 'string', ['decimal', 'percent', 'currency'], 'decimal')); | 1135 'style', 'string', ['decimal', 'percent', 'currency'], 'decimal')); |
1142 | 1136 |
1143 var currency = getOption('currency', 'string'); | 1137 var currency = getOption('currency', 'string'); |
1144 if (!IS_UNDEFINED(currency) && !isWellFormedCurrencyCode(currency)) { | 1138 if (!IS_UNDEFINED(currency) && !isWellFormedCurrencyCode(currency)) { |
1145 throw MakeRangeError(kInvalidCurrencyCode, currency); | 1139 throw %make_range_error(kInvalidCurrencyCode, currency); |
1146 } | 1140 } |
1147 | 1141 |
1148 if (internalOptions.style === 'currency' && IS_UNDEFINED(currency)) { | 1142 if (internalOptions.style === 'currency' && IS_UNDEFINED(currency)) { |
1149 throw MakeTypeError(kCurrencyCode); | 1143 throw %make_type_error(kCurrencyCode); |
1150 } | 1144 } |
1151 | 1145 |
1152 var currencyDisplay = getOption( | 1146 var currencyDisplay = getOption( |
1153 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol'); | 1147 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol'); |
1154 if (internalOptions.style === 'currency') { | 1148 if (internalOptions.style === 'currency') { |
1155 defineWEProperty(internalOptions, 'currency', %StringToUpperCase(currency)); | 1149 defineWEProperty(internalOptions, 'currency', %StringToUpperCase(currency)); |
1156 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay); | 1150 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay); |
1157 } | 1151 } |
1158 | 1152 |
1159 // Digit ranges. | 1153 // Digit ranges. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 return initializeNumberFormat(TO_OBJECT(this), locales, options); | 1255 return initializeNumberFormat(TO_OBJECT(this), locales, options); |
1262 } | 1256 } |
1263 ); | 1257 ); |
1264 | 1258 |
1265 | 1259 |
1266 /** | 1260 /** |
1267 * NumberFormat resolvedOptions method. | 1261 * NumberFormat resolvedOptions method. |
1268 */ | 1262 */ |
1269 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { | 1263 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
1270 if (!IS_UNDEFINED(new.target)) { | 1264 if (!IS_UNDEFINED(new.target)) { |
1271 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1265 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1272 } | 1266 } |
1273 | 1267 |
1274 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { | 1268 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { |
1275 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "NumberFormat"); | 1269 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "NumberFormat"); |
1276 } | 1270 } |
1277 | 1271 |
1278 var format = this; | 1272 var format = this; |
1279 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, | 1273 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, |
1280 format[resolvedSymbol].locale); | 1274 format[resolvedSymbol].locale); |
1281 | 1275 |
1282 var result = { | 1276 var result = { |
1283 locale: locale, | 1277 locale: locale, |
1284 numberingSystem: format[resolvedSymbol].numberingSystem, | 1278 numberingSystem: format[resolvedSymbol].numberingSystem, |
1285 style: format[resolvedSymbol].style, | 1279 style: format[resolvedSymbol].style, |
(...skipping 25 matching lines...) Expand all Loading... |
1311 | 1305 |
1312 | 1306 |
1313 /** | 1307 /** |
1314 * Returns the subset of the given locale list for which this locale list | 1308 * Returns the subset of the given locale list for which this locale list |
1315 * has a matching (possibly fallback) locale. Locales appear in the same | 1309 * has a matching (possibly fallback) locale. Locales appear in the same |
1316 * order in the returned list as in the input list. | 1310 * order in the returned list as in the input list. |
1317 * Options are optional parameter. | 1311 * Options are optional parameter. |
1318 */ | 1312 */ |
1319 InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { | 1313 InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { |
1320 if (!IS_UNDEFINED(new.target)) { | 1314 if (!IS_UNDEFINED(new.target)) { |
1321 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1315 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1322 } | 1316 } |
1323 | 1317 |
1324 return supportedLocalesOf('numberformat', locales, arguments[1]); | 1318 return supportedLocalesOf('numberformat', locales, arguments[1]); |
1325 } | 1319 } |
1326 ); | 1320 ); |
1327 | 1321 |
1328 | 1322 |
1329 /** | 1323 /** |
1330 * Returns a String value representing the result of calling ToNumber(value) | 1324 * Returns a String value representing the result of calling ToNumber(value) |
1331 * according to the effective locale and the formatting options of this | 1325 * according to the effective locale and the formatting options of this |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 } | 1542 } |
1549 | 1543 |
1550 | 1544 |
1551 /** | 1545 /** |
1552 * Initializes the given object so it's a valid DateTimeFormat instance. | 1546 * Initializes the given object so it's a valid DateTimeFormat instance. |
1553 * Useful for subclassing. | 1547 * Useful for subclassing. |
1554 */ | 1548 */ |
1555 function initializeDateTimeFormat(dateFormat, locales, options) { | 1549 function initializeDateTimeFormat(dateFormat, locales, options) { |
1556 | 1550 |
1557 if (%IsInitializedIntlObject(dateFormat)) { | 1551 if (%IsInitializedIntlObject(dateFormat)) { |
1558 throw MakeTypeError(kReinitializeIntl, "DateTimeFormat"); | 1552 throw %make_type_error(kReinitializeIntl, "DateTimeFormat"); |
1559 } | 1553 } |
1560 | 1554 |
1561 if (IS_UNDEFINED(options)) { | 1555 if (IS_UNDEFINED(options)) { |
1562 options = {}; | 1556 options = {}; |
1563 } | 1557 } |
1564 | 1558 |
1565 var locale = resolveLocale('dateformat', locales, options); | 1559 var locale = resolveLocale('dateformat', locales, options); |
1566 | 1560 |
1567 options = toDateTimeOptions(options, 'any', 'date'); | 1561 options = toDateTimeOptions(options, 'any', 'date'); |
1568 | 1562 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 timeZoneName: {writable: true}, | 1610 timeZoneName: {writable: true}, |
1617 tz: {value: tz, writable: true}, | 1611 tz: {value: tz, writable: true}, |
1618 weekday: {writable: true}, | 1612 weekday: {writable: true}, |
1619 year: {writable: true} | 1613 year: {writable: true} |
1620 }); | 1614 }); |
1621 | 1615 |
1622 var formatter = %CreateDateTimeFormat( | 1616 var formatter = %CreateDateTimeFormat( |
1623 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); | 1617 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); |
1624 | 1618 |
1625 if (resolved.timeZone === "Etc/Unknown") { | 1619 if (resolved.timeZone === "Etc/Unknown") { |
1626 throw MakeRangeError(kUnsupportedTimeZone, tz); | 1620 throw %make_range_error(kUnsupportedTimeZone, tz); |
1627 } | 1621 } |
1628 | 1622 |
1629 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); | 1623 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); |
1630 dateFormat[resolvedSymbol] = resolved; | 1624 dateFormat[resolvedSymbol] = resolved; |
1631 if (FLAG_intl_extra) { | 1625 if (FLAG_intl_extra) { |
1632 %object_define_property(resolved, 'pattern', patternAccessor); | 1626 %object_define_property(resolved, 'pattern', patternAccessor); |
1633 %object_define_property(dateFormat, 'resolved', resolvedAccessor); | 1627 %object_define_property(dateFormat, 'resolved', resolvedAccessor); |
1634 } | 1628 } |
1635 | 1629 |
1636 return dateFormat; | 1630 return dateFormat; |
(...skipping 18 matching lines...) Expand all Loading... |
1655 return initializeDateTimeFormat(TO_OBJECT(this), locales, options); | 1649 return initializeDateTimeFormat(TO_OBJECT(this), locales, options); |
1656 } | 1650 } |
1657 ); | 1651 ); |
1658 | 1652 |
1659 | 1653 |
1660 /** | 1654 /** |
1661 * DateTimeFormat resolvedOptions method. | 1655 * DateTimeFormat resolvedOptions method. |
1662 */ | 1656 */ |
1663 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { | 1657 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
1664 if (!IS_UNDEFINED(new.target)) { | 1658 if (!IS_UNDEFINED(new.target)) { |
1665 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1659 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1666 } | 1660 } |
1667 | 1661 |
1668 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { | 1662 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { |
1669 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "DateTimeFormat"); | 1663 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "DateTimeFormat"
); |
1670 } | 1664 } |
1671 | 1665 |
1672 /** | 1666 /** |
1673 * Maps ICU calendar names into LDML type. | 1667 * Maps ICU calendar names into LDML type. |
1674 */ | 1668 */ |
1675 var ICU_CALENDAR_MAP = { | 1669 var ICU_CALENDAR_MAP = { |
1676 'gregorian': 'gregory', | 1670 'gregorian': 'gregory', |
1677 'japanese': 'japanese', | 1671 'japanese': 'japanese', |
1678 'buddhist': 'buddhist', | 1672 'buddhist': 'buddhist', |
1679 'roc': 'roc', | 1673 'roc': 'roc', |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 | 1718 |
1725 | 1719 |
1726 /** | 1720 /** |
1727 * Returns the subset of the given locale list for which this locale list | 1721 * Returns the subset of the given locale list for which this locale list |
1728 * has a matching (possibly fallback) locale. Locales appear in the same | 1722 * has a matching (possibly fallback) locale. Locales appear in the same |
1729 * order in the returned list as in the input list. | 1723 * order in the returned list as in the input list. |
1730 * Options are optional parameter. | 1724 * Options are optional parameter. |
1731 */ | 1725 */ |
1732 InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { | 1726 InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { |
1733 if (!IS_UNDEFINED(new.target)) { | 1727 if (!IS_UNDEFINED(new.target)) { |
1734 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1728 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1735 } | 1729 } |
1736 | 1730 |
1737 return supportedLocalesOf('dateformat', locales, arguments[1]); | 1731 return supportedLocalesOf('dateformat', locales, arguments[1]); |
1738 } | 1732 } |
1739 ); | 1733 ); |
1740 | 1734 |
1741 | 1735 |
1742 /** | 1736 /** |
1743 * Returns a String value representing the result of calling ToNumber(date) | 1737 * Returns a String value representing the result of calling ToNumber(date) |
1744 * according to the effective locale and the formatting options of this | 1738 * according to the effective locale and the formatting options of this |
1745 * DateTimeFormat. | 1739 * DateTimeFormat. |
1746 */ | 1740 */ |
1747 function formatDate(formatter, dateValue) { | 1741 function formatDate(formatter, dateValue) { |
1748 var dateMs; | 1742 var dateMs; |
1749 if (IS_UNDEFINED(dateValue)) { | 1743 if (IS_UNDEFINED(dateValue)) { |
1750 dateMs = %DateCurrentTime(); | 1744 dateMs = %DateCurrentTime(); |
1751 } else { | 1745 } else { |
1752 dateMs = TO_NUMBER(dateValue); | 1746 dateMs = TO_NUMBER(dateValue); |
1753 } | 1747 } |
1754 | 1748 |
1755 if (!NUMBER_IS_FINITE(dateMs)) throw MakeRangeError(kDateRange); | 1749 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); |
1756 | 1750 |
1757 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), | 1751 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), |
1758 new GlobalDate(dateMs)); | 1752 new GlobalDate(dateMs)); |
1759 } | 1753 } |
1760 | 1754 |
1761 | 1755 |
1762 /** | 1756 /** |
1763 * Returns a Date object representing the result of calling ToString(value) | 1757 * Returns a Date object representing the result of calling ToString(value) |
1764 * according to the effective locale and the formatting options of this | 1758 * according to the effective locale and the formatting options of this |
1765 * DateTimeFormat. | 1759 * DateTimeFormat. |
(...skipping 27 matching lines...) Expand all Loading... |
1793 if (upperID === 'UTC' || upperID === 'GMT' || | 1787 if (upperID === 'UTC' || upperID === 'GMT' || |
1794 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') { | 1788 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') { |
1795 return 'UTC'; | 1789 return 'UTC'; |
1796 } | 1790 } |
1797 | 1791 |
1798 // TODO(jshin): Add support for Etc/GMT[+-]([1-9]|1[0-2]) | 1792 // TODO(jshin): Add support for Etc/GMT[+-]([1-9]|1[0-2]) |
1799 | 1793 |
1800 // We expect only _, '-' and / beside ASCII letters. | 1794 // We expect only _, '-' and / beside ASCII letters. |
1801 // All inputs should conform to Area/Location(/Location)* from now on. | 1795 // All inputs should conform to Area/Location(/Location)* from now on. |
1802 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID); | 1796 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID); |
1803 if (IS_NULL(match)) throw MakeRangeError(kExpectedTimezoneID, tzID); | 1797 if (IS_NULL(match)) throw %make_range_error(kExpectedTimezoneID, tzID); |
1804 | 1798 |
1805 var result = toTitleCaseTimezoneLocation(match[1]) + '/' + | 1799 var result = toTitleCaseTimezoneLocation(match[1]) + '/' + |
1806 toTitleCaseTimezoneLocation(match[2]); | 1800 toTitleCaseTimezoneLocation(match[2]); |
1807 | 1801 |
1808 if (!IS_UNDEFINED(match[3]) && 3 < match.length) { | 1802 if (!IS_UNDEFINED(match[3]) && 3 < match.length) { |
1809 var locations = %StringSplit(match[3], '/', kMaxUint32); | 1803 var locations = %StringSplit(match[3], '/', kMaxUint32); |
1810 // The 1st element is empty. Starts with i=1. | 1804 // The 1st element is empty. Starts with i=1. |
1811 for (var i = 1; i < locations.length; i++) { | 1805 for (var i = 1; i < locations.length; i++) { |
1812 result = result + '/' + toTitleCaseTimezoneLocation(locations[i]); | 1806 result = result + '/' + toTitleCaseTimezoneLocation(locations[i]); |
1813 } | 1807 } |
1814 } | 1808 } |
1815 | 1809 |
1816 return result; | 1810 return result; |
1817 } | 1811 } |
1818 | 1812 |
1819 /** | 1813 /** |
1820 * Initializes the given object so it's a valid BreakIterator instance. | 1814 * Initializes the given object so it's a valid BreakIterator instance. |
1821 * Useful for subclassing. | 1815 * Useful for subclassing. |
1822 */ | 1816 */ |
1823 function initializeBreakIterator(iterator, locales, options) { | 1817 function initializeBreakIterator(iterator, locales, options) { |
1824 if (%IsInitializedIntlObject(iterator)) { | 1818 if (%IsInitializedIntlObject(iterator)) { |
1825 throw MakeTypeError(kReinitializeIntl, "v8BreakIterator"); | 1819 throw %make_type_error(kReinitializeIntl, "v8BreakIterator"); |
1826 } | 1820 } |
1827 | 1821 |
1828 if (IS_UNDEFINED(options)) { | 1822 if (IS_UNDEFINED(options)) { |
1829 options = {}; | 1823 options = {}; |
1830 } | 1824 } |
1831 | 1825 |
1832 var getOption = getGetOption(options, 'breakiterator'); | 1826 var getOption = getGetOption(options, 'breakiterator'); |
1833 | 1827 |
1834 var internalOptions = {}; | 1828 var internalOptions = {}; |
1835 | 1829 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 } | 1871 } |
1878 ); | 1872 ); |
1879 | 1873 |
1880 | 1874 |
1881 /** | 1875 /** |
1882 * BreakIterator resolvedOptions method. | 1876 * BreakIterator resolvedOptions method. |
1883 */ | 1877 */ |
1884 InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions', | 1878 InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions', |
1885 function() { | 1879 function() { |
1886 if (!IS_UNDEFINED(new.target)) { | 1880 if (!IS_UNDEFINED(new.target)) { |
1887 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1881 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1888 } | 1882 } |
1889 | 1883 |
1890 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { | 1884 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { |
1891 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "v8BreakIterator"); | 1885 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "v8BreakIterator
"); |
1892 } | 1886 } |
1893 | 1887 |
1894 var segmenter = this; | 1888 var segmenter = this; |
1895 var locale = | 1889 var locale = |
1896 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale, | 1890 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale, |
1897 segmenter[resolvedSymbol].locale); | 1891 segmenter[resolvedSymbol].locale); |
1898 | 1892 |
1899 return { | 1893 return { |
1900 locale: locale, | 1894 locale: locale, |
1901 type: segmenter[resolvedSymbol].type | 1895 type: segmenter[resolvedSymbol].type |
1902 }; | 1896 }; |
1903 } | 1897 } |
1904 ); | 1898 ); |
1905 | 1899 |
1906 | 1900 |
1907 /** | 1901 /** |
1908 * Returns the subset of the given locale list for which this locale list | 1902 * Returns the subset of the given locale list for which this locale list |
1909 * has a matching (possibly fallback) locale. Locales appear in the same | 1903 * has a matching (possibly fallback) locale. Locales appear in the same |
1910 * order in the returned list as in the input list. | 1904 * order in the returned list as in the input list. |
1911 * Options are optional parameter. | 1905 * Options are optional parameter. |
1912 */ | 1906 */ |
1913 InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf', | 1907 InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf', |
1914 function(locales) { | 1908 function(locales) { |
1915 if (!IS_UNDEFINED(new.target)) { | 1909 if (!IS_UNDEFINED(new.target)) { |
1916 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1910 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
1917 } | 1911 } |
1918 | 1912 |
1919 return supportedLocalesOf('breakiterator', locales, arguments[1]); | 1913 return supportedLocalesOf('breakiterator', locales, arguments[1]); |
1920 } | 1914 } |
1921 ); | 1915 ); |
1922 | 1916 |
1923 | 1917 |
1924 /** | 1918 /** |
1925 * Adopts text to segment using the iterator. Old text, if present, | 1919 * Adopts text to segment using the iterator. Old text, if present, |
1926 * gets discarded. | 1920 * gets discarded. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 return %StringLocaleConvertCase(s, isToUpper, | 2049 return %StringLocaleConvertCase(s, isToUpper, |
2056 CUSTOM_CASE_LANGUAGES[langIndex]); | 2050 CUSTOM_CASE_LANGUAGES[langIndex]); |
2057 } | 2051 } |
2058 | 2052 |
2059 /** | 2053 /** |
2060 * Compares this and that, and returns less than 0, 0 or greater than 0 value. | 2054 * Compares this and that, and returns less than 0, 0 or greater than 0 value. |
2061 * Overrides the built-in method. | 2055 * Overrides the built-in method. |
2062 */ | 2056 */ |
2063 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { | 2057 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { |
2064 if (!IS_UNDEFINED(new.target)) { | 2058 if (!IS_UNDEFINED(new.target)) { |
2065 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2059 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2066 } | 2060 } |
2067 | 2061 |
2068 if (IS_NULL_OR_UNDEFINED(this)) { | 2062 if (IS_NULL_OR_UNDEFINED(this)) { |
2069 throw MakeTypeError(kMethodInvokedOnNullOrUndefined); | 2063 throw %make_type_error(kMethodInvokedOnNullOrUndefined); |
2070 } | 2064 } |
2071 | 2065 |
2072 var locales = arguments[1]; | 2066 var locales = arguments[1]; |
2073 var options = arguments[2]; | 2067 var options = arguments[2]; |
2074 var collator = cachedOrNewService('collator', locales, options); | 2068 var collator = cachedOrNewService('collator', locales, options); |
2075 return compare(collator, this, that); | 2069 return compare(collator, this, that); |
2076 } | 2070 } |
2077 ); | 2071 ); |
2078 | 2072 |
2079 | 2073 |
2080 /** | 2074 /** |
2081 * Unicode normalization. This method is called with one argument that | 2075 * Unicode normalization. This method is called with one argument that |
2082 * specifies the normalization form. | 2076 * specifies the normalization form. |
2083 * If none is specified, "NFC" is assumed. | 2077 * If none is specified, "NFC" is assumed. |
2084 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw | 2078 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw |
2085 * a RangeError Exception. | 2079 * a RangeError Exception. |
2086 */ | 2080 */ |
2087 | 2081 |
2088 OverrideFunction(GlobalString.prototype, 'normalize', function() { | 2082 OverrideFunction(GlobalString.prototype, 'normalize', function() { |
2089 if (!IS_UNDEFINED(new.target)) { | 2083 if (!IS_UNDEFINED(new.target)) { |
2090 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2084 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2091 } | 2085 } |
2092 | 2086 |
2093 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); | 2087 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); |
2094 var s = TO_STRING(this); | 2088 var s = TO_STRING(this); |
2095 | 2089 |
2096 var formArg = arguments[0]; | 2090 var formArg = arguments[0]; |
2097 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg); | 2091 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg); |
2098 | 2092 |
2099 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; | 2093 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; |
2100 | 2094 |
2101 var normalizationForm = %_Call(ArrayIndexOf, NORMALIZATION_FORMS, form); | 2095 var normalizationForm = %_Call(ArrayIndexOf, NORMALIZATION_FORMS, form); |
2102 if (normalizationForm === -1) { | 2096 if (normalizationForm === -1) { |
2103 throw MakeRangeError(kNormalizationForm, | 2097 throw %make_range_error(kNormalizationForm, |
2104 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', ')); | 2098 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', ')); |
2105 } | 2099 } |
2106 | 2100 |
2107 return %StringNormalize(s, normalizationForm); | 2101 return %StringNormalize(s, normalizationForm); |
2108 } | 2102 } |
2109 ); | 2103 ); |
2110 | 2104 |
2111 function ToLowerCaseI18N() { | 2105 function ToLowerCaseI18N() { |
2112 if (!IS_UNDEFINED(new.target)) { | 2106 if (!IS_UNDEFINED(new.target)) { |
2113 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2107 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2114 } | 2108 } |
2115 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); | 2109 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); |
2116 var s = TO_STRING(this); | 2110 var s = TO_STRING(this); |
2117 return %StringToLowerCaseI18N(s); | 2111 return %StringToLowerCaseI18N(s); |
2118 } | 2112 } |
2119 | 2113 |
2120 function ToUpperCaseI18N() { | 2114 function ToUpperCaseI18N() { |
2121 if (!IS_UNDEFINED(new.target)) { | 2115 if (!IS_UNDEFINED(new.target)) { |
2122 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2116 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2123 } | 2117 } |
2124 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); | 2118 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); |
2125 var s = TO_STRING(this); | 2119 var s = TO_STRING(this); |
2126 return %StringToUpperCaseI18N(s); | 2120 return %StringToUpperCaseI18N(s); |
2127 } | 2121 } |
2128 | 2122 |
2129 function ToLocaleLowerCaseI18N(locales) { | 2123 function ToLocaleLowerCaseI18N(locales) { |
2130 if (!IS_UNDEFINED(new.target)) { | 2124 if (!IS_UNDEFINED(new.target)) { |
2131 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2125 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2132 } | 2126 } |
2133 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); | 2127 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); |
2134 return LocaleConvertCase(TO_STRING(this), locales, false); | 2128 return LocaleConvertCase(TO_STRING(this), locales, false); |
2135 } | 2129 } |
2136 | 2130 |
2137 %FunctionSetLength(ToLocaleLowerCaseI18N, 0); | 2131 %FunctionSetLength(ToLocaleLowerCaseI18N, 0); |
2138 | 2132 |
2139 function ToLocaleUpperCaseI18N(locales) { | 2133 function ToLocaleUpperCaseI18N(locales) { |
2140 if (!IS_UNDEFINED(new.target)) { | 2134 if (!IS_UNDEFINED(new.target)) { |
2141 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2135 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2142 } | 2136 } |
2143 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); | 2137 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); |
2144 return LocaleConvertCase(TO_STRING(this), locales, true); | 2138 return LocaleConvertCase(TO_STRING(this), locales, true); |
2145 } | 2139 } |
2146 | 2140 |
2147 %FunctionSetLength(ToLocaleUpperCaseI18N, 0); | 2141 %FunctionSetLength(ToLocaleUpperCaseI18N, 0); |
2148 | 2142 |
2149 %FunctionRemovePrototype(ToLowerCaseI18N); | 2143 %FunctionRemovePrototype(ToLowerCaseI18N); |
2150 %FunctionRemovePrototype(ToUpperCaseI18N); | 2144 %FunctionRemovePrototype(ToUpperCaseI18N); |
2151 %FunctionRemovePrototype(ToLocaleLowerCaseI18N); | 2145 %FunctionRemovePrototype(ToLocaleLowerCaseI18N); |
2152 %FunctionRemovePrototype(ToLocaleUpperCaseI18N); | 2146 %FunctionRemovePrototype(ToLocaleUpperCaseI18N); |
2153 | 2147 |
2154 utils.Export(function(to) { | 2148 utils.Export(function(to) { |
2155 to.ToLowerCaseI18N = ToLowerCaseI18N; | 2149 to.ToLowerCaseI18N = ToLowerCaseI18N; |
2156 to.ToUpperCaseI18N = ToUpperCaseI18N; | 2150 to.ToUpperCaseI18N = ToUpperCaseI18N; |
2157 to.ToLocaleLowerCaseI18N = ToLocaleLowerCaseI18N; | 2151 to.ToLocaleLowerCaseI18N = ToLocaleLowerCaseI18N; |
2158 to.ToLocaleUpperCaseI18N = ToLocaleUpperCaseI18N; | 2152 to.ToLocaleUpperCaseI18N = ToLocaleUpperCaseI18N; |
2159 }); | 2153 }); |
2160 | 2154 |
2161 | 2155 |
2162 /** | 2156 /** |
2163 * Formats a Number object (this) using locale and options values. | 2157 * Formats a Number object (this) using locale and options values. |
2164 * If locale or options are omitted, defaults are used. | 2158 * If locale or options are omitted, defaults are used. |
2165 */ | 2159 */ |
2166 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { | 2160 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
2167 if (!IS_UNDEFINED(new.target)) { | 2161 if (!IS_UNDEFINED(new.target)) { |
2168 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2162 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2169 } | 2163 } |
2170 | 2164 |
2171 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { | 2165 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { |
2172 throw MakeTypeError(kMethodInvokedOnWrongType, "Number"); | 2166 throw %make_type_error(kMethodInvokedOnWrongType, "Number"); |
2173 } | 2167 } |
2174 | 2168 |
2175 var locales = arguments[0]; | 2169 var locales = arguments[0]; |
2176 var options = arguments[1]; | 2170 var options = arguments[1]; |
2177 var numberFormat = cachedOrNewService('numberformat', locales, options); | 2171 var numberFormat = cachedOrNewService('numberformat', locales, options); |
2178 return formatNumber(numberFormat, this); | 2172 return formatNumber(numberFormat, this); |
2179 } | 2173 } |
2180 ); | 2174 ); |
2181 | 2175 |
2182 | 2176 |
2183 /** | 2177 /** |
2184 * Returns actual formatted date or fails if date parameter is invalid. | 2178 * Returns actual formatted date or fails if date parameter is invalid. |
2185 */ | 2179 */ |
2186 function toLocaleDateTime(date, locales, options, required, defaults, service) { | 2180 function toLocaleDateTime(date, locales, options, required, defaults, service) { |
2187 if (!(date instanceof GlobalDate)) { | 2181 if (!(date instanceof GlobalDate)) { |
2188 throw MakeTypeError(kMethodInvokedOnWrongType, "Date"); | 2182 throw %make_type_error(kMethodInvokedOnWrongType, "Date"); |
2189 } | 2183 } |
2190 | 2184 |
2191 if (IsNaN(date)) return 'Invalid Date'; | 2185 if (IsNaN(date)) return 'Invalid Date'; |
2192 | 2186 |
2193 var internalOptions = toDateTimeOptions(options, required, defaults); | 2187 var internalOptions = toDateTimeOptions(options, required, defaults); |
2194 | 2188 |
2195 var dateFormat = | 2189 var dateFormat = |
2196 cachedOrNewService(service, locales, options, internalOptions); | 2190 cachedOrNewService(service, locales, options, internalOptions); |
2197 | 2191 |
2198 return formatDate(dateFormat, date); | 2192 return formatDate(dateFormat, date); |
2199 } | 2193 } |
2200 | 2194 |
2201 | 2195 |
2202 /** | 2196 /** |
2203 * Formats a Date object (this) using locale and options values. | 2197 * Formats a Date object (this) using locale and options values. |
2204 * If locale or options are omitted, defaults are used - both date and time are | 2198 * If locale or options are omitted, defaults are used - both date and time are |
2205 * present in the output. | 2199 * present in the output. |
2206 */ | 2200 */ |
2207 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { | 2201 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { |
2208 if (!IS_UNDEFINED(new.target)) { | 2202 if (!IS_UNDEFINED(new.target)) { |
2209 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2203 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2210 } | 2204 } |
2211 | 2205 |
2212 var locales = arguments[0]; | 2206 var locales = arguments[0]; |
2213 var options = arguments[1]; | 2207 var options = arguments[1]; |
2214 return toLocaleDateTime( | 2208 return toLocaleDateTime( |
2215 this, locales, options, 'any', 'all', 'dateformatall'); | 2209 this, locales, options, 'any', 'all', 'dateformatall'); |
2216 } | 2210 } |
2217 ); | 2211 ); |
2218 | 2212 |
2219 | 2213 |
2220 /** | 2214 /** |
2221 * Formats a Date object (this) using locale and options values. | 2215 * Formats a Date object (this) using locale and options values. |
2222 * If locale or options are omitted, defaults are used - only date is present | 2216 * If locale or options are omitted, defaults are used - only date is present |
2223 * in the output. | 2217 * in the output. |
2224 */ | 2218 */ |
2225 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { | 2219 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { |
2226 if (!IS_UNDEFINED(new.target)) { | 2220 if (!IS_UNDEFINED(new.target)) { |
2227 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2221 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2228 } | 2222 } |
2229 | 2223 |
2230 var locales = arguments[0]; | 2224 var locales = arguments[0]; |
2231 var options = arguments[1]; | 2225 var options = arguments[1]; |
2232 return toLocaleDateTime( | 2226 return toLocaleDateTime( |
2233 this, locales, options, 'date', 'date', 'dateformatdate'); | 2227 this, locales, options, 'date', 'date', 'dateformatdate'); |
2234 } | 2228 } |
2235 ); | 2229 ); |
2236 | 2230 |
2237 | 2231 |
2238 /** | 2232 /** |
2239 * Formats a Date object (this) using locale and options values. | 2233 * Formats a Date object (this) using locale and options values. |
2240 * If locale or options are omitted, defaults are used - only time is present | 2234 * If locale or options are omitted, defaults are used - only time is present |
2241 * in the output. | 2235 * in the output. |
2242 */ | 2236 */ |
2243 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { | 2237 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { |
2244 if (!IS_UNDEFINED(new.target)) { | 2238 if (!IS_UNDEFINED(new.target)) { |
2245 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2239 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor); |
2246 } | 2240 } |
2247 | 2241 |
2248 var locales = arguments[0]; | 2242 var locales = arguments[0]; |
2249 var options = arguments[1]; | 2243 var options = arguments[1]; |
2250 return toLocaleDateTime( | 2244 return toLocaleDateTime( |
2251 this, locales, options, 'time', 'time', 'dateformattime'); | 2245 this, locales, options, 'time', 'time', 'dateformattime'); |
2252 } | 2246 } |
2253 ); | 2247 ); |
2254 | 2248 |
2255 utils.Export(function(to) { | 2249 utils.Export(function(to) { |
2256 to.AddBoundMethod = AddBoundMethod; | 2250 to.AddBoundMethod = AddBoundMethod; |
2257 to.IntlParseDate = IntlParseDate; | 2251 to.IntlParseDate = IntlParseDate; |
2258 to.IntlParseNumber = IntlParseNumber; | 2252 to.IntlParseNumber = IntlParseNumber; |
2259 }); | 2253 }); |
2260 | 2254 |
2261 }) | 2255 }) |
OLD | NEW |