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 GlobalBoolean = global.Boolean; | 20 var GlobalBoolean = global.Boolean; |
21 var GlobalDate = global.Date; | 21 var GlobalDate = global.Date; |
22 var GlobalNumber = global.Number; | 22 var GlobalNumber = global.Number; |
23 var GlobalRegExp = global.RegExp; | 23 var GlobalRegExp = global.RegExp; |
24 var GlobalString = global.String; | 24 var GlobalString = global.String; |
| 25 var ObjectDefineProperties = utils.ObjectDefineProperties; |
| 26 var ObjectDefineProperty = utils.ObjectDefineProperty; |
| 27 var SetFunctionName = utils.SetFunctionName; |
25 | 28 |
| 29 var IsFinite; |
| 30 var IsNaN; |
26 var MathFloor; | 31 var MathFloor; |
27 | 32 |
28 utils.Import(function(from) { | 33 utils.Import(function(from) { |
| 34 IsFinite = from.IsFinite; |
| 35 IsNaN = from.IsNaN; |
29 MathFloor = from.MathFloor; | 36 MathFloor = from.MathFloor; |
30 }); | 37 }); |
31 | 38 |
32 // ------------------------------------------------------------------- | 39 // ------------------------------------------------------------------- |
33 | 40 |
34 var Intl = {}; | 41 var Intl = {}; |
35 | 42 |
36 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); | 43 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
37 | 44 |
38 /** | 45 /** |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 TIMEZONE_NAME_CHECK_RE = | 153 TIMEZONE_NAME_CHECK_RE = |
147 new GlobalRegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$'); | 154 new GlobalRegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$'); |
148 } | 155 } |
149 return TIMEZONE_NAME_CHECK_RE; | 156 return TIMEZONE_NAME_CHECK_RE; |
150 } | 157 } |
151 | 158 |
152 /** | 159 /** |
153 * Adds bound method to the prototype of the given object. | 160 * Adds bound method to the prototype of the given object. |
154 */ | 161 */ |
155 function addBoundMethod(obj, methodName, implementation, length) { | 162 function addBoundMethod(obj, methodName, implementation, length) { |
| 163 %CheckIsBootstrapping(); |
156 function getter() { | 164 function getter() { |
157 if (!%IsInitializedIntlObject(this)) { | 165 if (!%IsInitializedIntlObject(this)) { |
158 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); | 166 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); |
159 } | 167 } |
160 var internalName = '__bound' + methodName + '__'; | 168 var internalName = '__bound' + methodName + '__'; |
161 if (IS_UNDEFINED(this[internalName])) { | 169 if (IS_UNDEFINED(this[internalName])) { |
162 var that = this; | 170 var that = this; |
163 var boundMethod; | 171 var boundMethod; |
164 if (IS_UNDEFINED(length) || length === 2) { | 172 if (IS_UNDEFINED(length) || length === 2) { |
165 boundMethod = function(x, y) { | 173 boundMethod = function(x, y) { |
(...skipping 17 matching lines...) Expand all Loading... |
183 // DateTimeFormat.format needs to be 0 arg method, but can stil | 191 // DateTimeFormat.format needs to be 0 arg method, but can stil |
184 // receive optional dateValue param. If one was provided, pass it | 192 // receive optional dateValue param. If one was provided, pass it |
185 // along. | 193 // along. |
186 if (%_ArgumentsLength() > 0) { | 194 if (%_ArgumentsLength() > 0) { |
187 return implementation(that, %_Arguments(0)); | 195 return implementation(that, %_Arguments(0)); |
188 } else { | 196 } else { |
189 return implementation(that); | 197 return implementation(that); |
190 } | 198 } |
191 } | 199 } |
192 } | 200 } |
193 $setFunctionName(boundMethod, internalName); | 201 SetFunctionName(boundMethod, internalName); |
194 %FunctionRemovePrototype(boundMethod); | 202 %FunctionRemovePrototype(boundMethod); |
195 %SetNativeFlag(boundMethod); | 203 %SetNativeFlag(boundMethod); |
196 this[internalName] = boundMethod; | 204 this[internalName] = boundMethod; |
197 } | 205 } |
198 return this[internalName]; | 206 return this[internalName]; |
199 } | 207 } |
200 | 208 |
201 $setFunctionName(getter, methodName); | 209 SetFunctionName(getter, methodName); |
202 %FunctionRemovePrototype(getter); | 210 %FunctionRemovePrototype(getter); |
203 %SetNativeFlag(getter); | 211 %SetNativeFlag(getter); |
204 | 212 |
205 $objectDefineProperty(obj.prototype, methodName, { | 213 ObjectDefineProperty(obj.prototype, methodName, { |
206 get: getter, | 214 get: getter, |
207 enumerable: false, | 215 enumerable: false, |
208 configurable: true | 216 configurable: true |
209 }); | 217 }); |
210 } | 218 } |
211 | 219 |
212 | 220 |
213 /** | 221 /** |
214 * Returns an intersection of locales and service supported locales. | 222 * Returns an intersection of locales and service supported locales. |
215 * Parameter locales is treated as a priority list. | 223 * Parameter locales is treated as a priority list. |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 return extension === ''? '' : '-u' + extension; | 522 return extension === ''? '' : '-u' + extension; |
515 } | 523 } |
516 | 524 |
517 | 525 |
518 /** | 526 /** |
519 * Converts all OwnProperties into | 527 * Converts all OwnProperties into |
520 * configurable: false, writable: false, enumerable: true. | 528 * configurable: false, writable: false, enumerable: true. |
521 */ | 529 */ |
522 function freezeArray(array) { | 530 function freezeArray(array) { |
523 array.forEach(function(element, index) { | 531 array.forEach(function(element, index) { |
524 $objectDefineProperty(array, index, {value: element, | 532 ObjectDefineProperty(array, index, {value: element, |
525 configurable: false, | 533 configurable: false, |
526 writable: false, | 534 writable: false, |
527 enumerable: true}); | 535 enumerable: true}); |
528 }); | 536 }); |
529 | 537 |
530 $objectDefineProperty(array, 'length', {value: array.length, | 538 ObjectDefineProperty(array, 'length', {value: array.length, |
531 writable: false}); | 539 writable: false}); |
532 return array; | 540 return array; |
533 } | 541 } |
534 | 542 |
535 | 543 |
536 /** | 544 /** |
537 * It's sometimes desireable to leave user requested locale instead of ICU | 545 * It's sometimes desireable to leave user requested locale instead of ICU |
538 * supported one (zh-TW is equivalent to zh-Hant-TW, so we should keep shorter | 546 * supported one (zh-TW is equivalent to zh-Hant-TW, so we should keep shorter |
539 * one, if that was what user requested). | 547 * one, if that was what user requested). |
540 * This function returns user specified tag if its maximized form matches ICU | 548 * This function returns user specified tag if its maximized form matches ICU |
541 * resolved locale. If not we return ICU result. | 549 * resolved locale. If not we return ICU result. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 590 |
583 return available; | 591 return available; |
584 } | 592 } |
585 | 593 |
586 | 594 |
587 /** | 595 /** |
588 * Defines a property and sets writable and enumerable to true. | 596 * Defines a property and sets writable and enumerable to true. |
589 * Configurable is false by default. | 597 * Configurable is false by default. |
590 */ | 598 */ |
591 function defineWEProperty(object, property, value) { | 599 function defineWEProperty(object, property, value) { |
592 $objectDefineProperty(object, property, | 600 ObjectDefineProperty(object, property, |
593 {value: value, writable: true, enumerable: true}); | 601 {value: value, writable: true, enumerable: true}); |
594 } | 602 } |
595 | 603 |
596 | 604 |
597 /** | 605 /** |
598 * Adds property to an object if the value is not undefined. | 606 * Adds property to an object if the value is not undefined. |
599 * Sets configurable descriptor to false. | 607 * Sets configurable descriptor to false. |
600 */ | 608 */ |
601 function addWEPropertyIfDefined(object, property, value) { | 609 function addWEPropertyIfDefined(object, property, value) { |
602 if (!IS_UNDEFINED(value)) { | 610 if (!IS_UNDEFINED(value)) { |
603 defineWEProperty(object, property, value); | 611 defineWEProperty(object, property, value); |
604 } | 612 } |
605 } | 613 } |
606 | 614 |
607 | 615 |
608 /** | 616 /** |
609 * Defines a property and sets writable, enumerable and configurable to true. | 617 * Defines a property and sets writable, enumerable and configurable to true. |
610 */ | 618 */ |
611 function defineWECProperty(object, property, value) { | 619 function defineWECProperty(object, property, value) { |
612 $objectDefineProperty(object, property, {value: value, | 620 ObjectDefineProperty(object, property, {value: value, |
613 writable: true, | 621 writable: true, |
614 enumerable: true, | 622 enumerable: true, |
615 configurable: true}); | 623 configurable: true}); |
616 } | 624 } |
617 | 625 |
618 | 626 |
619 /** | 627 /** |
620 * Adds property to an object if the value is not undefined. | 628 * Adds property to an object if the value is not undefined. |
621 * Sets all descriptors to true. | 629 * Sets all descriptors to true. |
622 */ | 630 */ |
623 function addWECPropertyIfDefined(object, property, value) { | 631 function addWECPropertyIfDefined(object, property, value) { |
624 if (!IS_UNDEFINED(value)) { | 632 if (!IS_UNDEFINED(value)) { |
625 defineWECProperty(object, property, value); | 633 defineWECProperty(object, property, value); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 extension = '-u-co-search'; | 874 extension = '-u-co-search'; |
867 } | 875 } |
868 defineWEProperty(internalOptions, 'collation', collation); | 876 defineWEProperty(internalOptions, 'collation', collation); |
869 | 877 |
870 var requestedLocale = locale.locale + extension; | 878 var requestedLocale = locale.locale + extension; |
871 | 879 |
872 // We define all properties C++ code may produce, to prevent security | 880 // We define all properties C++ code may produce, to prevent security |
873 // problems. If malicious user decides to redefine Object.prototype.locale | 881 // problems. If malicious user decides to redefine Object.prototype.locale |
874 // we can't just use plain x.locale = 'us' or in C++ Set("locale", "us"). | 882 // we can't just use plain x.locale = 'us' or in C++ Set("locale", "us"). |
875 // ObjectDefineProperties will either succeed defining or throw an error. | 883 // ObjectDefineProperties will either succeed defining or throw an error. |
876 var resolved = $objectDefineProperties({}, { | 884 var resolved = ObjectDefineProperties({}, { |
877 caseFirst: {writable: true}, | 885 caseFirst: {writable: true}, |
878 collation: {value: internalOptions.collation, writable: true}, | 886 collation: {value: internalOptions.collation, writable: true}, |
879 ignorePunctuation: {writable: true}, | 887 ignorePunctuation: {writable: true}, |
880 locale: {writable: true}, | 888 locale: {writable: true}, |
881 numeric: {writable: true}, | 889 numeric: {writable: true}, |
882 requestedLocale: {value: requestedLocale, writable: true}, | 890 requestedLocale: {value: requestedLocale, writable: true}, |
883 sensitivity: {writable: true}, | 891 sensitivity: {writable: true}, |
884 strength: {writable: true}, | 892 strength: {writable: true}, |
885 usage: {value: internalOptions.usage, writable: true} | 893 usage: {value: internalOptions.usage, writable: true} |
886 }); | 894 }); |
887 | 895 |
888 var internalCollator = %CreateCollator(requestedLocale, | 896 var internalCollator = %CreateCollator(requestedLocale, |
889 internalOptions, | 897 internalOptions, |
890 resolved); | 898 resolved); |
891 | 899 |
892 // Writable, configurable and enumerable are set to false by default. | 900 // Writable, configurable and enumerable are set to false by default. |
893 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); | 901 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); |
894 $objectDefineProperty(collator, 'resolved', {value: resolved}); | 902 ObjectDefineProperty(collator, 'resolved', {value: resolved}); |
895 | 903 |
896 return collator; | 904 return collator; |
897 } | 905 } |
898 | 906 |
899 | 907 |
900 /** | 908 /** |
901 * Constructs Intl.Collator object given optional locales and options | 909 * Constructs Intl.Collator object given optional locales and options |
902 * parameters. | 910 * parameters. |
903 * | 911 * |
904 * @constructor | 912 * @constructor |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 usage: coll.resolved.usage, | 947 usage: coll.resolved.usage, |
940 sensitivity: coll.resolved.sensitivity, | 948 sensitivity: coll.resolved.sensitivity, |
941 ignorePunctuation: coll.resolved.ignorePunctuation, | 949 ignorePunctuation: coll.resolved.ignorePunctuation, |
942 numeric: coll.resolved.numeric, | 950 numeric: coll.resolved.numeric, |
943 caseFirst: coll.resolved.caseFirst, | 951 caseFirst: coll.resolved.caseFirst, |
944 collation: coll.resolved.collation | 952 collation: coll.resolved.collation |
945 }; | 953 }; |
946 }, | 954 }, |
947 DONT_ENUM | 955 DONT_ENUM |
948 ); | 956 ); |
949 $setFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); | 957 SetFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); |
950 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); | 958 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); |
951 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); | 959 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); |
952 | 960 |
953 | 961 |
954 /** | 962 /** |
955 * Returns the subset of the given locale list for which this locale list | 963 * Returns the subset of the given locale list for which this locale list |
956 * has a matching (possibly fallback) locale. Locales appear in the same | 964 * has a matching (possibly fallback) locale. Locales appear in the same |
957 * order in the returned list as in the input list. | 965 * order in the returned list as in the input list. |
958 * Options are optional parameter. | 966 * Options are optional parameter. |
959 */ | 967 */ |
960 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { | 968 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { |
961 if (%_IsConstructCall()) { | 969 if (%_IsConstructCall()) { |
962 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 970 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
963 } | 971 } |
964 | 972 |
965 return supportedLocalesOf('collator', locales, %_Arguments(1)); | 973 return supportedLocalesOf('collator', locales, %_Arguments(1)); |
966 }, | 974 }, |
967 DONT_ENUM | 975 DONT_ENUM |
968 ); | 976 ); |
969 $setFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); | 977 SetFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); |
970 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); | 978 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); |
971 %SetNativeFlag(Intl.Collator.supportedLocalesOf); | 979 %SetNativeFlag(Intl.Collator.supportedLocalesOf); |
972 | 980 |
973 | 981 |
974 /** | 982 /** |
975 * When the compare method is called with two arguments x and y, it returns a | 983 * When the compare method is called with two arguments x and y, it returns a |
976 * Number other than NaN that represents the result of a locale-sensitive | 984 * Number other than NaN that represents the result of a locale-sensitive |
977 * String comparison of x with y. | 985 * String comparison of x with y. |
978 * The result is intended to order String values in the sort order specified | 986 * The result is intended to order String values in the sort order specified |
979 * by the effective locale and collation options computed during construction | 987 * by the effective locale and collation options computed during construction |
(...skipping 22 matching lines...) Expand all Loading... |
1002 | 1010 |
1003 | 1011 |
1004 /** | 1012 /** |
1005 * Returns the valid digit count for a property, or throws RangeError on | 1013 * Returns the valid digit count for a property, or throws RangeError on |
1006 * a value out of the range. | 1014 * a value out of the range. |
1007 */ | 1015 */ |
1008 function getNumberOption(options, property, min, max, fallback) { | 1016 function getNumberOption(options, property, min, max, fallback) { |
1009 var value = options[property]; | 1017 var value = options[property]; |
1010 if (!IS_UNDEFINED(value)) { | 1018 if (!IS_UNDEFINED(value)) { |
1011 value = GlobalNumber(value); | 1019 value = GlobalNumber(value); |
1012 if ($isNaN(value) || value < min || value > max) { | 1020 if (IsNaN(value) || value < min || value > max) { |
1013 throw MakeRangeError(kPropertyValueOutOfRange, property); | 1021 throw MakeRangeError(kPropertyValueOutOfRange, property); |
1014 } | 1022 } |
1015 return MathFloor(value); | 1023 return MathFloor(value); |
1016 } | 1024 } |
1017 | 1025 |
1018 return fallback; | 1026 return fallback; |
1019 } | 1027 } |
1020 | 1028 |
1021 | 1029 |
1022 /** | 1030 /** |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 * for a number format. | 1097 * for a number format. |
1090 */ | 1098 */ |
1091 var NUMBER_FORMAT_KEY_MAP = { | 1099 var NUMBER_FORMAT_KEY_MAP = { |
1092 'nu': {'property': UNDEFINED, 'type': 'string'} | 1100 'nu': {'property': UNDEFINED, 'type': 'string'} |
1093 }; | 1101 }; |
1094 | 1102 |
1095 var extension = setOptions(options, extensionMap, NUMBER_FORMAT_KEY_MAP, | 1103 var extension = setOptions(options, extensionMap, NUMBER_FORMAT_KEY_MAP, |
1096 getOption, internalOptions); | 1104 getOption, internalOptions); |
1097 | 1105 |
1098 var requestedLocale = locale.locale + extension; | 1106 var requestedLocale = locale.locale + extension; |
1099 var resolved = $objectDefineProperties({}, { | 1107 var resolved = ObjectDefineProperties({}, { |
1100 currency: {writable: true}, | 1108 currency: {writable: true}, |
1101 currencyDisplay: {writable: true}, | 1109 currencyDisplay: {writable: true}, |
1102 locale: {writable: true}, | 1110 locale: {writable: true}, |
1103 maximumFractionDigits: {writable: true}, | 1111 maximumFractionDigits: {writable: true}, |
1104 minimumFractionDigits: {writable: true}, | 1112 minimumFractionDigits: {writable: true}, |
1105 minimumIntegerDigits: {writable: true}, | 1113 minimumIntegerDigits: {writable: true}, |
1106 numberingSystem: {writable: true}, | 1114 numberingSystem: {writable: true}, |
1107 requestedLocale: {value: requestedLocale, writable: true}, | 1115 requestedLocale: {value: requestedLocale, writable: true}, |
1108 style: {value: internalOptions.style, writable: true}, | 1116 style: {value: internalOptions.style, writable: true}, |
1109 useGrouping: {writable: true} | 1117 useGrouping: {writable: true} |
1110 }); | 1118 }); |
1111 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) { | 1119 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) { |
1112 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); | 1120 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); |
1113 } | 1121 } |
1114 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) { | 1122 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) { |
1115 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); | 1123 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); |
1116 } | 1124 } |
1117 var formatter = %CreateNumberFormat(requestedLocale, | 1125 var formatter = %CreateNumberFormat(requestedLocale, |
1118 internalOptions, | 1126 internalOptions, |
1119 resolved); | 1127 resolved); |
1120 | 1128 |
1121 // We can't get information about number or currency style from ICU, so we | 1129 // We can't get information about number or currency style from ICU, so we |
1122 // assume user request was fulfilled. | 1130 // assume user request was fulfilled. |
1123 if (internalOptions.style === 'currency') { | 1131 if (internalOptions.style === 'currency') { |
1124 $objectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, | 1132 ObjectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, |
1125 writable: true}); | 1133 writable: true}); |
1126 } | 1134 } |
1127 | 1135 |
1128 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); | 1136 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); |
1129 $objectDefineProperty(numberFormat, 'resolved', {value: resolved}); | 1137 ObjectDefineProperty(numberFormat, 'resolved', {value: resolved}); |
1130 | 1138 |
1131 return numberFormat; | 1139 return numberFormat; |
1132 } | 1140 } |
1133 | 1141 |
1134 | 1142 |
1135 /** | 1143 /** |
1136 * Constructs Intl.NumberFormat object given optional locales and options | 1144 * Constructs Intl.NumberFormat object given optional locales and options |
1137 * parameters. | 1145 * parameters. |
1138 * | 1146 * |
1139 * @constructor | 1147 * @constructor |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 | 1200 |
1193 if (format.resolved.hasOwnProperty('maximumSignificantDigits')) { | 1201 if (format.resolved.hasOwnProperty('maximumSignificantDigits')) { |
1194 defineWECProperty(result, 'maximumSignificantDigits', | 1202 defineWECProperty(result, 'maximumSignificantDigits', |
1195 format.resolved.maximumSignificantDigits); | 1203 format.resolved.maximumSignificantDigits); |
1196 } | 1204 } |
1197 | 1205 |
1198 return result; | 1206 return result; |
1199 }, | 1207 }, |
1200 DONT_ENUM | 1208 DONT_ENUM |
1201 ); | 1209 ); |
1202 $setFunctionName(Intl.NumberFormat.prototype.resolvedOptions, | 1210 SetFunctionName(Intl.NumberFormat.prototype.resolvedOptions, 'resolvedOptions'); |
1203 'resolvedOptions'); | |
1204 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); | 1211 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); |
1205 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); | 1212 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); |
1206 | 1213 |
1207 | 1214 |
1208 /** | 1215 /** |
1209 * Returns the subset of the given locale list for which this locale list | 1216 * Returns the subset of the given locale list for which this locale list |
1210 * has a matching (possibly fallback) locale. Locales appear in the same | 1217 * has a matching (possibly fallback) locale. Locales appear in the same |
1211 * order in the returned list as in the input list. | 1218 * order in the returned list as in the input list. |
1212 * Options are optional parameter. | 1219 * Options are optional parameter. |
1213 */ | 1220 */ |
1214 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { | 1221 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { |
1215 if (%_IsConstructCall()) { | 1222 if (%_IsConstructCall()) { |
1216 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1223 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1217 } | 1224 } |
1218 | 1225 |
1219 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); | 1226 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); |
1220 }, | 1227 }, |
1221 DONT_ENUM | 1228 DONT_ENUM |
1222 ); | 1229 ); |
1223 $setFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); | 1230 SetFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); |
1224 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); | 1231 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); |
1225 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); | 1232 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
1226 | 1233 |
1227 | 1234 |
1228 /** | 1235 /** |
1229 * Returns a String value representing the result of calling ToNumber(value) | 1236 * Returns a String value representing the result of calling ToNumber(value) |
1230 * according to the effective locale and the formatting options of this | 1237 * according to the effective locale and the formatting options of this |
1231 * NumberFormat. | 1238 * NumberFormat. |
1232 */ | 1239 */ |
1233 function formatNumber(formatter, value) { | 1240 function formatNumber(formatter, value) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 needsDefault = false; | 1416 needsDefault = false; |
1410 } | 1417 } |
1411 | 1418 |
1412 if ((required === 'time' || required === 'any') && | 1419 if ((required === 'time' || required === 'any') && |
1413 (!IS_UNDEFINED(options.hour) || !IS_UNDEFINED(options.minute) || | 1420 (!IS_UNDEFINED(options.hour) || !IS_UNDEFINED(options.minute) || |
1414 !IS_UNDEFINED(options.second))) { | 1421 !IS_UNDEFINED(options.second))) { |
1415 needsDefault = false; | 1422 needsDefault = false; |
1416 } | 1423 } |
1417 | 1424 |
1418 if (needsDefault && (defaults === 'date' || defaults === 'all')) { | 1425 if (needsDefault && (defaults === 'date' || defaults === 'all')) { |
1419 $objectDefineProperty(options, 'year', {value: 'numeric', | 1426 ObjectDefineProperty(options, 'year', {value: 'numeric', |
| 1427 writable: true, |
| 1428 enumerable: true, |
| 1429 configurable: true}); |
| 1430 ObjectDefineProperty(options, 'month', {value: 'numeric', |
1420 writable: true, | 1431 writable: true, |
1421 enumerable: true, | 1432 enumerable: true, |
1422 configurable: true}); | 1433 configurable: true}); |
1423 $objectDefineProperty(options, 'month', {value: 'numeric', | 1434 ObjectDefineProperty(options, 'day', {value: 'numeric', |
| 1435 writable: true, |
| 1436 enumerable: true, |
| 1437 configurable: true}); |
| 1438 } |
| 1439 |
| 1440 if (needsDefault && (defaults === 'time' || defaults === 'all')) { |
| 1441 ObjectDefineProperty(options, 'hour', {value: 'numeric', |
| 1442 writable: true, |
| 1443 enumerable: true, |
| 1444 configurable: true}); |
| 1445 ObjectDefineProperty(options, 'minute', {value: 'numeric', |
1424 writable: true, | 1446 writable: true, |
1425 enumerable: true, | 1447 enumerable: true, |
1426 configurable: true}); | 1448 configurable: true}); |
1427 $objectDefineProperty(options, 'day', {value: 'numeric', | 1449 ObjectDefineProperty(options, 'second', {value: 'numeric', |
1428 writable: true, | 1450 writable: true, |
1429 enumerable: true, | 1451 enumerable: true, |
1430 configurable: true}); | 1452 configurable: true}); |
1431 } | |
1432 | |
1433 if (needsDefault && (defaults === 'time' || defaults === 'all')) { | |
1434 $objectDefineProperty(options, 'hour', {value: 'numeric', | |
1435 writable: true, | |
1436 enumerable: true, | |
1437 configurable: true}); | |
1438 $objectDefineProperty(options, 'minute', {value: 'numeric', | |
1439 writable: true, | |
1440 enumerable: true, | |
1441 configurable: true}); | |
1442 $objectDefineProperty(options, 'second', {value: 'numeric', | |
1443 writable: true, | |
1444 enumerable: true, | |
1445 configurable: true}); | |
1446 } | 1453 } |
1447 | 1454 |
1448 return options; | 1455 return options; |
1449 } | 1456 } |
1450 | 1457 |
1451 | 1458 |
1452 /** | 1459 /** |
1453 * Initializes the given object so it's a valid DateTimeFormat instance. | 1460 * Initializes the given object so it's a valid DateTimeFormat instance. |
1454 * Useful for subclassing. | 1461 * Useful for subclassing. |
1455 */ | 1462 */ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 */ | 1500 */ |
1494 var DATETIME_FORMAT_KEY_MAP = { | 1501 var DATETIME_FORMAT_KEY_MAP = { |
1495 'ca': {'property': UNDEFINED, 'type': 'string'}, | 1502 'ca': {'property': UNDEFINED, 'type': 'string'}, |
1496 'nu': {'property': UNDEFINED, 'type': 'string'} | 1503 'nu': {'property': UNDEFINED, 'type': 'string'} |
1497 }; | 1504 }; |
1498 | 1505 |
1499 var extension = setOptions(options, extensionMap, DATETIME_FORMAT_KEY_MAP, | 1506 var extension = setOptions(options, extensionMap, DATETIME_FORMAT_KEY_MAP, |
1500 getOption, internalOptions); | 1507 getOption, internalOptions); |
1501 | 1508 |
1502 var requestedLocale = locale.locale + extension; | 1509 var requestedLocale = locale.locale + extension; |
1503 var resolved = $objectDefineProperties({}, { | 1510 var resolved = ObjectDefineProperties({}, { |
1504 calendar: {writable: true}, | 1511 calendar: {writable: true}, |
1505 day: {writable: true}, | 1512 day: {writable: true}, |
1506 era: {writable: true}, | 1513 era: {writable: true}, |
1507 hour12: {writable: true}, | 1514 hour12: {writable: true}, |
1508 hour: {writable: true}, | 1515 hour: {writable: true}, |
1509 locale: {writable: true}, | 1516 locale: {writable: true}, |
1510 minute: {writable: true}, | 1517 minute: {writable: true}, |
1511 month: {writable: true}, | 1518 month: {writable: true}, |
1512 numberingSystem: {writable: true}, | 1519 numberingSystem: {writable: true}, |
1513 pattern: {writable: true}, | 1520 pattern: {writable: true}, |
1514 requestedLocale: {value: requestedLocale, writable: true}, | 1521 requestedLocale: {value: requestedLocale, writable: true}, |
1515 second: {writable: true}, | 1522 second: {writable: true}, |
1516 timeZone: {writable: true}, | 1523 timeZone: {writable: true}, |
1517 timeZoneName: {writable: true}, | 1524 timeZoneName: {writable: true}, |
1518 tz: {value: tz, writable: true}, | 1525 tz: {value: tz, writable: true}, |
1519 weekday: {writable: true}, | 1526 weekday: {writable: true}, |
1520 year: {writable: true} | 1527 year: {writable: true} |
1521 }); | 1528 }); |
1522 | 1529 |
1523 var formatter = %CreateDateTimeFormat( | 1530 var formatter = %CreateDateTimeFormat( |
1524 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); | 1531 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); |
1525 | 1532 |
1526 if (!IS_UNDEFINED(tz) && tz !== resolved.timeZone) { | 1533 if (!IS_UNDEFINED(tz) && tz !== resolved.timeZone) { |
1527 throw MakeRangeError(kUnsupportedTimeZone, tz); | 1534 throw MakeRangeError(kUnsupportedTimeZone, tz); |
1528 } | 1535 } |
1529 | 1536 |
1530 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); | 1537 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); |
1531 $objectDefineProperty(dateFormat, 'resolved', {value: resolved}); | 1538 ObjectDefineProperty(dateFormat, 'resolved', {value: resolved}); |
1532 | 1539 |
1533 return dateFormat; | 1540 return dateFormat; |
1534 } | 1541 } |
1535 | 1542 |
1536 | 1543 |
1537 /** | 1544 /** |
1538 * Constructs Intl.DateTimeFormat object given optional locales and options | 1545 * Constructs Intl.DateTimeFormat object given optional locales and options |
1539 * parameters. | 1546 * parameters. |
1540 * | 1547 * |
1541 * @constructor | 1548 * @constructor |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1613 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); | 1620 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); |
1614 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); | 1621 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); |
1615 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); | 1622 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); |
1616 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); | 1623 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); |
1617 addWECPropertyIfDefined(result, 'second', fromPattern.second); | 1624 addWECPropertyIfDefined(result, 'second', fromPattern.second); |
1618 | 1625 |
1619 return result; | 1626 return result; |
1620 }, | 1627 }, |
1621 DONT_ENUM | 1628 DONT_ENUM |
1622 ); | 1629 ); |
1623 $setFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, | 1630 SetFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, |
1624 'resolvedOptions'); | 1631 'resolvedOptions'); |
1625 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); | 1632 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); |
1626 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); | 1633 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); |
1627 | 1634 |
1628 | 1635 |
1629 /** | 1636 /** |
1630 * Returns the subset of the given locale list for which this locale list | 1637 * Returns the subset of the given locale list for which this locale list |
1631 * has a matching (possibly fallback) locale. Locales appear in the same | 1638 * has a matching (possibly fallback) locale. Locales appear in the same |
1632 * order in the returned list as in the input list. | 1639 * order in the returned list as in the input list. |
1633 * Options are optional parameter. | 1640 * Options are optional parameter. |
1634 */ | 1641 */ |
1635 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { | 1642 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { |
1636 if (%_IsConstructCall()) { | 1643 if (%_IsConstructCall()) { |
1637 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1644 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1638 } | 1645 } |
1639 | 1646 |
1640 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); | 1647 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); |
1641 }, | 1648 }, |
1642 DONT_ENUM | 1649 DONT_ENUM |
1643 ); | 1650 ); |
1644 $setFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); | 1651 SetFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); |
1645 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); | 1652 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); |
1646 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); | 1653 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); |
1647 | 1654 |
1648 | 1655 |
1649 /** | 1656 /** |
1650 * Returns a String value representing the result of calling ToNumber(date) | 1657 * Returns a String value representing the result of calling ToNumber(date) |
1651 * according to the effective locale and the formatting options of this | 1658 * according to the effective locale and the formatting options of this |
1652 * DateTimeFormat. | 1659 * DateTimeFormat. |
1653 */ | 1660 */ |
1654 function formatDate(formatter, dateValue) { | 1661 function formatDate(formatter, dateValue) { |
1655 var dateMs; | 1662 var dateMs; |
1656 if (IS_UNDEFINED(dateValue)) { | 1663 if (IS_UNDEFINED(dateValue)) { |
1657 dateMs = GlobalDate.now(); | 1664 dateMs = GlobalDate.now(); |
1658 } else { | 1665 } else { |
1659 dateMs = $toNumber(dateValue); | 1666 dateMs = $toNumber(dateValue); |
1660 } | 1667 } |
1661 | 1668 |
1662 if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange); | 1669 if (!IsFinite(dateMs)) throw MakeRangeError(kDateRange); |
1663 | 1670 |
1664 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), | 1671 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), |
1665 new GlobalDate(dateMs)); | 1672 new GlobalDate(dateMs)); |
1666 } | 1673 } |
1667 | 1674 |
1668 | 1675 |
1669 /** | 1676 /** |
1670 * Returns a Date object representing the result of calling ToString(value) | 1677 * Returns a Date object representing the result of calling ToString(value) |
1671 * according to the effective locale and the formatting options of this | 1678 * according to the effective locale and the formatting options of this |
1672 * DateTimeFormat. | 1679 * DateTimeFormat. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 } | 1736 } |
1730 | 1737 |
1731 var getOption = getGetOption(options, 'breakiterator'); | 1738 var getOption = getGetOption(options, 'breakiterator'); |
1732 | 1739 |
1733 var internalOptions = {}; | 1740 var internalOptions = {}; |
1734 | 1741 |
1735 defineWEProperty(internalOptions, 'type', getOption( | 1742 defineWEProperty(internalOptions, 'type', getOption( |
1736 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); | 1743 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); |
1737 | 1744 |
1738 var locale = resolveLocale('breakiterator', locales, options); | 1745 var locale = resolveLocale('breakiterator', locales, options); |
1739 var resolved = $objectDefineProperties({}, { | 1746 var resolved = ObjectDefineProperties({}, { |
1740 requestedLocale: {value: locale.locale, writable: true}, | 1747 requestedLocale: {value: locale.locale, writable: true}, |
1741 type: {value: internalOptions.type, writable: true}, | 1748 type: {value: internalOptions.type, writable: true}, |
1742 locale: {writable: true} | 1749 locale: {writable: true} |
1743 }); | 1750 }); |
1744 | 1751 |
1745 var internalIterator = %CreateBreakIterator(locale.locale, | 1752 var internalIterator = %CreateBreakIterator(locale.locale, |
1746 internalOptions, | 1753 internalOptions, |
1747 resolved); | 1754 resolved); |
1748 | 1755 |
1749 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', | 1756 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', |
1750 internalIterator); | 1757 internalIterator); |
1751 $objectDefineProperty(iterator, 'resolved', {value: resolved}); | 1758 ObjectDefineProperty(iterator, 'resolved', {value: resolved}); |
1752 | 1759 |
1753 return iterator; | 1760 return iterator; |
1754 } | 1761 } |
1755 | 1762 |
1756 | 1763 |
1757 /** | 1764 /** |
1758 * Constructs Intl.v8BreakIterator object given optional locales and options | 1765 * Constructs Intl.v8BreakIterator object given optional locales and options |
1759 * parameters. | 1766 * parameters. |
1760 * | 1767 * |
1761 * @constructor | 1768 * @constructor |
(...skipping 30 matching lines...) Expand all Loading... |
1792 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, | 1799 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, |
1793 segmenter.resolved.locale); | 1800 segmenter.resolved.locale); |
1794 | 1801 |
1795 return { | 1802 return { |
1796 locale: locale, | 1803 locale: locale, |
1797 type: segmenter.resolved.type | 1804 type: segmenter.resolved.type |
1798 }; | 1805 }; |
1799 }, | 1806 }, |
1800 DONT_ENUM | 1807 DONT_ENUM |
1801 ); | 1808 ); |
1802 $setFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, | 1809 SetFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, |
1803 'resolvedOptions'); | 1810 'resolvedOptions'); |
1804 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); | 1811 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); |
1805 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); | 1812 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); |
1806 | 1813 |
1807 | 1814 |
1808 /** | 1815 /** |
1809 * Returns the subset of the given locale list for which this locale list | 1816 * Returns the subset of the given locale list for which this locale list |
1810 * has a matching (possibly fallback) locale. Locales appear in the same | 1817 * has a matching (possibly fallback) locale. Locales appear in the same |
1811 * order in the returned list as in the input list. | 1818 * order in the returned list as in the input list. |
1812 * Options are optional parameter. | 1819 * Options are optional parameter. |
1813 */ | 1820 */ |
1814 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', | 1821 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', |
1815 function(locales) { | 1822 function(locales) { |
1816 if (%_IsConstructCall()) { | 1823 if (%_IsConstructCall()) { |
1817 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1824 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1818 } | 1825 } |
1819 | 1826 |
1820 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); | 1827 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); |
1821 }, | 1828 }, |
1822 DONT_ENUM | 1829 DONT_ENUM |
1823 ); | 1830 ); |
1824 $setFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); | 1831 SetFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
1825 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); | 1832 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
1826 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); | 1833 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
1827 | 1834 |
1828 | 1835 |
1829 /** | 1836 /** |
1830 * Adopts text to segment using the iterator. Old text, if present, | 1837 * Adopts text to segment using the iterator. Old text, if present, |
1831 * gets discarded. | 1838 * gets discarded. |
1832 */ | 1839 */ |
1833 function adoptText(iterator, text) { | 1840 function adoptText(iterator, text) { |
1834 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), | 1841 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) { | 1911 if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) { |
1905 if (IS_UNDEFINED(defaultObjects[service])) { | 1912 if (IS_UNDEFINED(defaultObjects[service])) { |
1906 defaultObjects[service] = new savedObjects[service](locales, useOptions); | 1913 defaultObjects[service] = new savedObjects[service](locales, useOptions); |
1907 } | 1914 } |
1908 return defaultObjects[service]; | 1915 return defaultObjects[service]; |
1909 } | 1916 } |
1910 return new savedObjects[service](locales, useOptions); | 1917 return new savedObjects[service](locales, useOptions); |
1911 } | 1918 } |
1912 | 1919 |
1913 | 1920 |
| 1921 function OverrideFunction(object, name, f) { |
| 1922 %CheckIsBootstrapping(); |
| 1923 ObjectDefineProperty(object, name, { value: f, |
| 1924 writeable: true, |
| 1925 configurable: true, |
| 1926 enumerable: false }); |
| 1927 SetFunctionName(f, name); |
| 1928 %FunctionRemovePrototype(f); |
| 1929 %SetNativeFlag(f); |
| 1930 } |
| 1931 |
1914 /** | 1932 /** |
1915 * Compares this and that, and returns less than 0, 0 or greater than 0 value. | 1933 * Compares this and that, and returns less than 0, 0 or greater than 0 value. |
1916 * Overrides the built-in method. | 1934 * Overrides the built-in method. |
1917 */ | 1935 */ |
1918 $overrideFunction(GlobalString.prototype, 'localeCompare', function(that) { | 1936 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { |
1919 if (%_IsConstructCall()) { | 1937 if (%_IsConstructCall()) { |
1920 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1938 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1921 } | 1939 } |
1922 | 1940 |
1923 if (IS_NULL_OR_UNDEFINED(this)) { | 1941 if (IS_NULL_OR_UNDEFINED(this)) { |
1924 throw MakeTypeError(kMethodInvokedOnNullOrUndefined); | 1942 throw MakeTypeError(kMethodInvokedOnNullOrUndefined); |
1925 } | 1943 } |
1926 | 1944 |
1927 var locales = %_Arguments(1); | 1945 var locales = %_Arguments(1); |
1928 var options = %_Arguments(2); | 1946 var options = %_Arguments(2); |
1929 var collator = cachedOrNewService('collator', locales, options); | 1947 var collator = cachedOrNewService('collator', locales, options); |
1930 return compare(collator, this, that); | 1948 return compare(collator, this, that); |
1931 } | 1949 } |
1932 ); | 1950 ); |
1933 | 1951 |
1934 | 1952 |
1935 /** | 1953 /** |
1936 * Unicode normalization. This method is called with one argument that | 1954 * Unicode normalization. This method is called with one argument that |
1937 * specifies the normalization form. | 1955 * specifies the normalization form. |
1938 * If none is specified, "NFC" is assumed. | 1956 * If none is specified, "NFC" is assumed. |
1939 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw | 1957 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw |
1940 * a RangeError Exception. | 1958 * a RangeError Exception. |
1941 */ | 1959 */ |
1942 $overrideFunction(GlobalString.prototype, 'normalize', function(that) { | 1960 OverrideFunction(GlobalString.prototype, 'normalize', function(that) { |
1943 if (%_IsConstructCall()) { | 1961 if (%_IsConstructCall()) { |
1944 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1962 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1945 } | 1963 } |
1946 | 1964 |
1947 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); | 1965 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); |
1948 | 1966 |
1949 var form = GlobalString(%_Arguments(0) || 'NFC'); | 1967 var form = GlobalString(%_Arguments(0) || 'NFC'); |
1950 | 1968 |
1951 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; | 1969 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; |
1952 | 1970 |
1953 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); | 1971 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); |
1954 if (normalizationForm === -1) { | 1972 if (normalizationForm === -1) { |
1955 throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', ')); | 1973 throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', ')); |
1956 } | 1974 } |
1957 | 1975 |
1958 return %StringNormalize(this, normalizationForm); | 1976 return %StringNormalize(this, normalizationForm); |
1959 } | 1977 } |
1960 ); | 1978 ); |
1961 | 1979 |
1962 | 1980 |
1963 /** | 1981 /** |
1964 * Formats a Number object (this) using locale and options values. | 1982 * Formats a Number object (this) using locale and options values. |
1965 * If locale or options are omitted, defaults are used. | 1983 * If locale or options are omitted, defaults are used. |
1966 */ | 1984 */ |
1967 $overrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { | 1985 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
1968 if (%_IsConstructCall()) { | 1986 if (%_IsConstructCall()) { |
1969 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1987 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1970 } | 1988 } |
1971 | 1989 |
1972 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { | 1990 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { |
1973 throw MakeTypeError(kMethodInvokedOnWrongType, "Number"); | 1991 throw MakeTypeError(kMethodInvokedOnWrongType, "Number"); |
1974 } | 1992 } |
1975 | 1993 |
1976 var locales = %_Arguments(0); | 1994 var locales = %_Arguments(0); |
1977 var options = %_Arguments(1); | 1995 var options = %_Arguments(1); |
1978 var numberFormat = cachedOrNewService('numberformat', locales, options); | 1996 var numberFormat = cachedOrNewService('numberformat', locales, options); |
1979 return formatNumber(numberFormat, this); | 1997 return formatNumber(numberFormat, this); |
1980 } | 1998 } |
1981 ); | 1999 ); |
1982 | 2000 |
1983 | 2001 |
1984 /** | 2002 /** |
1985 * Returns actual formatted date or fails if date parameter is invalid. | 2003 * Returns actual formatted date or fails if date parameter is invalid. |
1986 */ | 2004 */ |
1987 function toLocaleDateTime(date, locales, options, required, defaults, service) { | 2005 function toLocaleDateTime(date, locales, options, required, defaults, service) { |
1988 if (!(date instanceof GlobalDate)) { | 2006 if (!(date instanceof GlobalDate)) { |
1989 throw MakeTypeError(kMethodInvokedOnWrongType, "Date"); | 2007 throw MakeTypeError(kMethodInvokedOnWrongType, "Date"); |
1990 } | 2008 } |
1991 | 2009 |
1992 if ($isNaN(date)) { | 2010 if (IsNaN(date)) return 'Invalid Date'; |
1993 return 'Invalid Date'; | |
1994 } | |
1995 | 2011 |
1996 var internalOptions = toDateTimeOptions(options, required, defaults); | 2012 var internalOptions = toDateTimeOptions(options, required, defaults); |
1997 | 2013 |
1998 var dateFormat = | 2014 var dateFormat = |
1999 cachedOrNewService(service, locales, options, internalOptions); | 2015 cachedOrNewService(service, locales, options, internalOptions); |
2000 | 2016 |
2001 return formatDate(dateFormat, date); | 2017 return formatDate(dateFormat, date); |
2002 } | 2018 } |
2003 | 2019 |
2004 | 2020 |
2005 /** | 2021 /** |
2006 * Formats a Date object (this) using locale and options values. | 2022 * Formats a Date object (this) using locale and options values. |
2007 * If locale or options are omitted, defaults are used - both date and time are | 2023 * If locale or options are omitted, defaults are used - both date and time are |
2008 * present in the output. | 2024 * present in the output. |
2009 */ | 2025 */ |
2010 $overrideFunction(GlobalDate.prototype, 'toLocaleString', function() { | 2026 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { |
2011 if (%_IsConstructCall()) { | 2027 if (%_IsConstructCall()) { |
2012 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2028 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2013 } | 2029 } |
2014 | 2030 |
2015 var locales = %_Arguments(0); | 2031 var locales = %_Arguments(0); |
2016 var options = %_Arguments(1); | 2032 var options = %_Arguments(1); |
2017 return toLocaleDateTime( | 2033 return toLocaleDateTime( |
2018 this, locales, options, 'any', 'all', 'dateformatall'); | 2034 this, locales, options, 'any', 'all', 'dateformatall'); |
2019 } | 2035 } |
2020 ); | 2036 ); |
2021 | 2037 |
2022 | 2038 |
2023 /** | 2039 /** |
2024 * Formats a Date object (this) using locale and options values. | 2040 * Formats a Date object (this) using locale and options values. |
2025 * If locale or options are omitted, defaults are used - only date is present | 2041 * If locale or options are omitted, defaults are used - only date is present |
2026 * in the output. | 2042 * in the output. |
2027 */ | 2043 */ |
2028 $overrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { | 2044 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { |
2029 if (%_IsConstructCall()) { | 2045 if (%_IsConstructCall()) { |
2030 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2046 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2031 } | 2047 } |
2032 | 2048 |
2033 var locales = %_Arguments(0); | 2049 var locales = %_Arguments(0); |
2034 var options = %_Arguments(1); | 2050 var options = %_Arguments(1); |
2035 return toLocaleDateTime( | 2051 return toLocaleDateTime( |
2036 this, locales, options, 'date', 'date', 'dateformatdate'); | 2052 this, locales, options, 'date', 'date', 'dateformatdate'); |
2037 } | 2053 } |
2038 ); | 2054 ); |
2039 | 2055 |
2040 | 2056 |
2041 /** | 2057 /** |
2042 * Formats a Date object (this) using locale and options values. | 2058 * Formats a Date object (this) using locale and options values. |
2043 * If locale or options are omitted, defaults are used - only time is present | 2059 * If locale or options are omitted, defaults are used - only time is present |
2044 * in the output. | 2060 * in the output. |
2045 */ | 2061 */ |
2046 $overrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { | 2062 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { |
2047 if (%_IsConstructCall()) { | 2063 if (%_IsConstructCall()) { |
2048 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2064 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2049 } | 2065 } |
2050 | 2066 |
2051 var locales = %_Arguments(0); | 2067 var locales = %_Arguments(0); |
2052 var options = %_Arguments(1); | 2068 var options = %_Arguments(1); |
2053 return toLocaleDateTime( | 2069 return toLocaleDateTime( |
2054 this, locales, options, 'time', 'time', 'dateformattime'); | 2070 this, locales, options, 'time', 'time', 'dateformattime'); |
2055 } | 2071 } |
2056 ); | 2072 ); |
2057 | 2073 |
2058 }) | 2074 }) |
OLD | NEW |