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, |
Jakob Kummerow
2015/05/21 13:45:24
nit: should still fit on one line
| |
958 'resolvedOptions'); | |
950 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); | 959 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); |
951 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); | 960 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); |
952 | 961 |
953 | 962 |
954 /** | 963 /** |
955 * Returns the subset of the given locale list for which this locale list | 964 * 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 | 965 * has a matching (possibly fallback) locale. Locales appear in the same |
957 * order in the returned list as in the input list. | 966 * order in the returned list as in the input list. |
958 * Options are optional parameter. | 967 * Options are optional parameter. |
959 */ | 968 */ |
960 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { | 969 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { |
961 if (%_IsConstructCall()) { | 970 if (%_IsConstructCall()) { |
962 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 971 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
963 } | 972 } |
964 | 973 |
965 return supportedLocalesOf('collator', locales, %_Arguments(1)); | 974 return supportedLocalesOf('collator', locales, %_Arguments(1)); |
966 }, | 975 }, |
967 DONT_ENUM | 976 DONT_ENUM |
968 ); | 977 ); |
969 $setFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); | 978 SetFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); |
970 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); | 979 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); |
971 %SetNativeFlag(Intl.Collator.supportedLocalesOf); | 980 %SetNativeFlag(Intl.Collator.supportedLocalesOf); |
972 | 981 |
973 | 982 |
974 /** | 983 /** |
975 * When the compare method is called with two arguments x and y, it returns a | 984 * 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 | 985 * Number other than NaN that represents the result of a locale-sensitive |
977 * String comparison of x with y. | 986 * String comparison of x with y. |
978 * The result is intended to order String values in the sort order specified | 987 * The result is intended to order String values in the sort order specified |
979 * by the effective locale and collation options computed during construction | 988 * by the effective locale and collation options computed during construction |
(...skipping 22 matching lines...) Expand all Loading... | |
1002 | 1011 |
1003 | 1012 |
1004 /** | 1013 /** |
1005 * Returns the valid digit count for a property, or throws RangeError on | 1014 * Returns the valid digit count for a property, or throws RangeError on |
1006 * a value out of the range. | 1015 * a value out of the range. |
1007 */ | 1016 */ |
1008 function getNumberOption(options, property, min, max, fallback) { | 1017 function getNumberOption(options, property, min, max, fallback) { |
1009 var value = options[property]; | 1018 var value = options[property]; |
1010 if (!IS_UNDEFINED(value)) { | 1019 if (!IS_UNDEFINED(value)) { |
1011 value = GlobalNumber(value); | 1020 value = GlobalNumber(value); |
1012 if ($isNaN(value) || value < min || value > max) { | 1021 if (IsNaN(value) || value < min || value > max) { |
1013 throw MakeRangeError(kPropertyValueOutOfRange, property); | 1022 throw MakeRangeError(kPropertyValueOutOfRange, property); |
1014 } | 1023 } |
1015 return MathFloor(value); | 1024 return MathFloor(value); |
1016 } | 1025 } |
1017 | 1026 |
1018 return fallback; | 1027 return fallback; |
1019 } | 1028 } |
1020 | 1029 |
1021 | 1030 |
1022 /** | 1031 /** |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1089 * for a number format. | 1098 * for a number format. |
1090 */ | 1099 */ |
1091 var NUMBER_FORMAT_KEY_MAP = { | 1100 var NUMBER_FORMAT_KEY_MAP = { |
1092 'nu': {'property': UNDEFINED, 'type': 'string'} | 1101 'nu': {'property': UNDEFINED, 'type': 'string'} |
1093 }; | 1102 }; |
1094 | 1103 |
1095 var extension = setOptions(options, extensionMap, NUMBER_FORMAT_KEY_MAP, | 1104 var extension = setOptions(options, extensionMap, NUMBER_FORMAT_KEY_MAP, |
1096 getOption, internalOptions); | 1105 getOption, internalOptions); |
1097 | 1106 |
1098 var requestedLocale = locale.locale + extension; | 1107 var requestedLocale = locale.locale + extension; |
1099 var resolved = $objectDefineProperties({}, { | 1108 var resolved = ObjectDefineProperties({}, { |
1100 currency: {writable: true}, | 1109 currency: {writable: true}, |
1101 currencyDisplay: {writable: true}, | 1110 currencyDisplay: {writable: true}, |
1102 locale: {writable: true}, | 1111 locale: {writable: true}, |
1103 maximumFractionDigits: {writable: true}, | 1112 maximumFractionDigits: {writable: true}, |
1104 minimumFractionDigits: {writable: true}, | 1113 minimumFractionDigits: {writable: true}, |
1105 minimumIntegerDigits: {writable: true}, | 1114 minimumIntegerDigits: {writable: true}, |
1106 numberingSystem: {writable: true}, | 1115 numberingSystem: {writable: true}, |
1107 requestedLocale: {value: requestedLocale, writable: true}, | 1116 requestedLocale: {value: requestedLocale, writable: true}, |
1108 style: {value: internalOptions.style, writable: true}, | 1117 style: {value: internalOptions.style, writable: true}, |
1109 useGrouping: {writable: true} | 1118 useGrouping: {writable: true} |
1110 }); | 1119 }); |
1111 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) { | 1120 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) { |
1112 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); | 1121 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); |
1113 } | 1122 } |
1114 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) { | 1123 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) { |
1115 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); | 1124 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); |
1116 } | 1125 } |
1117 var formatter = %CreateNumberFormat(requestedLocale, | 1126 var formatter = %CreateNumberFormat(requestedLocale, |
1118 internalOptions, | 1127 internalOptions, |
1119 resolved); | 1128 resolved); |
1120 | 1129 |
1121 // We can't get information about number or currency style from ICU, so we | 1130 // We can't get information about number or currency style from ICU, so we |
1122 // assume user request was fulfilled. | 1131 // assume user request was fulfilled. |
1123 if (internalOptions.style === 'currency') { | 1132 if (internalOptions.style === 'currency') { |
1124 $objectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, | 1133 ObjectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, |
1125 writable: true}); | 1134 writable: true}); |
1126 } | 1135 } |
1127 | 1136 |
1128 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); | 1137 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); |
1129 $objectDefineProperty(numberFormat, 'resolved', {value: resolved}); | 1138 ObjectDefineProperty(numberFormat, 'resolved', {value: resolved}); |
1130 | 1139 |
1131 return numberFormat; | 1140 return numberFormat; |
1132 } | 1141 } |
1133 | 1142 |
1134 | 1143 |
1135 /** | 1144 /** |
1136 * Constructs Intl.NumberFormat object given optional locales and options | 1145 * Constructs Intl.NumberFormat object given optional locales and options |
1137 * parameters. | 1146 * parameters. |
1138 * | 1147 * |
1139 * @constructor | 1148 * @constructor |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1192 | 1201 |
1193 if (format.resolved.hasOwnProperty('maximumSignificantDigits')) { | 1202 if (format.resolved.hasOwnProperty('maximumSignificantDigits')) { |
1194 defineWECProperty(result, 'maximumSignificantDigits', | 1203 defineWECProperty(result, 'maximumSignificantDigits', |
1195 format.resolved.maximumSignificantDigits); | 1204 format.resolved.maximumSignificantDigits); |
1196 } | 1205 } |
1197 | 1206 |
1198 return result; | 1207 return result; |
1199 }, | 1208 }, |
1200 DONT_ENUM | 1209 DONT_ENUM |
1201 ); | 1210 ); |
1202 $setFunctionName(Intl.NumberFormat.prototype.resolvedOptions, | 1211 SetFunctionName(Intl.NumberFormat.prototype.resolvedOptions, |
1203 'resolvedOptions'); | 1212 'resolvedOptions'); |
1204 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); | 1213 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); |
1205 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); | 1214 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); |
1206 | 1215 |
1207 | 1216 |
1208 /** | 1217 /** |
1209 * Returns the subset of the given locale list for which this locale list | 1218 * 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 | 1219 * has a matching (possibly fallback) locale. Locales appear in the same |
1211 * order in the returned list as in the input list. | 1220 * order in the returned list as in the input list. |
1212 * Options are optional parameter. | 1221 * Options are optional parameter. |
1213 */ | 1222 */ |
1214 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { | 1223 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { |
1215 if (%_IsConstructCall()) { | 1224 if (%_IsConstructCall()) { |
1216 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1225 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1217 } | 1226 } |
1218 | 1227 |
1219 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); | 1228 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); |
1220 }, | 1229 }, |
1221 DONT_ENUM | 1230 DONT_ENUM |
1222 ); | 1231 ); |
1223 $setFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); | 1232 SetFunctionName(Intl.NumberFormat.supportedLocalesOf, |
Jakob Kummerow
2015/05/21 13:45:24
nit: should still fit on one line
| |
1233 'supportedLocalesOf'); | |
1224 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); | 1234 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); |
1225 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); | 1235 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
1226 | 1236 |
1227 | 1237 |
1228 /** | 1238 /** |
1229 * Returns a String value representing the result of calling ToNumber(value) | 1239 * Returns a String value representing the result of calling ToNumber(value) |
1230 * according to the effective locale and the formatting options of this | 1240 * according to the effective locale and the formatting options of this |
1231 * NumberFormat. | 1241 * NumberFormat. |
1232 */ | 1242 */ |
1233 function formatNumber(formatter, value) { | 1243 function formatNumber(formatter, value) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1409 needsDefault = false; | 1419 needsDefault = false; |
1410 } | 1420 } |
1411 | 1421 |
1412 if ((required === 'time' || required === 'any') && | 1422 if ((required === 'time' || required === 'any') && |
1413 (!IS_UNDEFINED(options.hour) || !IS_UNDEFINED(options.minute) || | 1423 (!IS_UNDEFINED(options.hour) || !IS_UNDEFINED(options.minute) || |
1414 !IS_UNDEFINED(options.second))) { | 1424 !IS_UNDEFINED(options.second))) { |
1415 needsDefault = false; | 1425 needsDefault = false; |
1416 } | 1426 } |
1417 | 1427 |
1418 if (needsDefault && (defaults === 'date' || defaults === 'all')) { | 1428 if (needsDefault && (defaults === 'date' || defaults === 'all')) { |
1419 $objectDefineProperty(options, 'year', {value: 'numeric', | 1429 ObjectDefineProperty(options, 'year', {value: 'numeric', |
1430 writable: true, | |
1431 enumerable: true, | |
1432 configurable: true}); | |
1433 ObjectDefineProperty(options, 'month', {value: 'numeric', | |
1420 writable: true, | 1434 writable: true, |
1421 enumerable: true, | 1435 enumerable: true, |
1422 configurable: true}); | 1436 configurable: true}); |
1423 $objectDefineProperty(options, 'month', {value: 'numeric', | 1437 ObjectDefineProperty(options, 'day', {value: 'numeric', |
1438 writable: true, | |
1439 enumerable: true, | |
1440 configurable: true}); | |
1441 } | |
1442 | |
1443 if (needsDefault && (defaults === 'time' || defaults === 'all')) { | |
1444 ObjectDefineProperty(options, 'hour', {value: 'numeric', | |
1445 writable: true, | |
1446 enumerable: true, | |
1447 configurable: true}); | |
1448 ObjectDefineProperty(options, 'minute', {value: 'numeric', | |
1424 writable: true, | 1449 writable: true, |
1425 enumerable: true, | 1450 enumerable: true, |
1426 configurable: true}); | 1451 configurable: true}); |
1427 $objectDefineProperty(options, 'day', {value: 'numeric', | 1452 ObjectDefineProperty(options, 'second', {value: 'numeric', |
1428 writable: true, | 1453 writable: true, |
1429 enumerable: true, | 1454 enumerable: true, |
1430 configurable: true}); | 1455 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 } | 1456 } |
1447 | 1457 |
1448 return options; | 1458 return options; |
1449 } | 1459 } |
1450 | 1460 |
1451 | 1461 |
1452 /** | 1462 /** |
1453 * Initializes the given object so it's a valid DateTimeFormat instance. | 1463 * Initializes the given object so it's a valid DateTimeFormat instance. |
1454 * Useful for subclassing. | 1464 * Useful for subclassing. |
1455 */ | 1465 */ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1493 */ | 1503 */ |
1494 var DATETIME_FORMAT_KEY_MAP = { | 1504 var DATETIME_FORMAT_KEY_MAP = { |
1495 'ca': {'property': UNDEFINED, 'type': 'string'}, | 1505 'ca': {'property': UNDEFINED, 'type': 'string'}, |
1496 'nu': {'property': UNDEFINED, 'type': 'string'} | 1506 'nu': {'property': UNDEFINED, 'type': 'string'} |
1497 }; | 1507 }; |
1498 | 1508 |
1499 var extension = setOptions(options, extensionMap, DATETIME_FORMAT_KEY_MAP, | 1509 var extension = setOptions(options, extensionMap, DATETIME_FORMAT_KEY_MAP, |
1500 getOption, internalOptions); | 1510 getOption, internalOptions); |
1501 | 1511 |
1502 var requestedLocale = locale.locale + extension; | 1512 var requestedLocale = locale.locale + extension; |
1503 var resolved = $objectDefineProperties({}, { | 1513 var resolved = ObjectDefineProperties({}, { |
1504 calendar: {writable: true}, | 1514 calendar: {writable: true}, |
1505 day: {writable: true}, | 1515 day: {writable: true}, |
1506 era: {writable: true}, | 1516 era: {writable: true}, |
1507 hour12: {writable: true}, | 1517 hour12: {writable: true}, |
1508 hour: {writable: true}, | 1518 hour: {writable: true}, |
1509 locale: {writable: true}, | 1519 locale: {writable: true}, |
1510 minute: {writable: true}, | 1520 minute: {writable: true}, |
1511 month: {writable: true}, | 1521 month: {writable: true}, |
1512 numberingSystem: {writable: true}, | 1522 numberingSystem: {writable: true}, |
1513 pattern: {writable: true}, | 1523 pattern: {writable: true}, |
1514 requestedLocale: {value: requestedLocale, writable: true}, | 1524 requestedLocale: {value: requestedLocale, writable: true}, |
1515 second: {writable: true}, | 1525 second: {writable: true}, |
1516 timeZone: {writable: true}, | 1526 timeZone: {writable: true}, |
1517 timeZoneName: {writable: true}, | 1527 timeZoneName: {writable: true}, |
1518 tz: {value: tz, writable: true}, | 1528 tz: {value: tz, writable: true}, |
1519 weekday: {writable: true}, | 1529 weekday: {writable: true}, |
1520 year: {writable: true} | 1530 year: {writable: true} |
1521 }); | 1531 }); |
1522 | 1532 |
1523 var formatter = %CreateDateTimeFormat( | 1533 var formatter = %CreateDateTimeFormat( |
1524 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); | 1534 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); |
1525 | 1535 |
1526 if (!IS_UNDEFINED(tz) && tz !== resolved.timeZone) { | 1536 if (!IS_UNDEFINED(tz) && tz !== resolved.timeZone) { |
1527 throw MakeRangeError(kUnsupportedTimeZone, tz); | 1537 throw MakeRangeError(kUnsupportedTimeZone, tz); |
1528 } | 1538 } |
1529 | 1539 |
1530 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); | 1540 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); |
1531 $objectDefineProperty(dateFormat, 'resolved', {value: resolved}); | 1541 ObjectDefineProperty(dateFormat, 'resolved', {value: resolved}); |
1532 | 1542 |
1533 return dateFormat; | 1543 return dateFormat; |
1534 } | 1544 } |
1535 | 1545 |
1536 | 1546 |
1537 /** | 1547 /** |
1538 * Constructs Intl.DateTimeFormat object given optional locales and options | 1548 * Constructs Intl.DateTimeFormat object given optional locales and options |
1539 * parameters. | 1549 * parameters. |
1540 * | 1550 * |
1541 * @constructor | 1551 * @constructor |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1613 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); | 1623 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); |
1614 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); | 1624 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); |
1615 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); | 1625 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); |
1616 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); | 1626 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); |
1617 addWECPropertyIfDefined(result, 'second', fromPattern.second); | 1627 addWECPropertyIfDefined(result, 'second', fromPattern.second); |
1618 | 1628 |
1619 return result; | 1629 return result; |
1620 }, | 1630 }, |
1621 DONT_ENUM | 1631 DONT_ENUM |
1622 ); | 1632 ); |
1623 $setFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, | 1633 SetFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, |
1624 'resolvedOptions'); | 1634 'resolvedOptions'); |
1625 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); | 1635 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); |
1626 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); | 1636 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); |
1627 | 1637 |
1628 | 1638 |
1629 /** | 1639 /** |
1630 * Returns the subset of the given locale list for which this locale list | 1640 * 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 | 1641 * has a matching (possibly fallback) locale. Locales appear in the same |
1632 * order in the returned list as in the input list. | 1642 * order in the returned list as in the input list. |
1633 * Options are optional parameter. | 1643 * Options are optional parameter. |
1634 */ | 1644 */ |
1635 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { | 1645 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { |
1636 if (%_IsConstructCall()) { | 1646 if (%_IsConstructCall()) { |
1637 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1647 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1638 } | 1648 } |
1639 | 1649 |
1640 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); | 1650 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); |
1641 }, | 1651 }, |
1642 DONT_ENUM | 1652 DONT_ENUM |
1643 ); | 1653 ); |
1644 $setFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); | 1654 SetFunctionName(Intl.DateTimeFormat.supportedLocalesOf, |
Jakob Kummerow
2015/05/21 13:45:24
nit: should still fit on one line
| |
1655 'supportedLocalesOf'); | |
1645 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); | 1656 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); |
1646 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); | 1657 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); |
1647 | 1658 |
1648 | 1659 |
1649 /** | 1660 /** |
1650 * Returns a String value representing the result of calling ToNumber(date) | 1661 * Returns a String value representing the result of calling ToNumber(date) |
1651 * according to the effective locale and the formatting options of this | 1662 * according to the effective locale and the formatting options of this |
1652 * DateTimeFormat. | 1663 * DateTimeFormat. |
1653 */ | 1664 */ |
1654 function formatDate(formatter, dateValue) { | 1665 function formatDate(formatter, dateValue) { |
1655 var dateMs; | 1666 var dateMs; |
1656 if (IS_UNDEFINED(dateValue)) { | 1667 if (IS_UNDEFINED(dateValue)) { |
1657 dateMs = GlobalDate.now(); | 1668 dateMs = GlobalDate.now(); |
1658 } else { | 1669 } else { |
1659 dateMs = $toNumber(dateValue); | 1670 dateMs = $toNumber(dateValue); |
1660 } | 1671 } |
1661 | 1672 |
1662 if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange); | 1673 if (!IsFinite(dateMs)) throw MakeRangeError(kDateRange); |
1663 | 1674 |
1664 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), | 1675 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), |
1665 new GlobalDate(dateMs)); | 1676 new GlobalDate(dateMs)); |
1666 } | 1677 } |
1667 | 1678 |
1668 | 1679 |
1669 /** | 1680 /** |
1670 * Returns a Date object representing the result of calling ToString(value) | 1681 * Returns a Date object representing the result of calling ToString(value) |
1671 * according to the effective locale and the formatting options of this | 1682 * according to the effective locale and the formatting options of this |
1672 * DateTimeFormat. | 1683 * DateTimeFormat. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1729 } | 1740 } |
1730 | 1741 |
1731 var getOption = getGetOption(options, 'breakiterator'); | 1742 var getOption = getGetOption(options, 'breakiterator'); |
1732 | 1743 |
1733 var internalOptions = {}; | 1744 var internalOptions = {}; |
1734 | 1745 |
1735 defineWEProperty(internalOptions, 'type', getOption( | 1746 defineWEProperty(internalOptions, 'type', getOption( |
1736 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); | 1747 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); |
1737 | 1748 |
1738 var locale = resolveLocale('breakiterator', locales, options); | 1749 var locale = resolveLocale('breakiterator', locales, options); |
1739 var resolved = $objectDefineProperties({}, { | 1750 var resolved = ObjectDefineProperties({}, { |
1740 requestedLocale: {value: locale.locale, writable: true}, | 1751 requestedLocale: {value: locale.locale, writable: true}, |
1741 type: {value: internalOptions.type, writable: true}, | 1752 type: {value: internalOptions.type, writable: true}, |
1742 locale: {writable: true} | 1753 locale: {writable: true} |
1743 }); | 1754 }); |
1744 | 1755 |
1745 var internalIterator = %CreateBreakIterator(locale.locale, | 1756 var internalIterator = %CreateBreakIterator(locale.locale, |
1746 internalOptions, | 1757 internalOptions, |
1747 resolved); | 1758 resolved); |
1748 | 1759 |
1749 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', | 1760 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', |
1750 internalIterator); | 1761 internalIterator); |
1751 $objectDefineProperty(iterator, 'resolved', {value: resolved}); | 1762 ObjectDefineProperty(iterator, 'resolved', {value: resolved}); |
1752 | 1763 |
1753 return iterator; | 1764 return iterator; |
1754 } | 1765 } |
1755 | 1766 |
1756 | 1767 |
1757 /** | 1768 /** |
1758 * Constructs Intl.v8BreakIterator object given optional locales and options | 1769 * Constructs Intl.v8BreakIterator object given optional locales and options |
1759 * parameters. | 1770 * parameters. |
1760 * | 1771 * |
1761 * @constructor | 1772 * @constructor |
(...skipping 30 matching lines...) Expand all Loading... | |
1792 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, | 1803 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, |
1793 segmenter.resolved.locale); | 1804 segmenter.resolved.locale); |
1794 | 1805 |
1795 return { | 1806 return { |
1796 locale: locale, | 1807 locale: locale, |
1797 type: segmenter.resolved.type | 1808 type: segmenter.resolved.type |
1798 }; | 1809 }; |
1799 }, | 1810 }, |
1800 DONT_ENUM | 1811 DONT_ENUM |
1801 ); | 1812 ); |
1802 $setFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, | 1813 SetFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, |
1803 'resolvedOptions'); | 1814 'resolvedOptions'); |
1804 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); | 1815 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); |
1805 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); | 1816 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); |
1806 | 1817 |
1807 | 1818 |
1808 /** | 1819 /** |
1809 * Returns the subset of the given locale list for which this locale list | 1820 * 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 | 1821 * has a matching (possibly fallback) locale. Locales appear in the same |
1811 * order in the returned list as in the input list. | 1822 * order in the returned list as in the input list. |
1812 * Options are optional parameter. | 1823 * Options are optional parameter. |
1813 */ | 1824 */ |
1814 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', | 1825 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', |
1815 function(locales) { | 1826 function(locales) { |
1816 if (%_IsConstructCall()) { | 1827 if (%_IsConstructCall()) { |
1817 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1828 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1818 } | 1829 } |
1819 | 1830 |
1820 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); | 1831 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); |
1821 }, | 1832 }, |
1822 DONT_ENUM | 1833 DONT_ENUM |
1823 ); | 1834 ); |
1824 $setFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); | 1835 SetFunctionName(Intl.v8BreakIterator.supportedLocalesOf, |
Jakob Kummerow
2015/05/21 13:45:24
nit: should still fit on one line
| |
1836 'supportedLocalesOf'); | |
1825 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); | 1837 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
1826 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); | 1838 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
1827 | 1839 |
1828 | 1840 |
1829 /** | 1841 /** |
1830 * Adopts text to segment using the iterator. Old text, if present, | 1842 * Adopts text to segment using the iterator. Old text, if present, |
1831 * gets discarded. | 1843 * gets discarded. |
1832 */ | 1844 */ |
1833 function adoptText(iterator, text) { | 1845 function adoptText(iterator, text) { |
1834 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), | 1846 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1904 if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) { | 1916 if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) { |
1905 if (IS_UNDEFINED(defaultObjects[service])) { | 1917 if (IS_UNDEFINED(defaultObjects[service])) { |
1906 defaultObjects[service] = new savedObjects[service](locales, useOptions); | 1918 defaultObjects[service] = new savedObjects[service](locales, useOptions); |
1907 } | 1919 } |
1908 return defaultObjects[service]; | 1920 return defaultObjects[service]; |
1909 } | 1921 } |
1910 return new savedObjects[service](locales, useOptions); | 1922 return new savedObjects[service](locales, useOptions); |
1911 } | 1923 } |
1912 | 1924 |
1913 | 1925 |
1926 function OverrideFunction(object, name, f) { | |
1927 %CheckIsBootstrapping(); | |
1928 ObjectDefineProperty(object, name, { value: f, | |
1929 writeable: true, | |
1930 configurable: true, | |
1931 enumerable: false }); | |
1932 SetFunctionName(f, name); | |
1933 %FunctionRemovePrototype(f); | |
1934 %SetNativeFlag(f); | |
1935 } | |
1936 | |
1914 /** | 1937 /** |
1915 * Compares this and that, and returns less than 0, 0 or greater than 0 value. | 1938 * Compares this and that, and returns less than 0, 0 or greater than 0 value. |
1916 * Overrides the built-in method. | 1939 * Overrides the built-in method. |
1917 */ | 1940 */ |
1918 $overrideFunction(GlobalString.prototype, 'localeCompare', function(that) { | 1941 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { |
1919 if (%_IsConstructCall()) { | 1942 if (%_IsConstructCall()) { |
1920 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1943 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1921 } | 1944 } |
1922 | 1945 |
1923 if (IS_NULL_OR_UNDEFINED(this)) { | 1946 if (IS_NULL_OR_UNDEFINED(this)) { |
1924 throw MakeTypeError(kMethodInvokedOnNullOrUndefined); | 1947 throw MakeTypeError(kMethodInvokedOnNullOrUndefined); |
1925 } | 1948 } |
1926 | 1949 |
1927 var locales = %_Arguments(1); | 1950 var locales = %_Arguments(1); |
1928 var options = %_Arguments(2); | 1951 var options = %_Arguments(2); |
1929 var collator = cachedOrNewService('collator', locales, options); | 1952 var collator = cachedOrNewService('collator', locales, options); |
1930 return compare(collator, this, that); | 1953 return compare(collator, this, that); |
1931 } | 1954 } |
1932 ); | 1955 ); |
1933 | 1956 |
1934 | 1957 |
1935 /** | 1958 /** |
1936 * Unicode normalization. This method is called with one argument that | 1959 * Unicode normalization. This method is called with one argument that |
1937 * specifies the normalization form. | 1960 * specifies the normalization form. |
1938 * If none is specified, "NFC" is assumed. | 1961 * If none is specified, "NFC" is assumed. |
1939 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw | 1962 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw |
1940 * a RangeError Exception. | 1963 * a RangeError Exception. |
1941 */ | 1964 */ |
1942 $overrideFunction(GlobalString.prototype, 'normalize', function(that) { | 1965 OverrideFunction(GlobalString.prototype, 'normalize', function(that) { |
1943 if (%_IsConstructCall()) { | 1966 if (%_IsConstructCall()) { |
1944 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1967 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1945 } | 1968 } |
1946 | 1969 |
1947 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); | 1970 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); |
1948 | 1971 |
1949 var form = GlobalString(%_Arguments(0) || 'NFC'); | 1972 var form = GlobalString(%_Arguments(0) || 'NFC'); |
1950 | 1973 |
1951 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; | 1974 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; |
1952 | 1975 |
1953 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); | 1976 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); |
1954 if (normalizationForm === -1) { | 1977 if (normalizationForm === -1) { |
1955 throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', ')); | 1978 throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', ')); |
1956 } | 1979 } |
1957 | 1980 |
1958 return %StringNormalize(this, normalizationForm); | 1981 return %StringNormalize(this, normalizationForm); |
1959 } | 1982 } |
1960 ); | 1983 ); |
1961 | 1984 |
1962 | 1985 |
1963 /** | 1986 /** |
1964 * Formats a Number object (this) using locale and options values. | 1987 * Formats a Number object (this) using locale and options values. |
1965 * If locale or options are omitted, defaults are used. | 1988 * If locale or options are omitted, defaults are used. |
1966 */ | 1989 */ |
1967 $overrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { | 1990 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
1968 if (%_IsConstructCall()) { | 1991 if (%_IsConstructCall()) { |
1969 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1992 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1970 } | 1993 } |
1971 | 1994 |
1972 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { | 1995 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { |
1973 throw MakeTypeError(kMethodInvokedOnWrongType, "Number"); | 1996 throw MakeTypeError(kMethodInvokedOnWrongType, "Number"); |
1974 } | 1997 } |
1975 | 1998 |
1976 var locales = %_Arguments(0); | 1999 var locales = %_Arguments(0); |
1977 var options = %_Arguments(1); | 2000 var options = %_Arguments(1); |
1978 var numberFormat = cachedOrNewService('numberformat', locales, options); | 2001 var numberFormat = cachedOrNewService('numberformat', locales, options); |
1979 return formatNumber(numberFormat, this); | 2002 return formatNumber(numberFormat, this); |
1980 } | 2003 } |
1981 ); | 2004 ); |
1982 | 2005 |
1983 | 2006 |
1984 /** | 2007 /** |
1985 * Returns actual formatted date or fails if date parameter is invalid. | 2008 * Returns actual formatted date or fails if date parameter is invalid. |
1986 */ | 2009 */ |
1987 function toLocaleDateTime(date, locales, options, required, defaults, service) { | 2010 function toLocaleDateTime(date, locales, options, required, defaults, service) { |
1988 if (!(date instanceof GlobalDate)) { | 2011 if (!(date instanceof GlobalDate)) { |
1989 throw MakeTypeError(kMethodInvokedOnWrongType, "Date"); | 2012 throw MakeTypeError(kMethodInvokedOnWrongType, "Date"); |
1990 } | 2013 } |
1991 | 2014 |
1992 if ($isNaN(date)) { | 2015 if (IsNaN(date)) return 'Invalid Date'; |
1993 return 'Invalid Date'; | |
1994 } | |
1995 | 2016 |
1996 var internalOptions = toDateTimeOptions(options, required, defaults); | 2017 var internalOptions = toDateTimeOptions(options, required, defaults); |
1997 | 2018 |
1998 var dateFormat = | 2019 var dateFormat = |
1999 cachedOrNewService(service, locales, options, internalOptions); | 2020 cachedOrNewService(service, locales, options, internalOptions); |
2000 | 2021 |
2001 return formatDate(dateFormat, date); | 2022 return formatDate(dateFormat, date); |
2002 } | 2023 } |
2003 | 2024 |
2004 | 2025 |
2005 /** | 2026 /** |
2006 * Formats a Date object (this) using locale and options values. | 2027 * 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 | 2028 * If locale or options are omitted, defaults are used - both date and time are |
2008 * present in the output. | 2029 * present in the output. |
2009 */ | 2030 */ |
2010 $overrideFunction(GlobalDate.prototype, 'toLocaleString', function() { | 2031 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { |
2011 if (%_IsConstructCall()) { | 2032 if (%_IsConstructCall()) { |
2012 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2033 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2013 } | 2034 } |
2014 | 2035 |
2015 var locales = %_Arguments(0); | 2036 var locales = %_Arguments(0); |
2016 var options = %_Arguments(1); | 2037 var options = %_Arguments(1); |
2017 return toLocaleDateTime( | 2038 return toLocaleDateTime( |
2018 this, locales, options, 'any', 'all', 'dateformatall'); | 2039 this, locales, options, 'any', 'all', 'dateformatall'); |
2019 } | 2040 } |
2020 ); | 2041 ); |
2021 | 2042 |
2022 | 2043 |
2023 /** | 2044 /** |
2024 * Formats a Date object (this) using locale and options values. | 2045 * Formats a Date object (this) using locale and options values. |
2025 * If locale or options are omitted, defaults are used - only date is present | 2046 * If locale or options are omitted, defaults are used - only date is present |
2026 * in the output. | 2047 * in the output. |
2027 */ | 2048 */ |
2028 $overrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { | 2049 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { |
2029 if (%_IsConstructCall()) { | 2050 if (%_IsConstructCall()) { |
2030 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2051 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2031 } | 2052 } |
2032 | 2053 |
2033 var locales = %_Arguments(0); | 2054 var locales = %_Arguments(0); |
2034 var options = %_Arguments(1); | 2055 var options = %_Arguments(1); |
2035 return toLocaleDateTime( | 2056 return toLocaleDateTime( |
2036 this, locales, options, 'date', 'date', 'dateformatdate'); | 2057 this, locales, options, 'date', 'date', 'dateformatdate'); |
2037 } | 2058 } |
2038 ); | 2059 ); |
2039 | 2060 |
2040 | 2061 |
2041 /** | 2062 /** |
2042 * Formats a Date object (this) using locale and options values. | 2063 * Formats a Date object (this) using locale and options values. |
2043 * If locale or options are omitted, defaults are used - only time is present | 2064 * If locale or options are omitted, defaults are used - only time is present |
2044 * in the output. | 2065 * in the output. |
2045 */ | 2066 */ |
2046 $overrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { | 2067 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { |
2047 if (%_IsConstructCall()) { | 2068 if (%_IsConstructCall()) { |
2048 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2069 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2049 } | 2070 } |
2050 | 2071 |
2051 var locales = %_Arguments(0); | 2072 var locales = %_Arguments(0); |
2052 var options = %_Arguments(1); | 2073 var options = %_Arguments(1); |
2053 return toLocaleDateTime( | 2074 return toLocaleDateTime( |
2054 this, locales, options, 'time', 'time', 'dateformattime'); | 2075 this, locales, options, 'time', 'time', 'dateformattime'); |
2055 } | 2076 } |
2056 ); | 2077 ); |
2057 | 2078 |
2058 }) | 2079 }) |
OLD | NEW |