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

Side by Side Diff: src/i18n.js

Issue 1096243003: Migrate error messages, part 5 (array.js and i18n.js). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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-array.js ('k') | src/macros.py » ('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 */
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 var ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR = 212 var ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR =
213 'Function object that\'s not a constructor was created with new'; 213 'Function object that\'s not a constructor was created with new';
214 214
215 215
216 /** 216 /**
217 * Adds bound method to the prototype of the given object. 217 * Adds bound method to the prototype of the given object.
218 */ 218 */
219 function addBoundMethod(obj, methodName, implementation, length) { 219 function addBoundMethod(obj, methodName, implementation, length) {
220 function getter() { 220 function getter() {
221 if (!%IsInitializedIntlObject(this)) { 221 if (!%IsInitializedIntlObject(this)) {
222 throw new $TypeError('Method ' + methodName + ' called on a ' + 222 throw MakeTypeError(kMethodCalledOnWrongObject, methodName);
223 'non-object or on a wrong type of object.');
224 } 223 }
225 var internalName = '__bound' + methodName + '__'; 224 var internalName = '__bound' + methodName + '__';
226 if (this[internalName] === undefined) { 225 if (this[internalName] === undefined) {
227 var that = this; 226 var that = this;
228 var boundMethod; 227 var boundMethod;
229 if (length === undefined || length === 2) { 228 if (length === undefined || length === 2) {
230 boundMethod = function(x, y) { 229 boundMethod = function(x, y) {
231 if (%_IsConstructCall()) { 230 if (%_IsConstructCall()) {
232 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 231 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
233 } 232 }
234 return implementation(that, x, y); 233 return implementation(that, x, y);
235 } 234 }
236 } else if (length === 1) { 235 } else if (length === 1) {
237 boundMethod = function(x) { 236 boundMethod = function(x) {
238 if (%_IsConstructCall()) { 237 if (%_IsConstructCall()) {
239 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 238 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
240 } 239 }
241 return implementation(that, x); 240 return implementation(that, x);
242 } 241 }
243 } else { 242 } else {
244 boundMethod = function() { 243 boundMethod = function() {
245 if (%_IsConstructCall()) { 244 if (%_IsConstructCall()) {
246 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 245 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
247 } 246 }
248 // DateTimeFormat.format needs to be 0 arg method, but can stil 247 // DateTimeFormat.format needs to be 0 arg method, but can stil
249 // receive optional dateValue param. If one was provided, pass it 248 // receive optional dateValue param. If one was provided, pass it
250 // along. 249 // along.
251 if (%_ArgumentsLength() > 0) { 250 if (%_ArgumentsLength() > 0) {
252 return implementation(that, %_Arguments(0)); 251 return implementation(that, %_Arguments(0));
253 } else { 252 } else {
254 return implementation(that); 253 return implementation(that);
255 } 254 }
256 } 255 }
(...skipping 17 matching lines...) Expand all
274 }); 273 });
275 } 274 }
276 275
277 276
278 /** 277 /**
279 * Returns an intersection of locales and service supported locales. 278 * Returns an intersection of locales and service supported locales.
280 * Parameter locales is treated as a priority list. 279 * Parameter locales is treated as a priority list.
281 */ 280 */
282 function supportedLocalesOf(service, locales, options) { 281 function supportedLocalesOf(service, locales, options) {
283 if (IS_NULL(service.match(GetServiceRE()))) { 282 if (IS_NULL(service.match(GetServiceRE()))) {
284 throw new $Error('Internal error, wrong service type: ' + service); 283 throw MakeError(kWrongServiceType, service);
285 } 284 }
286 285
287 // Provide defaults if matcher was not specified. 286 // Provide defaults if matcher was not specified.
288 if (options === undefined) { 287 if (options === undefined) {
289 options = {}; 288 options = {};
290 } else { 289 } else {
291 options = ToObject(options); 290 options = ToObject(options);
292 } 291 }
293 292
294 var matcher = options.localeMatcher; 293 var matcher = options.localeMatcher;
295 if (matcher !== undefined) { 294 if (matcher !== undefined) {
296 matcher = GlobalString(matcher); 295 matcher = GlobalString(matcher);
297 if (matcher !== 'lookup' && matcher !== 'best fit') { 296 if (matcher !== 'lookup' && matcher !== 'best fit') {
298 throw new $RangeError('Illegal value for localeMatcher:' + matcher); 297 throw MakeRangeError(kLocaleMatcher, matcher);
299 } 298 }
300 } else { 299 } else {
301 matcher = 'best fit'; 300 matcher = 'best fit';
302 } 301 }
303 302
304 var requestedLocales = initializeLocaleList(locales); 303 var requestedLocales = initializeLocaleList(locales);
305 304
306 // Cache these, they don't ever change per service. 305 // Cache these, they don't ever change per service.
307 if (AVAILABLE_LOCALES[service] === undefined) { 306 if (AVAILABLE_LOCALES[service] === undefined) {
308 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); 307 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 return lookupSupportedLocalesOf(requestedLocales, availableLocales); 358 return lookupSupportedLocalesOf(requestedLocales, availableLocales);
360 } 359 }
361 360
362 361
363 /** 362 /**
364 * Returns a getOption function that extracts property value for given 363 * Returns a getOption function that extracts property value for given
365 * options object. If property is missing it returns defaultValue. If value 364 * options object. If property is missing it returns defaultValue. If value
366 * is out of range for that property it throws RangeError. 365 * is out of range for that property it throws RangeError.
367 */ 366 */
368 function getGetOption(options, caller) { 367 function getGetOption(options, caller) {
369 if (options === undefined) { 368 if (options === undefined) throw MakeError(kDefaultOptionsMissing, caller);
370 throw new $Error('Internal ' + caller + ' error. ' +
371 'Default options are missing.');
372 }
373 369
374 var getOption = function getOption(property, type, values, defaultValue) { 370 var getOption = function getOption(property, type, values, defaultValue) {
375 if (options[property] !== undefined) { 371 if (options[property] !== undefined) {
376 var value = options[property]; 372 var value = options[property];
377 switch (type) { 373 switch (type) {
378 case 'boolean': 374 case 'boolean':
379 value = GlobalBoolean(value); 375 value = GlobalBoolean(value);
380 break; 376 break;
381 case 'string': 377 case 'string':
382 value = GlobalString(value); 378 value = GlobalString(value);
383 break; 379 break;
384 case 'number': 380 case 'number':
385 value = GlobalNumber(value); 381 value = GlobalNumber(value);
386 break; 382 break;
387 default: 383 default:
388 throw new $Error('Internal error. Wrong value type.'); 384 throw MakeError(kWrongValueType);
389 } 385 }
390 if (values !== undefined && values.indexOf(value) === -1) { 386 if (values !== undefined && values.indexOf(value) === -1) {
391 throw new $RangeError('Value ' + value + ' out of range for ' + caller + 387 throw MakeRangeError(kValueOutOfRange, value, caller, property);
392 ' options property ' + property);
393 } 388 }
394 389
395 return value; 390 return value;
396 } 391 }
397 392
398 return defaultValue; 393 return defaultValue;
399 } 394 }
400 395
401 return getOption; 396 return getOption;
402 } 397 }
(...skipping 28 matching lines...) Expand all
431 return resolved; 426 return resolved;
432 } 427 }
433 428
434 429
435 /** 430 /**
436 * Returns best matched supported locale and extension info using basic 431 * Returns best matched supported locale and extension info using basic
437 * lookup algorithm. 432 * lookup algorithm.
438 */ 433 */
439 function lookupMatcher(service, requestedLocales) { 434 function lookupMatcher(service, requestedLocales) {
440 if (IS_NULL(service.match(GetServiceRE()))) { 435 if (IS_NULL(service.match(GetServiceRE()))) {
441 throw new $Error('Internal error, wrong service type: ' + service); 436 throw MakeError(kWrongServiceType, service);
442 } 437 }
443 438
444 // Cache these, they don't ever change per service. 439 // Cache these, they don't ever change per service.
445 if (AVAILABLE_LOCALES[service] === undefined) { 440 if (AVAILABLE_LOCALES[service] === undefined) {
446 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); 441 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service);
447 } 442 }
448 443
449 for (var i = 0; i < requestedLocales.length; ++i) { 444 for (var i = 0; i < requestedLocales.length; ++i) {
450 // Remove all extensions. 445 // Remove all extensions.
451 var locale = requestedLocales[i].replace(GetAnyExtensionRE(), ''); 446 var locale = requestedLocales[i].replace(GetAnyExtensionRE(), '');
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 return word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase(); 699 return word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase();
705 } 700 }
706 701
707 /** 702 /**
708 * Canonicalizes the language tag, or throws in case the tag is invalid. 703 * Canonicalizes the language tag, or throws in case the tag is invalid.
709 */ 704 */
710 function canonicalizeLanguageTag(localeID) { 705 function canonicalizeLanguageTag(localeID) {
711 // null is typeof 'object' so we have to do extra check. 706 // null is typeof 'object' so we have to do extra check.
712 if (typeof localeID !== 'string' && typeof localeID !== 'object' || 707 if (typeof localeID !== 'string' && typeof localeID !== 'object' ||
713 IS_NULL(localeID)) { 708 IS_NULL(localeID)) {
714 throw new $TypeError('Language ID should be string or object.'); 709 throw MakeTypeError(kLanguageID);
715 } 710 }
716 711
717 var localeString = GlobalString(localeID); 712 var localeString = GlobalString(localeID);
718 713
719 if (isValidLanguageTag(localeString) === false) { 714 if (isValidLanguageTag(localeString) === false) {
720 throw new $RangeError('Invalid language tag: ' + localeString); 715 throw MakeRangeError(kInvalidLanguageTag, localeString);
721 } 716 }
722 717
723 // This call will strip -kn but not -kn-true extensions. 718 // This call will strip -kn but not -kn-true extensions.
724 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265. 719 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265.
725 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after 720 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after
726 // upgrade to ICU 4.9. 721 // upgrade to ICU 4.9.
727 var tag = %CanonicalizeLanguageTag(localeString); 722 var tag = %CanonicalizeLanguageTag(localeString);
728 if (tag === 'invalid-tag') { 723 if (tag === 'invalid-tag') {
729 throw new $RangeError('Invalid language tag: ' + localeString); 724 throw MakeRangeError(kInvalidLanguageTag, localeString);
730 } 725 }
731 726
732 return tag; 727 return tag;
733 } 728 }
734 729
735 730
736 /** 731 /**
737 * Returns an array where all locales are canonicalized and duplicates removed. 732 * Returns an array where all locales are canonicalized and duplicates removed.
738 * Throws on locales that are not well formed BCP47 tags. 733 * Throws on locales that are not well formed BCP47 tags.
739 */ 734 */
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; 857 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$';
863 LANGUAGE_TAG_RE = new GlobalRegExp(languageTag, 'i'); 858 LANGUAGE_TAG_RE = new GlobalRegExp(languageTag, 'i');
864 } 859 }
865 860
866 /** 861 /**
867 * Initializes the given object so it's a valid Collator instance. 862 * Initializes the given object so it's a valid Collator instance.
868 * Useful for subclassing. 863 * Useful for subclassing.
869 */ 864 */
870 function initializeCollator(collator, locales, options) { 865 function initializeCollator(collator, locales, options) {
871 if (%IsInitializedIntlObject(collator)) { 866 if (%IsInitializedIntlObject(collator)) {
872 throw new $TypeError('Trying to re-initialize Collator object.'); 867 throw MakeTypeError(kReinitializeIntl, "Collator");
873 } 868 }
874 869
875 if (options === undefined) { 870 if (options === undefined) {
876 options = {}; 871 options = {};
877 } 872 }
878 873
879 var getOption = getGetOption(options, 'collator'); 874 var getOption = getGetOption(options, 'collator');
880 875
881 var internalOptions = {}; 876 var internalOptions = {};
882 877
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 }, 960 },
966 DONT_ENUM 961 DONT_ENUM
967 ); 962 );
968 963
969 964
970 /** 965 /**
971 * Collator resolvedOptions method. 966 * Collator resolvedOptions method.
972 */ 967 */
973 %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() { 968 %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() {
974 if (%_IsConstructCall()) { 969 if (%_IsConstructCall()) {
975 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 970 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
976 } 971 }
977 972
978 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { 973 if (!%IsInitializedIntlObjectOfType(this, 'collator')) {
979 throw new $TypeError('resolvedOptions method called on a non-object ' + 974 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "Collator");
980 'or on a object that is not Intl.Collator.');
981 } 975 }
982 976
983 var coll = this; 977 var coll = this;
984 var locale = getOptimalLanguageTag(coll.resolved.requestedLocale, 978 var locale = getOptimalLanguageTag(coll.resolved.requestedLocale,
985 coll.resolved.locale); 979 coll.resolved.locale);
986 980
987 return { 981 return {
988 locale: locale, 982 locale: locale,
989 usage: coll.resolved.usage, 983 usage: coll.resolved.usage,
990 sensitivity: coll.resolved.sensitivity, 984 sensitivity: coll.resolved.sensitivity,
(...skipping 11 matching lines...) Expand all
1002 996
1003 997
1004 /** 998 /**
1005 * Returns the subset of the given locale list for which this locale list 999 * Returns the subset of the given locale list for which this locale list
1006 * has a matching (possibly fallback) locale. Locales appear in the same 1000 * has a matching (possibly fallback) locale. Locales appear in the same
1007 * order in the returned list as in the input list. 1001 * order in the returned list as in the input list.
1008 * Options are optional parameter. 1002 * Options are optional parameter.
1009 */ 1003 */
1010 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { 1004 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) {
1011 if (%_IsConstructCall()) { 1005 if (%_IsConstructCall()) {
1012 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1006 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1013 } 1007 }
1014 1008
1015 return supportedLocalesOf('collator', locales, %_Arguments(1)); 1009 return supportedLocalesOf('collator', locales, %_Arguments(1));
1016 }, 1010 },
1017 DONT_ENUM 1011 DONT_ENUM
1018 ); 1012 );
1019 %FunctionSetName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); 1013 %FunctionSetName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf');
1020 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); 1014 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf);
1021 %SetNativeFlag(Intl.Collator.supportedLocalesOf); 1015 %SetNativeFlag(Intl.Collator.supportedLocalesOf);
1022 1016
(...skipping 30 matching lines...) Expand all
1053 1047
1054 /** 1048 /**
1055 * Returns the valid digit count for a property, or throws RangeError on 1049 * Returns the valid digit count for a property, or throws RangeError on
1056 * a value out of the range. 1050 * a value out of the range.
1057 */ 1051 */
1058 function getNumberOption(options, property, min, max, fallback) { 1052 function getNumberOption(options, property, min, max, fallback) {
1059 var value = options[property]; 1053 var value = options[property];
1060 if (value !== undefined) { 1054 if (value !== undefined) {
1061 value = GlobalNumber(value); 1055 value = GlobalNumber(value);
1062 if ($isNaN(value) || value < min || value > max) { 1056 if ($isNaN(value) || value < min || value > max) {
1063 throw new $RangeError(property + ' value is out of range.'); 1057 throw MakeRangeError(kPropertyValueOutOfRange, property);
1064 } 1058 }
1065 return $floor(value); 1059 return $floor(value);
1066 } 1060 }
1067 1061
1068 return fallback; 1062 return fallback;
1069 } 1063 }
1070 1064
1071 1065
1072 /** 1066 /**
1073 * Initializes the given object so it's a valid NumberFormat instance. 1067 * Initializes the given object so it's a valid NumberFormat instance.
1074 * Useful for subclassing. 1068 * Useful for subclassing.
1075 */ 1069 */
1076 function initializeNumberFormat(numberFormat, locales, options) { 1070 function initializeNumberFormat(numberFormat, locales, options) {
1077 if (%IsInitializedIntlObject(numberFormat)) { 1071 if (%IsInitializedIntlObject(numberFormat)) {
1078 throw new $TypeError('Trying to re-initialize NumberFormat object.'); 1072 throw MakeTypeError(kReinitializeIntl, "NumberFormat");
1079 } 1073 }
1080 1074
1081 if (options === undefined) { 1075 if (options === undefined) {
1082 options = {}; 1076 options = {};
1083 } 1077 }
1084 1078
1085 var getOption = getGetOption(options, 'numberformat'); 1079 var getOption = getGetOption(options, 'numberformat');
1086 1080
1087 var locale = resolveLocale('numberformat', locales, options); 1081 var locale = resolveLocale('numberformat', locales, options);
1088 1082
1089 var internalOptions = {}; 1083 var internalOptions = {};
1090 defineWEProperty(internalOptions, 'style', getOption( 1084 defineWEProperty(internalOptions, 'style', getOption(
1091 'style', 'string', ['decimal', 'percent', 'currency'], 'decimal')); 1085 'style', 'string', ['decimal', 'percent', 'currency'], 'decimal'));
1092 1086
1093 var currency = getOption('currency', 'string'); 1087 var currency = getOption('currency', 'string');
1094 if (currency !== undefined && !isWellFormedCurrencyCode(currency)) { 1088 if (currency !== undefined && !isWellFormedCurrencyCode(currency)) {
1095 throw new $RangeError('Invalid currency code: ' + currency); 1089 throw MakeRangeError(kInvalidCurrencyCode, currency);
1096 } 1090 }
1097 1091
1098 if (internalOptions.style === 'currency' && currency === undefined) { 1092 if (internalOptions.style === 'currency' && currency === undefined) {
1099 throw new $TypeError('Currency code is required with currency style.'); 1093 throw MakeTypeError(kCurrencyCode);
1100 } 1094 }
1101 1095
1102 var currencyDisplay = getOption( 1096 var currencyDisplay = getOption(
1103 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol'); 1097 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol');
1104 if (internalOptions.style === 'currency') { 1098 if (internalOptions.style === 'currency') {
1105 defineWEProperty(internalOptions, 'currency', currency.toUpperCase()); 1099 defineWEProperty(internalOptions, 'currency', currency.toUpperCase());
1106 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay); 1100 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay);
1107 } 1101 }
1108 1102
1109 // Digit ranges. 1103 // Digit ranges.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 }, 1186 },
1193 DONT_ENUM 1187 DONT_ENUM
1194 ); 1188 );
1195 1189
1196 1190
1197 /** 1191 /**
1198 * NumberFormat resolvedOptions method. 1192 * NumberFormat resolvedOptions method.
1199 */ 1193 */
1200 %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { 1194 %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
1201 if (%_IsConstructCall()) { 1195 if (%_IsConstructCall()) {
1202 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1196 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1203 } 1197 }
1204 1198
1205 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { 1199 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) {
1206 throw new $TypeError('resolvedOptions method called on a non-object' + 1200 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "NumberFormat");
1207 ' or on a object that is not Intl.NumberFormat.');
1208 } 1201 }
1209 1202
1210 var format = this; 1203 var format = this;
1211 var locale = getOptimalLanguageTag(format.resolved.requestedLocale, 1204 var locale = getOptimalLanguageTag(format.resolved.requestedLocale,
1212 format.resolved.locale); 1205 format.resolved.locale);
1213 1206
1214 var result = { 1207 var result = {
1215 locale: locale, 1208 locale: locale,
1216 numberingSystem: format.resolved.numberingSystem, 1209 numberingSystem: format.resolved.numberingSystem,
1217 style: format.resolved.style, 1210 style: format.resolved.style,
(...skipping 30 matching lines...) Expand all
1248 1241
1249 1242
1250 /** 1243 /**
1251 * Returns the subset of the given locale list for which this locale list 1244 * Returns the subset of the given locale list for which this locale list
1252 * has a matching (possibly fallback) locale. Locales appear in the same 1245 * has a matching (possibly fallback) locale. Locales appear in the same
1253 * order in the returned list as in the input list. 1246 * order in the returned list as in the input list.
1254 * Options are optional parameter. 1247 * Options are optional parameter.
1255 */ 1248 */
1256 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { 1249 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
1257 if (%_IsConstructCall()) { 1250 if (%_IsConstructCall()) {
1258 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1251 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1259 } 1252 }
1260 1253
1261 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); 1254 return supportedLocalesOf('numberformat', locales, %_Arguments(1));
1262 }, 1255 },
1263 DONT_ENUM 1256 DONT_ENUM
1264 ); 1257 );
1265 %FunctionSetName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); 1258 %FunctionSetName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf');
1266 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); 1259 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf);
1267 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); 1260 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf);
1268 1261
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 } 1484 }
1492 1485
1493 1486
1494 /** 1487 /**
1495 * Initializes the given object so it's a valid DateTimeFormat instance. 1488 * Initializes the given object so it's a valid DateTimeFormat instance.
1496 * Useful for subclassing. 1489 * Useful for subclassing.
1497 */ 1490 */
1498 function initializeDateTimeFormat(dateFormat, locales, options) { 1491 function initializeDateTimeFormat(dateFormat, locales, options) {
1499 1492
1500 if (%IsInitializedIntlObject(dateFormat)) { 1493 if (%IsInitializedIntlObject(dateFormat)) {
1501 throw new $TypeError('Trying to re-initialize DateTimeFormat object.'); 1494 throw MakeTypeError(kReinitializeIntl, "DateTimeFormat");
1502 } 1495 }
1503 1496
1504 if (options === undefined) { 1497 if (options === undefined) {
1505 options = {}; 1498 options = {};
1506 } 1499 }
1507 1500
1508 var locale = resolveLocale('dateformat', locales, options); 1501 var locale = resolveLocale('dateformat', locales, options);
1509 1502
1510 options = toDateTimeOptions(options, 'any', 'date'); 1503 options = toDateTimeOptions(options, 'any', 'date');
1511 1504
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 timeZoneName: {writable: true}, 1542 timeZoneName: {writable: true},
1550 tz: {value: tz, writable: true}, 1543 tz: {value: tz, writable: true},
1551 weekday: {writable: true}, 1544 weekday: {writable: true},
1552 year: {writable: true} 1545 year: {writable: true}
1553 }); 1546 });
1554 1547
1555 var formatter = %CreateDateTimeFormat( 1548 var formatter = %CreateDateTimeFormat(
1556 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); 1549 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
1557 1550
1558 if (tz !== undefined && tz !== resolved.timeZone) { 1551 if (tz !== undefined && tz !== resolved.timeZone) {
1559 throw new $RangeError('Unsupported time zone specified ' + tz); 1552 throw MakeRangeError(kUnsupportedTimeZone, tz);
1560 } 1553 }
1561 1554
1562 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); 1555 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter);
1563 ObjectDefineProperty(dateFormat, 'resolved', {value: resolved}); 1556 ObjectDefineProperty(dateFormat, 'resolved', {value: resolved});
1564 1557
1565 return dateFormat; 1558 return dateFormat;
1566 } 1559 }
1567 1560
1568 1561
1569 /** 1562 /**
(...skipping 15 matching lines...) Expand all
1585 }, 1578 },
1586 DONT_ENUM 1579 DONT_ENUM
1587 ); 1580 );
1588 1581
1589 1582
1590 /** 1583 /**
1591 * DateTimeFormat resolvedOptions method. 1584 * DateTimeFormat resolvedOptions method.
1592 */ 1585 */
1593 %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { 1586 %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
1594 if (%_IsConstructCall()) { 1587 if (%_IsConstructCall()) {
1595 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1588 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1596 } 1589 }
1597 1590
1598 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { 1591 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
1599 throw new $TypeError('resolvedOptions method called on a non-object or ' + 1592 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "DateTimeFormat");
1600 'on a object that is not Intl.DateTimeFormat.');
1601 } 1593 }
1602 1594
1603 var format = this; 1595 var format = this;
1604 var fromPattern = fromLDMLString(format.resolved.pattern); 1596 var fromPattern = fromLDMLString(format.resolved.pattern);
1605 var userCalendar = ICU_CALENDAR_MAP[format.resolved.calendar]; 1597 var userCalendar = ICU_CALENDAR_MAP[format.resolved.calendar];
1606 if (userCalendar === undefined) { 1598 if (userCalendar === undefined) {
1607 // Use ICU name if we don't have a match. It shouldn't happen, but 1599 // Use ICU name if we don't have a match. It shouldn't happen, but
1608 // it would be too strict to throw for this. 1600 // it would be too strict to throw for this.
1609 userCalendar = format.resolved.calendar; 1601 userCalendar = format.resolved.calendar;
1610 } 1602 }
(...skipping 30 matching lines...) Expand all
1641 1633
1642 1634
1643 /** 1635 /**
1644 * Returns the subset of the given locale list for which this locale list 1636 * Returns the subset of the given locale list for which this locale list
1645 * has a matching (possibly fallback) locale. Locales appear in the same 1637 * has a matching (possibly fallback) locale. Locales appear in the same
1646 * order in the returned list as in the input list. 1638 * order in the returned list as in the input list.
1647 * Options are optional parameter. 1639 * Options are optional parameter.
1648 */ 1640 */
1649 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { 1641 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
1650 if (%_IsConstructCall()) { 1642 if (%_IsConstructCall()) {
1651 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1643 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1652 } 1644 }
1653 1645
1654 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); 1646 return supportedLocalesOf('dateformat', locales, %_Arguments(1));
1655 }, 1647 },
1656 DONT_ENUM 1648 DONT_ENUM
1657 ); 1649 );
1658 %FunctionSetName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); 1650 %FunctionSetName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf');
1659 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); 1651 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf);
1660 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); 1652 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf);
1661 1653
1662 1654
1663 /** 1655 /**
1664 * Returns a String value representing the result of calling ToNumber(date) 1656 * Returns a String value representing the result of calling ToNumber(date)
1665 * according to the effective locale and the formatting options of this 1657 * according to the effective locale and the formatting options of this
1666 * DateTimeFormat. 1658 * DateTimeFormat.
1667 */ 1659 */
1668 function formatDate(formatter, dateValue) { 1660 function formatDate(formatter, dateValue) {
1669 var dateMs; 1661 var dateMs;
1670 if (dateValue === undefined) { 1662 if (dateValue === undefined) {
1671 dateMs = GlobalDate.now(); 1663 dateMs = GlobalDate.now();
1672 } else { 1664 } else {
1673 dateMs = GlobalNumber(dateValue); 1665 dateMs = GlobalNumber(dateValue);
1674 } 1666 }
1675 1667
1676 if (!$isFinite(dateMs)) { 1668 if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange);
1677 throw new $RangeError('Provided date is not in valid range.');
1678 }
1679 1669
1680 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), 1670 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter),
1681 new GlobalDate(dateMs)); 1671 new GlobalDate(dateMs));
1682 } 1672 }
1683 1673
1684 1674
1685 /** 1675 /**
1686 * Returns a Date object representing the result of calling ToString(value) 1676 * Returns a Date object representing the result of calling ToString(value)
1687 * according to the effective locale and the formatting options of this 1677 * according to the effective locale and the formatting options of this
1688 * DateTimeFormat. 1678 * DateTimeFormat.
(...skipping 23 matching lines...) Expand all
1712 // Special case handling (UTC, GMT). 1702 // Special case handling (UTC, GMT).
1713 var upperID = tzID.toUpperCase(); 1703 var upperID = tzID.toUpperCase();
1714 if (upperID === 'UTC' || upperID === 'GMT' || 1704 if (upperID === 'UTC' || upperID === 'GMT' ||
1715 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') { 1705 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') {
1716 return 'UTC'; 1706 return 'UTC';
1717 } 1707 }
1718 1708
1719 // We expect only _ and / beside ASCII letters. 1709 // We expect only _ and / beside ASCII letters.
1720 // All inputs should conform to Area/Location from now on. 1710 // All inputs should conform to Area/Location from now on.
1721 var match = GetTimezoneNameCheckRE().exec(tzID); 1711 var match = GetTimezoneNameCheckRE().exec(tzID);
1722 if (IS_NULL(match)) { 1712 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, tzID);
1723 throw new $RangeError('Expected Area/Location for time zone, got ' + tzID);
1724 }
1725 1713
1726 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]); 1714 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]);
1727 var i = 3; 1715 var i = 3;
1728 while (match[i] !== undefined && i < match.length) { 1716 while (match[i] !== undefined && i < match.length) {
1729 result = result + '_' + toTitleCaseWord(match[i]); 1717 result = result + '_' + toTitleCaseWord(match[i]);
1730 i++; 1718 i++;
1731 } 1719 }
1732 1720
1733 return result; 1721 return result;
1734 } 1722 }
1735 1723
1736 /** 1724 /**
1737 * Initializes the given object so it's a valid BreakIterator instance. 1725 * Initializes the given object so it's a valid BreakIterator instance.
1738 * Useful for subclassing. 1726 * Useful for subclassing.
1739 */ 1727 */
1740 function initializeBreakIterator(iterator, locales, options) { 1728 function initializeBreakIterator(iterator, locales, options) {
1741 if (%IsInitializedIntlObject(iterator)) { 1729 if (%IsInitializedIntlObject(iterator)) {
1742 throw new $TypeError('Trying to re-initialize v8BreakIterator object.'); 1730 throw MakeTypeError(kReinitializeIntl, "v8BreakIterator");
1743 } 1731 }
1744 1732
1745 if (options === undefined) { 1733 if (options === undefined) {
1746 options = {}; 1734 options = {};
1747 } 1735 }
1748 1736
1749 var getOption = getGetOption(options, 'breakiterator'); 1737 var getOption = getGetOption(options, 'breakiterator');
1750 1738
1751 var internalOptions = {}; 1739 var internalOptions = {};
1752 1740
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 DONT_ENUM 1780 DONT_ENUM
1793 ); 1781 );
1794 1782
1795 1783
1796 /** 1784 /**
1797 * BreakIterator resolvedOptions method. 1785 * BreakIterator resolvedOptions method.
1798 */ 1786 */
1799 %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', 1787 %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions',
1800 function() { 1788 function() {
1801 if (%_IsConstructCall()) { 1789 if (%_IsConstructCall()) {
1802 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1790 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1803 } 1791 }
1804 1792
1805 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { 1793 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) {
1806 throw new $TypeError('resolvedOptions method called on a non-object or ' + 1794 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "v8BreakIterator");
1807 'on a object that is not Intl.v8BreakIterator.');
1808 } 1795 }
1809 1796
1810 var segmenter = this; 1797 var segmenter = this;
1811 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, 1798 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale,
1812 segmenter.resolved.locale); 1799 segmenter.resolved.locale);
1813 1800
1814 return { 1801 return {
1815 locale: locale, 1802 locale: locale,
1816 type: segmenter.resolved.type 1803 type: segmenter.resolved.type
1817 }; 1804 };
1818 }, 1805 },
1819 DONT_ENUM 1806 DONT_ENUM
1820 ); 1807 );
1821 %FunctionSetName(Intl.v8BreakIterator.prototype.resolvedOptions, 1808 %FunctionSetName(Intl.v8BreakIterator.prototype.resolvedOptions,
1822 'resolvedOptions'); 1809 'resolvedOptions');
1823 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); 1810 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions);
1824 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); 1811 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions);
1825 1812
1826 1813
1827 /** 1814 /**
1828 * Returns the subset of the given locale list for which this locale list 1815 * Returns the subset of the given locale list for which this locale list
1829 * has a matching (possibly fallback) locale. Locales appear in the same 1816 * has a matching (possibly fallback) locale. Locales appear in the same
1830 * order in the returned list as in the input list. 1817 * order in the returned list as in the input list.
1831 * Options are optional parameter. 1818 * Options are optional parameter.
1832 */ 1819 */
1833 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', 1820 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf',
1834 function(locales) { 1821 function(locales) {
1835 if (%_IsConstructCall()) { 1822 if (%_IsConstructCall()) {
1836 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1823 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1837 } 1824 }
1838 1825
1839 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); 1826 return supportedLocalesOf('breakiterator', locales, %_Arguments(1));
1840 }, 1827 },
1841 DONT_ENUM 1828 DONT_ENUM
1842 ); 1829 );
1843 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); 1830 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf');
1844 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); 1831 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf);
1845 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); 1832 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf);
1846 1833
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 return new savedObjects[service](locales, useOptions); 1916 return new savedObjects[service](locales, useOptions);
1930 } 1917 }
1931 1918
1932 1919
1933 /** 1920 /**
1934 * Compares this and that, and returns less than 0, 0 or greater than 0 value. 1921 * Compares this and that, and returns less than 0, 0 or greater than 0 value.
1935 * Overrides the built-in method. 1922 * Overrides the built-in method.
1936 */ 1923 */
1937 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { 1924 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
1938 if (%_IsConstructCall()) { 1925 if (%_IsConstructCall()) {
1939 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1926 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1940 } 1927 }
1941 1928
1942 if (IS_NULL_OR_UNDEFINED(this)) { 1929 if (IS_NULL_OR_UNDEFINED(this)) {
1943 throw new $TypeError('Method invoked on undefined or null value.'); 1930 throw MakeTypeError(kMethodInvokedOnNullOrUndefined);
1944 } 1931 }
1945 1932
1946 var locales = %_Arguments(1); 1933 var locales = %_Arguments(1);
1947 var options = %_Arguments(2); 1934 var options = %_Arguments(2);
1948 var collator = cachedOrNewService('collator', locales, options); 1935 var collator = cachedOrNewService('collator', locales, options);
1949 return compare(collator, this, that); 1936 return compare(collator, this, that);
1950 } 1937 }
1951 ); 1938 );
1952 1939
1953 1940
1954 /** 1941 /**
1955 * Unicode normalization. This method is called with one argument that 1942 * Unicode normalization. This method is called with one argument that
1956 * specifies the normalization form. 1943 * specifies the normalization form.
1957 * If none is specified, "NFC" is assumed. 1944 * If none is specified, "NFC" is assumed.
1958 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw 1945 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
1959 * a RangeError Exception. 1946 * a RangeError Exception.
1960 */ 1947 */
1961 OverrideFunction(GlobalString.prototype, 'normalize', function(that) { 1948 OverrideFunction(GlobalString.prototype, 'normalize', function(that) {
1962 if (%_IsConstructCall()) { 1949 if (%_IsConstructCall()) {
1963 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1950 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1964 } 1951 }
1965 1952
1966 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); 1953 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
1967 1954
1968 var form = GlobalString(%_Arguments(0) || 'NFC'); 1955 var form = GlobalString(%_Arguments(0) || 'NFC');
1969 1956
1970 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); 1957 var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
1971 if (normalizationForm === -1) { 1958 if (normalizationForm === -1) {
1972 throw new $RangeError('The normalization form should be one of ' 1959 throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', '));
1973 + NORMALIZATION_FORMS.join(', ') + '.');
1974 } 1960 }
1975 1961
1976 return %StringNormalize(this, normalizationForm); 1962 return %StringNormalize(this, normalizationForm);
1977 } 1963 }
1978 ); 1964 );
1979 1965
1980 1966
1981 /** 1967 /**
1982 * Formats a Number object (this) using locale and options values. 1968 * Formats a Number object (this) using locale and options values.
1983 * If locale or options are omitted, defaults are used. 1969 * If locale or options are omitted, defaults are used.
1984 */ 1970 */
1985 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { 1971 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
1986 if (%_IsConstructCall()) { 1972 if (%_IsConstructCall()) {
1987 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1973 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1988 } 1974 }
1989 1975
1990 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { 1976 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
1991 throw new $TypeError('Method invoked on an object that is not Number.'); 1977 throw MakeTypeError(kMethodInvokedOnWrongType, "Number");
1992 } 1978 }
1993 1979
1994 var locales = %_Arguments(0); 1980 var locales = %_Arguments(0);
1995 var options = %_Arguments(1); 1981 var options = %_Arguments(1);
1996 var numberFormat = cachedOrNewService('numberformat', locales, options); 1982 var numberFormat = cachedOrNewService('numberformat', locales, options);
1997 return formatNumber(numberFormat, this); 1983 return formatNumber(numberFormat, this);
1998 } 1984 }
1999 ); 1985 );
2000 1986
2001 1987
2002 /** 1988 /**
2003 * Returns actual formatted date or fails if date parameter is invalid. 1989 * Returns actual formatted date or fails if date parameter is invalid.
2004 */ 1990 */
2005 function toLocaleDateTime(date, locales, options, required, defaults, service) { 1991 function toLocaleDateTime(date, locales, options, required, defaults, service) {
2006 if (!(date instanceof GlobalDate)) { 1992 if (!(date instanceof GlobalDate)) {
2007 throw new $TypeError('Method invoked on an object that is not Date.'); 1993 throw MakeTypeError(kMethodInvokedOnWrongType, "Date");
2008 } 1994 }
2009 1995
2010 if ($isNaN(date)) { 1996 if ($isNaN(date)) {
2011 return 'Invalid Date'; 1997 return 'Invalid Date';
2012 } 1998 }
2013 1999
2014 var internalOptions = toDateTimeOptions(options, required, defaults); 2000 var internalOptions = toDateTimeOptions(options, required, defaults);
2015 2001
2016 var dateFormat = 2002 var dateFormat =
2017 cachedOrNewService(service, locales, options, internalOptions); 2003 cachedOrNewService(service, locales, options, internalOptions);
2018 2004
2019 return formatDate(dateFormat, date); 2005 return formatDate(dateFormat, date);
2020 } 2006 }
2021 2007
2022 2008
2023 /** 2009 /**
2024 * Formats a Date object (this) using locale and options values. 2010 * Formats a Date object (this) using locale and options values.
2025 * If locale or options are omitted, defaults are used - both date and time are 2011 * If locale or options are omitted, defaults are used - both date and time are
2026 * present in the output. 2012 * present in the output.
2027 */ 2013 */
2028 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { 2014 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
2029 if (%_IsConstructCall()) { 2015 if (%_IsConstructCall()) {
2030 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 2016 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
2031 } 2017 }
2032 2018
2033 var locales = %_Arguments(0); 2019 var locales = %_Arguments(0);
2034 var options = %_Arguments(1); 2020 var options = %_Arguments(1);
2035 return toLocaleDateTime( 2021 return toLocaleDateTime(
2036 this, locales, options, 'any', 'all', 'dateformatall'); 2022 this, locales, options, 'any', 'all', 'dateformatall');
2037 } 2023 }
2038 ); 2024 );
2039 2025
2040 2026
2041 /** 2027 /**
2042 * Formats a Date object (this) using locale and options values. 2028 * Formats a Date object (this) using locale and options values.
2043 * If locale or options are omitted, defaults are used - only date is present 2029 * If locale or options are omitted, defaults are used - only date is present
2044 * in the output. 2030 * in the output.
2045 */ 2031 */
2046 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { 2032 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
2047 if (%_IsConstructCall()) { 2033 if (%_IsConstructCall()) {
2048 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 2034 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
2049 } 2035 }
2050 2036
2051 var locales = %_Arguments(0); 2037 var locales = %_Arguments(0);
2052 var options = %_Arguments(1); 2038 var options = %_Arguments(1);
2053 return toLocaleDateTime( 2039 return toLocaleDateTime(
2054 this, locales, options, 'date', 'date', 'dateformatdate'); 2040 this, locales, options, 'date', 'date', 'dateformatdate');
2055 } 2041 }
2056 ); 2042 );
2057 2043
2058 2044
2059 /** 2045 /**
2060 * Formats a Date object (this) using locale and options values. 2046 * Formats a Date object (this) using locale and options values.
2061 * If locale or options are omitted, defaults are used - only time is present 2047 * If locale or options are omitted, defaults are used - only time is present
2062 * in the output. 2048 * in the output.
2063 */ 2049 */
2064 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { 2050 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
2065 if (%_IsConstructCall()) { 2051 if (%_IsConstructCall()) {
2066 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 2052 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
2067 } 2053 }
2068 2054
2069 var locales = %_Arguments(0); 2055 var locales = %_Arguments(0);
2070 var options = %_Arguments(1); 2056 var options = %_Arguments(1);
2071 return toLocaleDateTime( 2057 return toLocaleDateTime(
2072 this, locales, options, 'time', 'time', 'dateformattime'); 2058 this, locales, options, 'time', 'time', 'dateformattime');
2073 } 2059 }
2074 ); 2060 );
2075 2061
2076 })(); 2062 })();
OLDNEW
« no previous file with comments | « src/harmony-array.js ('k') | src/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698