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

Side by Side Diff: src/i18n.js

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

Powered by Google App Engine
This is Rietveld 408576698