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

Side by Side Diff: src/js/i18n.js

Issue 2587713002: [intl] Remove new.target check in Intl functions and method (Closed)
Patch Set: Created 4 years 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 | « no previous file | test/intl/not-constructors.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 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 %IncrementUseCounter(kIntlResolved); 905 %IncrementUseCounter(kIntlResolved);
906 return this[resolvedSymbol]; 906 return this[resolvedSymbol];
907 }, 907 },
908 set(value) { 908 set(value) {
909 this[resolvedSymbol] = value; 909 this[resolvedSymbol] = value;
910 } 910 }
911 }; 911 };
912 912
913 // ECMA 402 section 8.2.1 913 // ECMA 402 section 8.2.1
914 InstallFunction(Intl, 'getCanonicalLocales', function(locales) { 914 InstallFunction(Intl, 'getCanonicalLocales', function(locales) {
915 if (!IS_UNDEFINED(new.target)) {
916 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
917 }
918
919 return makeArray(canonicalizeLocaleList(locales)); 915 return makeArray(canonicalizeLocaleList(locales));
920 } 916 }
921 ); 917 );
922 918
923 /** 919 /**
924 * Initializes the given object so it's a valid Collator instance. 920 * Initializes the given object so it's a valid Collator instance.
925 * Useful for subclassing. 921 * Useful for subclassing.
926 */ 922 */
927 function initializeCollator(collator, locales, options) { 923 function initializeCollator(collator, locales, options) {
928 if (%IsInitializedIntlObject(collator)) { 924 if (%IsInitializedIntlObject(collator)) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 1040
1045 return initializeCollator(TO_OBJECT(this), locales, options); 1041 return initializeCollator(TO_OBJECT(this), locales, options);
1046 } 1042 }
1047 ); 1043 );
1048 1044
1049 1045
1050 /** 1046 /**
1051 * Collator resolvedOptions method. 1047 * Collator resolvedOptions method.
1052 */ 1048 */
1053 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { 1049 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
1054 if (!IS_UNDEFINED(new.target)) {
1055 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1056 }
1057
1058 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { 1050 if (!%IsInitializedIntlObjectOfType(this, 'collator')) {
1059 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "Collator"); 1051 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "Collator");
1060 } 1052 }
1061 1053
1062 var coll = this; 1054 var coll = this;
1063 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, 1055 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale,
1064 coll[resolvedSymbol].locale); 1056 coll[resolvedSymbol].locale);
1065 1057
1066 return { 1058 return {
1067 locale: locale, 1059 locale: locale,
1068 usage: coll[resolvedSymbol].usage, 1060 usage: coll[resolvedSymbol].usage,
1069 sensitivity: coll[resolvedSymbol].sensitivity, 1061 sensitivity: coll[resolvedSymbol].sensitivity,
1070 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, 1062 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation,
1071 numeric: coll[resolvedSymbol].numeric, 1063 numeric: coll[resolvedSymbol].numeric,
1072 caseFirst: coll[resolvedSymbol].caseFirst, 1064 caseFirst: coll[resolvedSymbol].caseFirst,
1073 collation: coll[resolvedSymbol].collation 1065 collation: coll[resolvedSymbol].collation
1074 }; 1066 };
1075 } 1067 }
1076 ); 1068 );
1077 1069
1078 1070
1079 /** 1071 /**
1080 * Returns the subset of the given locale list for which this locale list 1072 * Returns the subset of the given locale list for which this locale list
1081 * has a matching (possibly fallback) locale. Locales appear in the same 1073 * has a matching (possibly fallback) locale. Locales appear in the same
1082 * order in the returned list as in the input list. 1074 * order in the returned list as in the input list.
1083 * Options are optional parameter. 1075 * Options are optional parameter.
1084 */ 1076 */
1085 InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) { 1077 InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) {
1086 if (!IS_UNDEFINED(new.target)) {
1087 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1088 }
1089
1090 return supportedLocalesOf('collator', locales, arguments[1]); 1078 return supportedLocalesOf('collator', locales, arguments[1]);
1091 } 1079 }
1092 ); 1080 );
1093 1081
1094 1082
1095 /** 1083 /**
1096 * When the compare method is called with two arguments x and y, it returns a 1084 * When the compare method is called with two arguments x and y, it returns a
1097 * Number other than NaN that represents the result of a locale-sensitive 1085 * Number other than NaN that represents the result of a locale-sensitive
1098 * String comparison of x with y. 1086 * String comparison of x with y.
1099 * The result is intended to order String values in the sort order specified 1087 * The result is intended to order String values in the sort order specified
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1273
1286 return initializeNumberFormat(TO_OBJECT(this), locales, options); 1274 return initializeNumberFormat(TO_OBJECT(this), locales, options);
1287 } 1275 }
1288 ); 1276 );
1289 1277
1290 1278
1291 /** 1279 /**
1292 * NumberFormat resolvedOptions method. 1280 * NumberFormat resolvedOptions method.
1293 */ 1281 */
1294 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { 1282 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
1295 if (!IS_UNDEFINED(new.target)) {
1296 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1297 }
1298
1299 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { 1283 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) {
1300 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "NumberFormat"); 1284 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "NumberFormat");
1301 } 1285 }
1302 1286
1303 var format = this; 1287 var format = this;
1304 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, 1288 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale,
1305 format[resolvedSymbol].locale); 1289 format[resolvedSymbol].locale);
1306 1290
1307 var result = { 1291 var result = {
1308 locale: locale, 1292 locale: locale,
(...skipping 26 matching lines...) Expand all
1335 ); 1319 );
1336 1320
1337 1321
1338 /** 1322 /**
1339 * Returns the subset of the given locale list for which this locale list 1323 * Returns the subset of the given locale list for which this locale list
1340 * has a matching (possibly fallback) locale. Locales appear in the same 1324 * has a matching (possibly fallback) locale. Locales appear in the same
1341 * order in the returned list as in the input list. 1325 * order in the returned list as in the input list.
1342 * Options are optional parameter. 1326 * Options are optional parameter.
1343 */ 1327 */
1344 InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { 1328 InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
1345 if (!IS_UNDEFINED(new.target)) {
1346 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1347 }
1348
1349 return supportedLocalesOf('numberformat', locales, arguments[1]); 1329 return supportedLocalesOf('numberformat', locales, arguments[1]);
1350 } 1330 }
1351 ); 1331 );
1352 1332
1353 1333
1354 /** 1334 /**
1355 * Returns a String value representing the result of calling ToNumber(value) 1335 * Returns a String value representing the result of calling ToNumber(value)
1356 * according to the effective locale and the formatting options of this 1336 * according to the effective locale and the formatting options of this
1357 * NumberFormat. 1337 * NumberFormat.
1358 */ 1338 */
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 1647
1668 return initializeDateTimeFormat(TO_OBJECT(this), locales, options); 1648 return initializeDateTimeFormat(TO_OBJECT(this), locales, options);
1669 } 1649 }
1670 ); 1650 );
1671 1651
1672 1652
1673 /** 1653 /**
1674 * DateTimeFormat resolvedOptions method. 1654 * DateTimeFormat resolvedOptions method.
1675 */ 1655 */
1676 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { 1656 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
1677 if (!IS_UNDEFINED(new.target)) {
1678 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1679 }
1680
1681 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { 1657 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
1682 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "DateTimeFormat" ); 1658 throw %make_type_error(kResolvedOptionsCalledOnNonObject, "DateTimeFormat" );
1683 } 1659 }
1684 1660
1685 /** 1661 /**
1686 * Maps ICU calendar names to LDML/BCP47 types for key 'ca'. 1662 * Maps ICU calendar names to LDML/BCP47 types for key 'ca'.
1687 * See typeMap section in third_party/icu/source/data/misc/keyTypeData.txt 1663 * See typeMap section in third_party/icu/source/data/misc/keyTypeData.txt
1688 * and 1664 * and
1689 * http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml 1665 * http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml
1690 */ 1666 */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 ); 1703 );
1728 1704
1729 1705
1730 /** 1706 /**
1731 * Returns the subset of the given locale list for which this locale list 1707 * Returns the subset of the given locale list for which this locale list
1732 * has a matching (possibly fallback) locale. Locales appear in the same 1708 * has a matching (possibly fallback) locale. Locales appear in the same
1733 * order in the returned list as in the input list. 1709 * order in the returned list as in the input list.
1734 * Options are optional parameter. 1710 * Options are optional parameter.
1735 */ 1711 */
1736 InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { 1712 InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
1737 if (!IS_UNDEFINED(new.target)) {
1738 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1739 }
1740
1741 return supportedLocalesOf('dateformat', locales, arguments[1]); 1713 return supportedLocalesOf('dateformat', locales, arguments[1]);
1742 } 1714 }
1743 ); 1715 );
1744 1716
1745 1717
1746 /** 1718 /**
1747 * Returns a String value representing the result of calling ToNumber(date) 1719 * Returns a String value representing the result of calling ToNumber(date)
1748 * according to the effective locale and the formatting options of this 1720 * according to the effective locale and the formatting options of this
1749 * DateTimeFormat. 1721 * DateTimeFormat.
1750 */ 1722 */
1751 function formatDate(formatter, dateValue) { 1723 function formatDate(formatter, dateValue) {
1752 var dateMs; 1724 var dateMs;
1753 if (IS_UNDEFINED(dateValue)) { 1725 if (IS_UNDEFINED(dateValue)) {
1754 dateMs = %DateCurrentTime(); 1726 dateMs = %DateCurrentTime();
1755 } else { 1727 } else {
1756 dateMs = TO_NUMBER(dateValue); 1728 dateMs = TO_NUMBER(dateValue);
1757 } 1729 }
1758 1730
1759 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); 1731 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
1760 1732
1761 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), 1733 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter),
1762 new GlobalDate(dateMs)); 1734 new GlobalDate(dateMs));
1763 } 1735 }
1764 1736
1765 function FormatDateToParts(dateValue) { 1737 function FormatDateToParts(dateValue) {
1766 if (!IS_UNDEFINED(new.target)) {
1767 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
1768 }
1769 CHECK_OBJECT_COERCIBLE(this, "Intl.DateTimeFormat.prototype.formatToParts"); 1738 CHECK_OBJECT_COERCIBLE(this, "Intl.DateTimeFormat.prototype.formatToParts");
1770 if (!IS_OBJECT(this)) { 1739 if (!IS_OBJECT(this)) {
1771 throw %make_type_error(kCalledOnNonObject, this); 1740 throw %make_type_error(kCalledOnNonObject, this);
1772 } 1741 }
1773 var dateMs; 1742 var dateMs;
1774 if (IS_UNDEFINED(dateValue)) { 1743 if (IS_UNDEFINED(dateValue)) {
1775 dateMs = %DateCurrentTime(); 1744 dateMs = %DateCurrentTime();
1776 } else { 1745 } else {
1777 dateMs = TO_NUMBER(dateValue); 1746 dateMs = TO_NUMBER(dateValue);
1778 } 1747 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 } 2035 }
2067 return %StringLocaleConvertCase(s, isToUpper, 2036 return %StringLocaleConvertCase(s, isToUpper,
2068 CUSTOM_CASE_LANGUAGES[langIndex]); 2037 CUSTOM_CASE_LANGUAGES[langIndex]);
2069 } 2038 }
2070 2039
2071 /** 2040 /**
2072 * Compares this and that, and returns less than 0, 0 or greater than 0 value. 2041 * Compares this and that, and returns less than 0, 0 or greater than 0 value.
2073 * Overrides the built-in method. 2042 * Overrides the built-in method.
2074 */ 2043 */
2075 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { 2044 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
2076 if (!IS_UNDEFINED(new.target)) {
2077 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2078 }
2079
2080 if (IS_NULL_OR_UNDEFINED(this)) { 2045 if (IS_NULL_OR_UNDEFINED(this)) {
2081 throw %make_type_error(kMethodInvokedOnNullOrUndefined); 2046 throw %make_type_error(kMethodInvokedOnNullOrUndefined);
2082 } 2047 }
2083 2048
2084 var locales = arguments[1]; 2049 var locales = arguments[1];
2085 var options = arguments[2]; 2050 var options = arguments[2];
2086 var collator = cachedOrNewService('collator', locales, options); 2051 var collator = cachedOrNewService('collator', locales, options);
2087 return compare(collator, this, that); 2052 return compare(collator, this, that);
2088 } 2053 }
2089 ); 2054 );
2090 2055
2091 2056
2092 /** 2057 /**
2093 * Unicode normalization. This method is called with one argument that 2058 * Unicode normalization. This method is called with one argument that
2094 * specifies the normalization form. 2059 * specifies the normalization form.
2095 * If none is specified, "NFC" is assumed. 2060 * If none is specified, "NFC" is assumed.
2096 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw 2061 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
2097 * a RangeError Exception. 2062 * a RangeError Exception.
2098 */ 2063 */
2099 2064
2100 OverrideFunction(GlobalString.prototype, 'normalize', function() { 2065 OverrideFunction(GlobalString.prototype, 'normalize', function() {
2101 if (!IS_UNDEFINED(new.target)) {
2102 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2103 }
2104
2105 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); 2066 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
2106 var s = TO_STRING(this); 2067 var s = TO_STRING(this);
2107 2068
2108 var formArg = arguments[0]; 2069 var formArg = arguments[0];
2109 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg); 2070 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg);
2110 2071
2111 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; 2072 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
2112 2073
2113 var normalizationForm = %ArrayIndexOf(NORMALIZATION_FORMS, form, 0); 2074 var normalizationForm = %ArrayIndexOf(NORMALIZATION_FORMS, form, 0);
2114 if (normalizationForm === -1) { 2075 if (normalizationForm === -1) {
2115 throw %make_range_error(kNormalizationForm, 2076 throw %make_range_error(kNormalizationForm,
2116 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', ')); 2077 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', '));
2117 } 2078 }
2118 2079
2119 return %StringNormalize(s, normalizationForm); 2080 return %StringNormalize(s, normalizationForm);
2120 } 2081 }
2121 ); 2082 );
2122 2083
2123 function ToLowerCaseI18N() { 2084 function ToLowerCaseI18N() {
2124 if (!IS_UNDEFINED(new.target)) {
2125 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2126 }
jungshik at Google 2016/12/19 20:56:09 I dropped the check in To(Locale){Lower,Upper}Case
2127 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); 2085 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
2128 var s = TO_STRING(this); 2086 var s = TO_STRING(this);
2129 return %StringToLowerCaseI18N(s); 2087 return %StringToLowerCaseI18N(s);
2130 } 2088 }
2131 2089
2132 function ToUpperCaseI18N() { 2090 function ToUpperCaseI18N() {
2133 if (!IS_UNDEFINED(new.target)) {
2134 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2135 }
2136 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); 2091 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase");
2137 var s = TO_STRING(this); 2092 var s = TO_STRING(this);
2138 return %StringToUpperCaseI18N(s); 2093 return %StringToUpperCaseI18N(s);
2139 } 2094 }
2140 2095
2141 function ToLocaleLowerCaseI18N(locales) { 2096 function ToLocaleLowerCaseI18N(locales) {
2142 if (!IS_UNDEFINED(new.target)) {
2143 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2144 }
2145 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); 2097 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase");
2146 return LocaleConvertCase(TO_STRING(this), locales, false); 2098 return LocaleConvertCase(TO_STRING(this), locales, false);
2147 } 2099 }
2148 2100
2149 %FunctionSetLength(ToLocaleLowerCaseI18N, 0); 2101 %FunctionSetLength(ToLocaleLowerCaseI18N, 0);
2150 2102
2151 function ToLocaleUpperCaseI18N(locales) { 2103 function ToLocaleUpperCaseI18N(locales) {
2152 if (!IS_UNDEFINED(new.target)) {
2153 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2154 }
2155 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); 2104 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase");
2156 return LocaleConvertCase(TO_STRING(this), locales, true); 2105 return LocaleConvertCase(TO_STRING(this), locales, true);
2157 } 2106 }
2158 2107
2159 %FunctionSetLength(ToLocaleUpperCaseI18N, 0); 2108 %FunctionSetLength(ToLocaleUpperCaseI18N, 0);
2160 2109
2161 %FunctionRemovePrototype(ToLowerCaseI18N); 2110 %FunctionRemovePrototype(ToLowerCaseI18N);
2162 %FunctionRemovePrototype(ToUpperCaseI18N); 2111 %FunctionRemovePrototype(ToUpperCaseI18N);
2163 %FunctionRemovePrototype(ToLocaleLowerCaseI18N); 2112 %FunctionRemovePrototype(ToLocaleLowerCaseI18N);
2164 %FunctionRemovePrototype(ToLocaleUpperCaseI18N); 2113 %FunctionRemovePrototype(ToLocaleUpperCaseI18N);
2165 2114
2166 utils.Export(function(to) { 2115 utils.Export(function(to) {
2167 to.ToLowerCaseI18N = ToLowerCaseI18N; 2116 to.ToLowerCaseI18N = ToLowerCaseI18N;
2168 to.ToUpperCaseI18N = ToUpperCaseI18N; 2117 to.ToUpperCaseI18N = ToUpperCaseI18N;
2169 to.ToLocaleLowerCaseI18N = ToLocaleLowerCaseI18N; 2118 to.ToLocaleLowerCaseI18N = ToLocaleLowerCaseI18N;
2170 to.ToLocaleUpperCaseI18N = ToLocaleUpperCaseI18N; 2119 to.ToLocaleUpperCaseI18N = ToLocaleUpperCaseI18N;
2171 }); 2120 });
2172 2121
2173 2122
2174 /** 2123 /**
2175 * Formats a Number object (this) using locale and options values. 2124 * Formats a Number object (this) using locale and options values.
2176 * If locale or options are omitted, defaults are used. 2125 * If locale or options are omitted, defaults are used.
2177 */ 2126 */
2178 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { 2127 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
2179 if (!IS_UNDEFINED(new.target)) {
2180 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2181 }
2182
2183 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { 2128 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
2184 throw %make_type_error(kMethodInvokedOnWrongType, "Number"); 2129 throw %make_type_error(kMethodInvokedOnWrongType, "Number");
2185 } 2130 }
2186 2131
2187 var locales = arguments[0]; 2132 var locales = arguments[0];
2188 var options = arguments[1]; 2133 var options = arguments[1];
2189 var numberFormat = cachedOrNewService('numberformat', locales, options); 2134 var numberFormat = cachedOrNewService('numberformat', locales, options);
2190 return formatNumber(numberFormat, this); 2135 return formatNumber(numberFormat, this);
2191 } 2136 }
2192 ); 2137 );
(...skipping 18 matching lines...) Expand all
2211 return formatDate(dateFormat, date); 2156 return formatDate(dateFormat, date);
2212 } 2157 }
2213 2158
2214 2159
2215 /** 2160 /**
2216 * Formats a Date object (this) using locale and options values. 2161 * Formats a Date object (this) using locale and options values.
2217 * If locale or options are omitted, defaults are used - both date and time are 2162 * If locale or options are omitted, defaults are used - both date and time are
2218 * present in the output. 2163 * present in the output.
2219 */ 2164 */
2220 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { 2165 OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
2221 if (!IS_UNDEFINED(new.target)) {
2222 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2223 }
2224
2225 var locales = arguments[0]; 2166 var locales = arguments[0];
2226 var options = arguments[1]; 2167 var options = arguments[1];
2227 return toLocaleDateTime( 2168 return toLocaleDateTime(
2228 this, locales, options, 'any', 'all', 'dateformatall'); 2169 this, locales, options, 'any', 'all', 'dateformatall');
2229 } 2170 }
2230 ); 2171 );
2231 2172
2232 2173
2233 /** 2174 /**
2234 * Formats a Date object (this) using locale and options values. 2175 * Formats a Date object (this) using locale and options values.
2235 * If locale or options are omitted, defaults are used - only date is present 2176 * If locale or options are omitted, defaults are used - only date is present
2236 * in the output. 2177 * in the output.
2237 */ 2178 */
2238 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { 2179 OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
2239 if (!IS_UNDEFINED(new.target)) {
2240 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2241 }
2242
2243 var locales = arguments[0]; 2180 var locales = arguments[0];
2244 var options = arguments[1]; 2181 var options = arguments[1];
2245 return toLocaleDateTime( 2182 return toLocaleDateTime(
2246 this, locales, options, 'date', 'date', 'dateformatdate'); 2183 this, locales, options, 'date', 'date', 'dateformatdate');
2247 } 2184 }
2248 ); 2185 );
2249 2186
2250 2187
2251 /** 2188 /**
2252 * Formats a Date object (this) using locale and options values. 2189 * Formats a Date object (this) using locale and options values.
2253 * If locale or options are omitted, defaults are used - only time is present 2190 * If locale or options are omitted, defaults are used - only time is present
2254 * in the output. 2191 * in the output.
2255 */ 2192 */
2256 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { 2193 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
2257 if (!IS_UNDEFINED(new.target)) {
2258 throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
2259 }
2260
2261 var locales = arguments[0]; 2194 var locales = arguments[0];
2262 var options = arguments[1]; 2195 var options = arguments[1];
2263 return toLocaleDateTime( 2196 return toLocaleDateTime(
2264 this, locales, options, 'time', 'time', 'dateformattime'); 2197 this, locales, options, 'time', 'time', 'dateformattime');
2265 } 2198 }
2266 ); 2199 );
2267 2200
2268 %FunctionRemovePrototype(FormatDateToParts); 2201 %FunctionRemovePrototype(FormatDateToParts);
2269 2202
2270 utils.Export(function(to) { 2203 utils.Export(function(to) {
2271 to.FormatDateToParts = FormatDateToParts; 2204 to.FormatDateToParts = FormatDateToParts;
2272 }); 2205 });
2273 2206
2274 }) 2207 })
OLDNEW
« no previous file with comments | « no previous file | test/intl/not-constructors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698