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

Side by Side Diff: src/i18n.js

Issue 1123703002: Reland "Wrap v8natives.js into a function." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: revert stack trace printing 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/json.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 */
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // DateTimeFormat.format needs to be 0 arg method, but can stil 247 // DateTimeFormat.format needs to be 0 arg method, but can stil
248 // receive optional dateValue param. If one was provided, pass it 248 // receive optional dateValue param. If one was provided, pass it
249 // along. 249 // along.
250 if (%_ArgumentsLength() > 0) { 250 if (%_ArgumentsLength() > 0) {
251 return implementation(that, %_Arguments(0)); 251 return implementation(that, %_Arguments(0));
252 } else { 252 } else {
253 return implementation(that); 253 return implementation(that);
254 } 254 }
255 } 255 }
256 } 256 }
257 SetFunctionName(boundMethod, internalName); 257 $setFunctionName(boundMethod, internalName);
258 %FunctionRemovePrototype(boundMethod); 258 %FunctionRemovePrototype(boundMethod);
259 %SetNativeFlag(boundMethod); 259 %SetNativeFlag(boundMethod);
260 this[internalName] = boundMethod; 260 this[internalName] = boundMethod;
261 } 261 }
262 return this[internalName]; 262 return this[internalName];
263 } 263 }
264 264
265 SetFunctionName(getter, methodName); 265 $setFunctionName(getter, methodName);
266 %FunctionRemovePrototype(getter); 266 %FunctionRemovePrototype(getter);
267 %SetNativeFlag(getter); 267 %SetNativeFlag(getter);
268 268
269 ObjectDefineProperty(obj.prototype, methodName, { 269 $objectDefineProperty(obj.prototype, methodName, {
270 get: getter, 270 get: getter,
271 enumerable: false, 271 enumerable: false,
272 configurable: true 272 configurable: true
273 }); 273 });
274 } 274 }
275 275
276 276
277 /** 277 /**
278 * Returns an intersection of locales and service supported locales. 278 * Returns an intersection of locales and service supported locales.
279 * Parameter locales is treated as a priority list. 279 * Parameter locales is treated as a priority list.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return extension === ''? '' : '-u' + extension; 578 return extension === ''? '' : '-u' + extension;
579 } 579 }
580 580
581 581
582 /** 582 /**
583 * Converts all OwnProperties into 583 * Converts all OwnProperties into
584 * configurable: false, writable: false, enumerable: true. 584 * configurable: false, writable: false, enumerable: true.
585 */ 585 */
586 function freezeArray(array) { 586 function freezeArray(array) {
587 array.forEach(function(element, index) { 587 array.forEach(function(element, index) {
588 ObjectDefineProperty(array, index, {value: element, 588 $objectDefineProperty(array, index, {value: element,
589 configurable: false, 589 configurable: false,
590 writable: false, 590 writable: false,
591 enumerable: true}); 591 enumerable: true});
592 }); 592 });
593 593
594 ObjectDefineProperty(array, 'length', {value: array.length, 594 $objectDefineProperty(array, 'length', {value: array.length,
595 writable: false}); 595 writable: false});
596 return array; 596 return array;
597 } 597 }
598 598
599 599
600 /** 600 /**
601 * It's sometimes desireable to leave user requested locale instead of ICU 601 * It's sometimes desireable to leave user requested locale instead of ICU
602 * supported one (zh-TW is equivalent to zh-Hant-TW, so we should keep shorter 602 * supported one (zh-TW is equivalent to zh-Hant-TW, so we should keep shorter
603 * one, if that was what user requested). 603 * one, if that was what user requested).
604 * This function returns user specified tag if its maximized form matches ICU 604 * This function returns user specified tag if its maximized form matches ICU
605 * resolved locale. If not we return ICU result. 605 * resolved locale. If not we return ICU result.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 646
647 return available; 647 return available;
648 } 648 }
649 649
650 650
651 /** 651 /**
652 * Defines a property and sets writable and enumerable to true. 652 * Defines a property and sets writable and enumerable to true.
653 * Configurable is false by default. 653 * Configurable is false by default.
654 */ 654 */
655 function defineWEProperty(object, property, value) { 655 function defineWEProperty(object, property, value) {
656 ObjectDefineProperty(object, property, 656 $objectDefineProperty(object, property,
657 {value: value, writable: true, enumerable: true}); 657 {value: value, writable: true, enumerable: true});
658 } 658 }
659 659
660 660
661 /** 661 /**
662 * Adds property to an object if the value is not undefined. 662 * Adds property to an object if the value is not undefined.
663 * Sets configurable descriptor to false. 663 * Sets configurable descriptor to false.
664 */ 664 */
665 function addWEPropertyIfDefined(object, property, value) { 665 function addWEPropertyIfDefined(object, property, value) {
666 if (value !== undefined) { 666 if (value !== undefined) {
667 defineWEProperty(object, property, value); 667 defineWEProperty(object, property, value);
668 } 668 }
669 } 669 }
670 670
671 671
672 /** 672 /**
673 * Defines a property and sets writable, enumerable and configurable to true. 673 * Defines a property and sets writable, enumerable and configurable to true.
674 */ 674 */
675 function defineWECProperty(object, property, value) { 675 function defineWECProperty(object, property, value) {
676 ObjectDefineProperty(object, property, 676 $objectDefineProperty(object, property, {value: value,
677 {value: value, 677 writable: true,
678 writable: true, 678 enumerable: true,
679 enumerable: true, 679 configurable: true});
680 configurable: true});
681 } 680 }
682 681
683 682
684 /** 683 /**
685 * Adds property to an object if the value is not undefined. 684 * Adds property to an object if the value is not undefined.
686 * Sets all descriptors to true. 685 * Sets all descriptors to true.
687 */ 686 */
688 function addWECPropertyIfDefined(object, property, value) { 687 function addWECPropertyIfDefined(object, property, value) {
689 if (value !== undefined) { 688 if (value !== undefined) {
690 defineWECProperty(object, property, value); 689 defineWECProperty(object, property, value);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 extension = '-u-co-search'; 909 extension = '-u-co-search';
911 } 910 }
912 defineWEProperty(internalOptions, 'collation', collation); 911 defineWEProperty(internalOptions, 'collation', collation);
913 912
914 var requestedLocale = locale.locale + extension; 913 var requestedLocale = locale.locale + extension;
915 914
916 // We define all properties C++ code may produce, to prevent security 915 // We define all properties C++ code may produce, to prevent security
917 // problems. If malicious user decides to redefine Object.prototype.locale 916 // problems. If malicious user decides to redefine Object.prototype.locale
918 // we can't just use plain x.locale = 'us' or in C++ Set("locale", "us"). 917 // we can't just use plain x.locale = 'us' or in C++ Set("locale", "us").
919 // ObjectDefineProperties will either succeed defining or throw an error. 918 // ObjectDefineProperties will either succeed defining or throw an error.
920 var resolved = ObjectDefineProperties({}, { 919 var resolved = $objectDefineProperties({}, {
921 caseFirst: {writable: true}, 920 caseFirst: {writable: true},
922 collation: {value: internalOptions.collation, writable: true}, 921 collation: {value: internalOptions.collation, writable: true},
923 ignorePunctuation: {writable: true}, 922 ignorePunctuation: {writable: true},
924 locale: {writable: true}, 923 locale: {writable: true},
925 numeric: {writable: true}, 924 numeric: {writable: true},
926 requestedLocale: {value: requestedLocale, writable: true}, 925 requestedLocale: {value: requestedLocale, writable: true},
927 sensitivity: {writable: true}, 926 sensitivity: {writable: true},
928 strength: {writable: true}, 927 strength: {writable: true},
929 usage: {value: internalOptions.usage, writable: true} 928 usage: {value: internalOptions.usage, writable: true}
930 }); 929 });
931 930
932 var internalCollator = %CreateCollator(requestedLocale, 931 var internalCollator = %CreateCollator(requestedLocale,
933 internalOptions, 932 internalOptions,
934 resolved); 933 resolved);
935 934
936 // Writable, configurable and enumerable are set to false by default. 935 // Writable, configurable and enumerable are set to false by default.
937 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); 936 %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator);
938 ObjectDefineProperty(collator, 'resolved', {value: resolved}); 937 $objectDefineProperty(collator, 'resolved', {value: resolved});
939 938
940 return collator; 939 return collator;
941 } 940 }
942 941
943 942
944 /** 943 /**
945 * Constructs Intl.Collator object given optional locales and options 944 * Constructs Intl.Collator object given optional locales and options
946 * parameters. 945 * parameters.
947 * 946 *
948 * @constructor 947 * @constructor
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 usage: coll.resolved.usage, 982 usage: coll.resolved.usage,
984 sensitivity: coll.resolved.sensitivity, 983 sensitivity: coll.resolved.sensitivity,
985 ignorePunctuation: coll.resolved.ignorePunctuation, 984 ignorePunctuation: coll.resolved.ignorePunctuation,
986 numeric: coll.resolved.numeric, 985 numeric: coll.resolved.numeric,
987 caseFirst: coll.resolved.caseFirst, 986 caseFirst: coll.resolved.caseFirst,
988 collation: coll.resolved.collation 987 collation: coll.resolved.collation
989 }; 988 };
990 }, 989 },
991 DONT_ENUM 990 DONT_ENUM
992 ); 991 );
993 SetFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); 992 $setFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions');
994 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); 993 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions);
995 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); 994 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions);
996 995
997 996
998 /** 997 /**
999 * Returns the subset of the given locale list for which this locale list 998 * Returns the subset of the given locale list for which this locale list
1000 * has a matching (possibly fallback) locale. Locales appear in the same 999 * has a matching (possibly fallback) locale. Locales appear in the same
1001 * order in the returned list as in the input list. 1000 * order in the returned list as in the input list.
1002 * Options are optional parameter. 1001 * Options are optional parameter.
1003 */ 1002 */
1004 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { 1003 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) {
1005 if (%_IsConstructCall()) { 1004 if (%_IsConstructCall()) {
1006 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 1005 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1007 } 1006 }
1008 1007
1009 return supportedLocalesOf('collator', locales, %_Arguments(1)); 1008 return supportedLocalesOf('collator', locales, %_Arguments(1));
1010 }, 1009 },
1011 DONT_ENUM 1010 DONT_ENUM
1012 ); 1011 );
1013 SetFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); 1012 $setFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf');
1014 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); 1013 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf);
1015 %SetNativeFlag(Intl.Collator.supportedLocalesOf); 1014 %SetNativeFlag(Intl.Collator.supportedLocalesOf);
1016 1015
1017 1016
1018 /** 1017 /**
1019 * When the compare method is called with two arguments x and y, it returns a 1018 * When the compare method is called with two arguments x and y, it returns a
1020 * Number other than NaN that represents the result of a locale-sensitive 1019 * Number other than NaN that represents the result of a locale-sensitive
1021 * String comparison of x with y. 1020 * String comparison of x with y.
1022 * The result is intended to order String values in the sort order specified 1021 * The result is intended to order String values in the sort order specified
1023 * by the effective locale and collation options computed during construction 1022 * by the effective locale and collation options computed during construction
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 defineWEProperty(internalOptions, 'useGrouping', getOption( 1123 defineWEProperty(internalOptions, 'useGrouping', getOption(
1125 'useGrouping', 'boolean', undefined, true)); 1124 'useGrouping', 'boolean', undefined, true));
1126 1125
1127 // ICU prefers options to be passed using -u- extension key/values for 1126 // ICU prefers options to be passed using -u- extension key/values for
1128 // number format, so we need to build that. 1127 // number format, so we need to build that.
1129 var extensionMap = parseExtension(locale.extension); 1128 var extensionMap = parseExtension(locale.extension);
1130 var extension = setOptions(options, extensionMap, NUMBER_FORMAT_KEY_MAP, 1129 var extension = setOptions(options, extensionMap, NUMBER_FORMAT_KEY_MAP,
1131 getOption, internalOptions); 1130 getOption, internalOptions);
1132 1131
1133 var requestedLocale = locale.locale + extension; 1132 var requestedLocale = locale.locale + extension;
1134 var resolved = ObjectDefineProperties({}, { 1133 var resolved = $objectDefineProperties({}, {
1135 currency: {writable: true}, 1134 currency: {writable: true},
1136 currencyDisplay: {writable: true}, 1135 currencyDisplay: {writable: true},
1137 locale: {writable: true}, 1136 locale: {writable: true},
1138 maximumFractionDigits: {writable: true}, 1137 maximumFractionDigits: {writable: true},
1139 minimumFractionDigits: {writable: true}, 1138 minimumFractionDigits: {writable: true},
1140 minimumIntegerDigits: {writable: true}, 1139 minimumIntegerDigits: {writable: true},
1141 numberingSystem: {writable: true}, 1140 numberingSystem: {writable: true},
1142 requestedLocale: {value: requestedLocale, writable: true}, 1141 requestedLocale: {value: requestedLocale, writable: true},
1143 style: {value: internalOptions.style, writable: true}, 1142 style: {value: internalOptions.style, writable: true},
1144 useGrouping: {writable: true} 1143 useGrouping: {writable: true}
1145 }); 1144 });
1146 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) { 1145 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) {
1147 defineWEProperty(resolved, 'minimumSignificantDigits', undefined); 1146 defineWEProperty(resolved, 'minimumSignificantDigits', undefined);
1148 } 1147 }
1149 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) { 1148 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) {
1150 defineWEProperty(resolved, 'maximumSignificantDigits', undefined); 1149 defineWEProperty(resolved, 'maximumSignificantDigits', undefined);
1151 } 1150 }
1152 var formatter = %CreateNumberFormat(requestedLocale, 1151 var formatter = %CreateNumberFormat(requestedLocale,
1153 internalOptions, 1152 internalOptions,
1154 resolved); 1153 resolved);
1155 1154
1156 // We can't get information about number or currency style from ICU, so we 1155 // We can't get information about number or currency style from ICU, so we
1157 // assume user request was fulfilled. 1156 // assume user request was fulfilled.
1158 if (internalOptions.style === 'currency') { 1157 if (internalOptions.style === 'currency') {
1159 ObjectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, 1158 $objectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay,
1160 writable: true}); 1159 writable: true});
1161 } 1160 }
1162 1161
1163 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); 1162 %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter);
1164 ObjectDefineProperty(numberFormat, 'resolved', {value: resolved}); 1163 $objectDefineProperty(numberFormat, 'resolved', {value: resolved});
1165 1164
1166 return numberFormat; 1165 return numberFormat;
1167 } 1166 }
1168 1167
1169 1168
1170 /** 1169 /**
1171 * Constructs Intl.NumberFormat object given optional locales and options 1170 * Constructs Intl.NumberFormat object given optional locales and options
1172 * parameters. 1171 * parameters.
1173 * 1172 *
1174 * @constructor 1173 * @constructor
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 1226
1228 if (format.resolved.hasOwnProperty('maximumSignificantDigits')) { 1227 if (format.resolved.hasOwnProperty('maximumSignificantDigits')) {
1229 defineWECProperty(result, 'maximumSignificantDigits', 1228 defineWECProperty(result, 'maximumSignificantDigits',
1230 format.resolved.maximumSignificantDigits); 1229 format.resolved.maximumSignificantDigits);
1231 } 1230 }
1232 1231
1233 return result; 1232 return result;
1234 }, 1233 },
1235 DONT_ENUM 1234 DONT_ENUM
1236 ); 1235 );
1237 SetFunctionName(Intl.NumberFormat.prototype.resolvedOptions, 1236 $setFunctionName(Intl.NumberFormat.prototype.resolvedOptions,
1238 'resolvedOptions'); 1237 'resolvedOptions');
1239 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); 1238 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions);
1240 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); 1239 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions);
1241 1240
1242 1241
1243 /** 1242 /**
1244 * Returns the subset of the given locale list for which this locale list 1243 * Returns the subset of the given locale list for which this locale list
1245 * has a matching (possibly fallback) locale. Locales appear in the same 1244 * has a matching (possibly fallback) locale. Locales appear in the same
1246 * order in the returned list as in the input list. 1245 * order in the returned list as in the input list.
1247 * Options are optional parameter. 1246 * Options are optional parameter.
1248 */ 1247 */
1249 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { 1248 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
1250 if (%_IsConstructCall()) { 1249 if (%_IsConstructCall()) {
1251 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 1250 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1252 } 1251 }
1253 1252
1254 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); 1253 return supportedLocalesOf('numberformat', locales, %_Arguments(1));
1255 }, 1254 },
1256 DONT_ENUM 1255 DONT_ENUM
1257 ); 1256 );
1258 SetFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); 1257 $setFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf');
1259 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); 1258 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf);
1260 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); 1259 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf);
1261 1260
1262 1261
1263 /** 1262 /**
1264 * Returns a String value representing the result of calling ToNumber(value) 1263 * Returns a String value representing the result of calling ToNumber(value)
1265 * according to the effective locale and the formatting options of this 1264 * according to the effective locale and the formatting options of this
1266 * NumberFormat. 1265 * NumberFormat.
1267 */ 1266 */
1268 function formatNumber(formatter, value) { 1267 function formatNumber(formatter, value) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 needsDefault = false; 1443 needsDefault = false;
1445 } 1444 }
1446 1445
1447 if ((required === 'time' || required === 'any') && 1446 if ((required === 'time' || required === 'any') &&
1448 (options.hour !== undefined || options.minute !== undefined || 1447 (options.hour !== undefined || options.minute !== undefined ||
1449 options.second !== undefined)) { 1448 options.second !== undefined)) {
1450 needsDefault = false; 1449 needsDefault = false;
1451 } 1450 }
1452 1451
1453 if (needsDefault && (defaults === 'date' || defaults === 'all')) { 1452 if (needsDefault && (defaults === 'date' || defaults === 'all')) {
1454 ObjectDefineProperty(options, 'year', {value: 'numeric', 1453 $objectDefineProperty(options, 'year', {value: 'numeric',
1454 writable: true,
1455 enumerable: true,
1456 configurable: true});
1457 $objectDefineProperty(options, 'month', {value: 'numeric',
1458 writable: true,
1459 enumerable: true,
1460 configurable: true});
1461 $objectDefineProperty(options, 'day', {value: 'numeric',
1455 writable: true, 1462 writable: true,
1456 enumerable: true, 1463 enumerable: true,
1457 configurable: true}); 1464 configurable: true});
1458 ObjectDefineProperty(options, 'month', {value: 'numeric', 1465 }
1466
1467 if (needsDefault && (defaults === 'time' || defaults === 'all')) {
1468 $objectDefineProperty(options, 'hour', {value: 'numeric',
1459 writable: true, 1469 writable: true,
1460 enumerable: true, 1470 enumerable: true,
1461 configurable: true}); 1471 configurable: true});
1462 ObjectDefineProperty(options, 'day', {value: 'numeric', 1472 $objectDefineProperty(options, 'minute', {value: 'numeric',
1463 writable: true, 1473 writable: true,
1464 enumerable: true, 1474 enumerable: true,
1465 configurable: true}); 1475 configurable: true});
1466 } 1476 $objectDefineProperty(options, 'second', {value: 'numeric',
1467 1477 writable: true,
1468 if (needsDefault && (defaults === 'time' || defaults === 'all')) { 1478 enumerable: true,
1469 ObjectDefineProperty(options, 'hour', {value: 'numeric', 1479 configurable: true});
1470 writable: true,
1471 enumerable: true,
1472 configurable: true});
1473 ObjectDefineProperty(options, 'minute', {value: 'numeric',
1474 writable: true,
1475 enumerable: true,
1476 configurable: true});
1477 ObjectDefineProperty(options, 'second', {value: 'numeric',
1478 writable: true,
1479 enumerable: true,
1480 configurable: true});
1481 } 1480 }
1482 1481
1483 return options; 1482 return options;
1484 } 1483 }
1485 1484
1486 1485
1487 /** 1486 /**
1488 * Initializes the given object so it's a valid DateTimeFormat instance. 1487 * Initializes the given object so it's a valid DateTimeFormat instance.
1489 * Useful for subclassing. 1488 * Useful for subclassing.
1490 */ 1489 */
(...skipping 27 matching lines...) Expand all
1518 var tz = canonicalizeTimeZoneID(options.timeZone); 1517 var tz = canonicalizeTimeZoneID(options.timeZone);
1519 1518
1520 // ICU prefers options to be passed using -u- extension key/values, so 1519 // ICU prefers options to be passed using -u- extension key/values, so
1521 // we need to build that. 1520 // we need to build that.
1522 var internalOptions = {}; 1521 var internalOptions = {};
1523 var extensionMap = parseExtension(locale.extension); 1522 var extensionMap = parseExtension(locale.extension);
1524 var extension = setOptions(options, extensionMap, DATETIME_FORMAT_KEY_MAP, 1523 var extension = setOptions(options, extensionMap, DATETIME_FORMAT_KEY_MAP,
1525 getOption, internalOptions); 1524 getOption, internalOptions);
1526 1525
1527 var requestedLocale = locale.locale + extension; 1526 var requestedLocale = locale.locale + extension;
1528 var resolved = ObjectDefineProperties({}, { 1527 var resolved = $objectDefineProperties({}, {
1529 calendar: {writable: true}, 1528 calendar: {writable: true},
1530 day: {writable: true}, 1529 day: {writable: true},
1531 era: {writable: true}, 1530 era: {writable: true},
1532 hour12: {writable: true}, 1531 hour12: {writable: true},
1533 hour: {writable: true}, 1532 hour: {writable: true},
1534 locale: {writable: true}, 1533 locale: {writable: true},
1535 minute: {writable: true}, 1534 minute: {writable: true},
1536 month: {writable: true}, 1535 month: {writable: true},
1537 numberingSystem: {writable: true}, 1536 numberingSystem: {writable: true},
1538 pattern: {writable: true}, 1537 pattern: {writable: true},
1539 requestedLocale: {value: requestedLocale, writable: true}, 1538 requestedLocale: {value: requestedLocale, writable: true},
1540 second: {writable: true}, 1539 second: {writable: true},
1541 timeZone: {writable: true}, 1540 timeZone: {writable: true},
1542 timeZoneName: {writable: true}, 1541 timeZoneName: {writable: true},
1543 tz: {value: tz, writable: true}, 1542 tz: {value: tz, writable: true},
1544 weekday: {writable: true}, 1543 weekday: {writable: true},
1545 year: {writable: true} 1544 year: {writable: true}
1546 }); 1545 });
1547 1546
1548 var formatter = %CreateDateTimeFormat( 1547 var formatter = %CreateDateTimeFormat(
1549 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); 1548 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
1550 1549
1551 if (tz !== undefined && tz !== resolved.timeZone) { 1550 if (tz !== undefined && tz !== resolved.timeZone) {
1552 throw MakeRangeError(kUnsupportedTimeZone, tz); 1551 throw MakeRangeError(kUnsupportedTimeZone, tz);
1553 } 1552 }
1554 1553
1555 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); 1554 %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter);
1556 ObjectDefineProperty(dateFormat, 'resolved', {value: resolved}); 1555 $objectDefineProperty(dateFormat, 'resolved', {value: resolved});
1557 1556
1558 return dateFormat; 1557 return dateFormat;
1559 } 1558 }
1560 1559
1561 1560
1562 /** 1561 /**
1563 * Constructs Intl.DateTimeFormat object given optional locales and options 1562 * Constructs Intl.DateTimeFormat object given optional locales and options
1564 * parameters. 1563 * parameters.
1565 * 1564 *
1566 * @constructor 1565 * @constructor
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); 1618 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday);
1620 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); 1619 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12);
1621 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); 1620 addWECPropertyIfDefined(result, 'hour', fromPattern.hour);
1622 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); 1621 addWECPropertyIfDefined(result, 'minute', fromPattern.minute);
1623 addWECPropertyIfDefined(result, 'second', fromPattern.second); 1622 addWECPropertyIfDefined(result, 'second', fromPattern.second);
1624 1623
1625 return result; 1624 return result;
1626 }, 1625 },
1627 DONT_ENUM 1626 DONT_ENUM
1628 ); 1627 );
1629 SetFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, 1628 $setFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions,
1630 'resolvedOptions'); 1629 'resolvedOptions');
1631 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); 1630 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions);
1632 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); 1631 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions);
1633 1632
1634 1633
1635 /** 1634 /**
1636 * Returns the subset of the given locale list for which this locale list 1635 * Returns the subset of the given locale list for which this locale list
1637 * has a matching (possibly fallback) locale. Locales appear in the same 1636 * has a matching (possibly fallback) locale. Locales appear in the same
1638 * order in the returned list as in the input list. 1637 * order in the returned list as in the input list.
1639 * Options are optional parameter. 1638 * Options are optional parameter.
1640 */ 1639 */
1641 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { 1640 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
1642 if (%_IsConstructCall()) { 1641 if (%_IsConstructCall()) {
1643 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 1642 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1644 } 1643 }
1645 1644
1646 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); 1645 return supportedLocalesOf('dateformat', locales, %_Arguments(1));
1647 }, 1646 },
1648 DONT_ENUM 1647 DONT_ENUM
1649 ); 1648 );
1650 SetFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); 1649 $setFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf');
1651 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); 1650 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf);
1652 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); 1651 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf);
1653 1652
1654 1653
1655 /** 1654 /**
1656 * Returns a String value representing the result of calling ToNumber(date) 1655 * Returns a String value representing the result of calling ToNumber(date)
1657 * according to the effective locale and the formatting options of this 1656 * according to the effective locale and the formatting options of this
1658 * DateTimeFormat. 1657 * DateTimeFormat.
1659 */ 1658 */
1660 function formatDate(formatter, dateValue) { 1659 function formatDate(formatter, dateValue) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 } 1734 }
1736 1735
1737 var getOption = getGetOption(options, 'breakiterator'); 1736 var getOption = getGetOption(options, 'breakiterator');
1738 1737
1739 var internalOptions = {}; 1738 var internalOptions = {};
1740 1739
1741 defineWEProperty(internalOptions, 'type', getOption( 1740 defineWEProperty(internalOptions, 'type', getOption(
1742 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); 1741 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word'));
1743 1742
1744 var locale = resolveLocale('breakiterator', locales, options); 1743 var locale = resolveLocale('breakiterator', locales, options);
1745 var resolved = ObjectDefineProperties({}, { 1744 var resolved = $objectDefineProperties({}, {
1746 requestedLocale: {value: locale.locale, writable: true}, 1745 requestedLocale: {value: locale.locale, writable: true},
1747 type: {value: internalOptions.type, writable: true}, 1746 type: {value: internalOptions.type, writable: true},
1748 locale: {writable: true} 1747 locale: {writable: true}
1749 }); 1748 });
1750 1749
1751 var internalIterator = %CreateBreakIterator(locale.locale, 1750 var internalIterator = %CreateBreakIterator(locale.locale,
1752 internalOptions, 1751 internalOptions,
1753 resolved); 1752 resolved);
1754 1753
1755 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', 1754 %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator',
1756 internalIterator); 1755 internalIterator);
1757 ObjectDefineProperty(iterator, 'resolved', {value: resolved}); 1756 $objectDefineProperty(iterator, 'resolved', {value: resolved});
1758 1757
1759 return iterator; 1758 return iterator;
1760 } 1759 }
1761 1760
1762 1761
1763 /** 1762 /**
1764 * Constructs Intl.v8BreakIterator object given optional locales and options 1763 * Constructs Intl.v8BreakIterator object given optional locales and options
1765 * parameters. 1764 * parameters.
1766 * 1765 *
1767 * @constructor 1766 * @constructor
(...skipping 30 matching lines...) Expand all
1798 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, 1797 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale,
1799 segmenter.resolved.locale); 1798 segmenter.resolved.locale);
1800 1799
1801 return { 1800 return {
1802 locale: locale, 1801 locale: locale,
1803 type: segmenter.resolved.type 1802 type: segmenter.resolved.type
1804 }; 1803 };
1805 }, 1804 },
1806 DONT_ENUM 1805 DONT_ENUM
1807 ); 1806 );
1808 SetFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, 1807 $setFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions,
1809 'resolvedOptions'); 1808 'resolvedOptions');
1810 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); 1809 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions);
1811 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); 1810 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions);
1812 1811
1813 1812
1814 /** 1813 /**
1815 * Returns the subset of the given locale list for which this locale list 1814 * Returns the subset of the given locale list for which this locale list
1816 * has a matching (possibly fallback) locale. Locales appear in the same 1815 * has a matching (possibly fallback) locale. Locales appear in the same
1817 * order in the returned list as in the input list. 1816 * order in the returned list as in the input list.
1818 * Options are optional parameter. 1817 * Options are optional parameter.
1819 */ 1818 */
1820 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', 1819 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf',
1821 function(locales) { 1820 function(locales) {
1822 if (%_IsConstructCall()) { 1821 if (%_IsConstructCall()) {
1823 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 1822 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1824 } 1823 }
1825 1824
1826 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); 1825 return supportedLocalesOf('breakiterator', locales, %_Arguments(1));
1827 }, 1826 },
1828 DONT_ENUM 1827 DONT_ENUM
1829 ); 1828 );
1830 SetFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); 1829 $setFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf');
1831 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); 1830 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf);
1832 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); 1831 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf);
1833 1832
1834 1833
1835 /** 1834 /**
1836 * Adopts text to segment using the iterator. Old text, if present, 1835 * Adopts text to segment using the iterator. Old text, if present,
1837 * gets discarded. 1836 * gets discarded.
1838 */ 1837 */
1839 function adoptText(iterator, text) { 1838 function adoptText(iterator, text) {
1840 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), 1839 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 return defaultObjects[service]; 1913 return defaultObjects[service];
1915 } 1914 }
1916 return new savedObjects[service](locales, useOptions); 1915 return new savedObjects[service](locales, useOptions);
1917 } 1916 }
1918 1917
1919 1918
1920 /** 1919 /**
1921 * Compares this and that, and returns less than 0, 0 or greater than 0 value. 1920 * Compares this and that, and returns less than 0, 0 or greater than 0 value.
1922 * Overrides the built-in method. 1921 * Overrides the built-in method.
1923 */ 1922 */
1924 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { 1923 $overrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
1925 if (%_IsConstructCall()) { 1924 if (%_IsConstructCall()) {
1926 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 1925 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1927 } 1926 }
1928 1927
1929 if (IS_NULL_OR_UNDEFINED(this)) { 1928 if (IS_NULL_OR_UNDEFINED(this)) {
1930 throw MakeTypeError(kMethodInvokedOnNullOrUndefined); 1929 throw MakeTypeError(kMethodInvokedOnNullOrUndefined);
1931 } 1930 }
1932 1931
1933 var locales = %_Arguments(1); 1932 var locales = %_Arguments(1);
1934 var options = %_Arguments(2); 1933 var options = %_Arguments(2);
1935 var collator = cachedOrNewService('collator', locales, options); 1934 var collator = cachedOrNewService('collator', locales, options);
1936 return compare(collator, this, that); 1935 return compare(collator, this, that);
1937 } 1936 }
1938 ); 1937 );
1939 1938
1940 1939
1941 /** 1940 /**
1942 * Unicode normalization. This method is called with one argument that 1941 * Unicode normalization. This method is called with one argument that
1943 * specifies the normalization form. 1942 * specifies the normalization form.
1944 * If none is specified, "NFC" is assumed. 1943 * If none is specified, "NFC" is assumed.
1945 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw 1944 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
1946 * a RangeError Exception. 1945 * a RangeError Exception.
1947 */ 1946 */
1948 OverrideFunction(GlobalString.prototype, 'normalize', function(that) { 1947 $overrideFunction(GlobalString.prototype, 'normalize', function(that) {
1949 if (%_IsConstructCall()) { 1948 if (%_IsConstructCall()) {
1950 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 1949 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1951 } 1950 }
1952 1951
1953 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); 1952 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
1954 1953
1955 var form = GlobalString(%_Arguments(0) || 'NFC'); 1954 var form = GlobalString(%_Arguments(0) || 'NFC');
1956 1955
1957 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); 1956 var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
1958 if (normalizationForm === -1) { 1957 if (normalizationForm === -1) {
1959 throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', ')); 1958 throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', '));
1960 } 1959 }
1961 1960
1962 return %StringNormalize(this, normalizationForm); 1961 return %StringNormalize(this, normalizationForm);
1963 } 1962 }
1964 ); 1963 );
1965 1964
1966 1965
1967 /** 1966 /**
1968 * Formats a Number object (this) using locale and options values. 1967 * Formats a Number object (this) using locale and options values.
1969 * If locale or options are omitted, defaults are used. 1968 * If locale or options are omitted, defaults are used.
1970 */ 1969 */
1971 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { 1970 $overrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
1972 if (%_IsConstructCall()) { 1971 if (%_IsConstructCall()) {
1973 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 1972 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
1974 } 1973 }
1975 1974
1976 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { 1975 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
1977 throw MakeTypeError(kMethodInvokedOnWrongType, "Number"); 1976 throw MakeTypeError(kMethodInvokedOnWrongType, "Number");
1978 } 1977 }
1979 1978
1980 var locales = %_Arguments(0); 1979 var locales = %_Arguments(0);
1981 var options = %_Arguments(1); 1980 var options = %_Arguments(1);
(...skipping 22 matching lines...) Expand all
2004 2003
2005 return formatDate(dateFormat, date); 2004 return formatDate(dateFormat, date);
2006 } 2005 }
2007 2006
2008 2007
2009 /** 2008 /**
2010 * Formats a Date object (this) using locale and options values. 2009 * Formats a Date object (this) using locale and options values.
2011 * If locale or options are omitted, defaults are used - both date and time are 2010 * If locale or options are omitted, defaults are used - both date and time are
2012 * present in the output. 2011 * present in the output.
2013 */ 2012 */
2014 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { 2013 $overrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
2015 if (%_IsConstructCall()) { 2014 if (%_IsConstructCall()) {
2016 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 2015 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
2017 } 2016 }
2018 2017
2019 var locales = %_Arguments(0); 2018 var locales = %_Arguments(0);
2020 var options = %_Arguments(1); 2019 var options = %_Arguments(1);
2021 return toLocaleDateTime( 2020 return toLocaleDateTime(
2022 this, locales, options, 'any', 'all', 'dateformatall'); 2021 this, locales, options, 'any', 'all', 'dateformatall');
2023 } 2022 }
2024 ); 2023 );
2025 2024
2026 2025
2027 /** 2026 /**
2028 * Formats a Date object (this) using locale and options values. 2027 * Formats a Date object (this) using locale and options values.
2029 * If locale or options are omitted, defaults are used - only date is present 2028 * If locale or options are omitted, defaults are used - only date is present
2030 * in the output. 2029 * in the output.
2031 */ 2030 */
2032 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { 2031 $overrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
2033 if (%_IsConstructCall()) { 2032 if (%_IsConstructCall()) {
2034 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 2033 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
2035 } 2034 }
2036 2035
2037 var locales = %_Arguments(0); 2036 var locales = %_Arguments(0);
2038 var options = %_Arguments(1); 2037 var options = %_Arguments(1);
2039 return toLocaleDateTime( 2038 return toLocaleDateTime(
2040 this, locales, options, 'date', 'date', 'dateformatdate'); 2039 this, locales, options, 'date', 'date', 'dateformatdate');
2041 } 2040 }
2042 ); 2041 );
2043 2042
2044 2043
2045 /** 2044 /**
2046 * Formats a Date object (this) using locale and options values. 2045 * Formats a Date object (this) using locale and options values.
2047 * If locale or options are omitted, defaults are used - only time is present 2046 * If locale or options are omitted, defaults are used - only time is present
2048 * in the output. 2047 * in the output.
2049 */ 2048 */
2050 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { 2049 $overrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
2051 if (%_IsConstructCall()) { 2050 if (%_IsConstructCall()) {
2052 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); 2051 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
2053 } 2052 }
2054 2053
2055 var locales = %_Arguments(0); 2054 var locales = %_Arguments(0);
2056 var options = %_Arguments(1); 2055 var options = %_Arguments(1);
2057 return toLocaleDateTime( 2056 return toLocaleDateTime(
2058 this, locales, options, 'time', 'time', 'dateformattime'); 2057 this, locales, options, 'time', 'time', 'dateformattime');
2059 } 2058 }
2060 ); 2059 );
2061 2060
2062 })(); 2061 })();
OLDNEW
« no previous file with comments | « src/harmony-typedarray.js ('k') | src/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698