Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: src/i18n.js

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

Powered by Google App Engine
This is Rietveld 408576698