| OLD | NEW |
| 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 2035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 var normalizationForm = %ArrayIndexOf(NORMALIZATION_FORMS, form, 0); | 2046 var normalizationForm = %ArrayIndexOf(NORMALIZATION_FORMS, form, 0); |
| 2047 if (normalizationForm === -1) { | 2047 if (normalizationForm === -1) { |
| 2048 throw %make_range_error(kNormalizationForm, | 2048 throw %make_range_error(kNormalizationForm, |
| 2049 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', ')); | 2049 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', ')); |
| 2050 } | 2050 } |
| 2051 | 2051 |
| 2052 return %StringNormalize(s, normalizationForm); | 2052 return %StringNormalize(s, normalizationForm); |
| 2053 } | 2053 } |
| 2054 ); | 2054 ); |
| 2055 | 2055 |
| 2056 // TODO(littledan): Rewrite these two functions as direct builtins |
| 2056 function ToLowerCaseI18N() { | 2057 function ToLowerCaseI18N() { |
| 2057 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); | 2058 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); |
| 2058 return %StringToLowerCaseI18N(TO_STRING(this)); | 2059 return %StringToLowerCaseI18N(TO_STRING(this)); |
| 2059 } | 2060 } |
| 2060 | 2061 |
| 2061 function ToUpperCaseI18N() { | 2062 function ToUpperCaseI18N() { |
| 2062 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); | 2063 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); |
| 2063 return %StringToUpperCaseI18N(TO_STRING(this)); | 2064 return %StringToUpperCaseI18N(TO_STRING(this)); |
| 2064 } | 2065 } |
| 2065 | 2066 |
| 2066 function ToLocaleLowerCaseI18N(locales) { | 2067 function ToLocaleLowerCaseI18N(locales) { |
| 2067 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); | 2068 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); |
| 2068 return LocaleConvertCase(TO_STRING(this), locales, false); | 2069 return LocaleConvertCase(TO_STRING(this), locales, false); |
| 2069 } | 2070 } |
| 2070 | 2071 |
| 2071 %FunctionSetLength(ToLocaleLowerCaseI18N, 0); | 2072 %FunctionSetLength(ToLocaleLowerCaseI18N, 0); |
| 2072 | 2073 |
| 2073 function ToLocaleUpperCaseI18N(locales) { | 2074 function ToLocaleUpperCaseI18N(locales) { |
| 2074 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); | 2075 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); |
| 2075 return LocaleConvertCase(TO_STRING(this), locales, true); | 2076 return LocaleConvertCase(TO_STRING(this), locales, true); |
| 2076 } | 2077 } |
| 2077 | 2078 |
| 2078 %FunctionSetLength(ToLocaleUpperCaseI18N, 0); | 2079 %FunctionSetLength(ToLocaleUpperCaseI18N, 0); |
| 2079 | 2080 |
| 2080 %FunctionRemovePrototype(ToLowerCaseI18N); | |
| 2081 %FunctionRemovePrototype(ToUpperCaseI18N); | |
| 2082 %FunctionRemovePrototype(ToLocaleLowerCaseI18N); | |
| 2083 %FunctionRemovePrototype(ToLocaleUpperCaseI18N); | |
| 2084 | |
| 2085 utils.Export(function(to) { | |
| 2086 to.ToLowerCaseI18N = ToLowerCaseI18N; | |
| 2087 to.ToUpperCaseI18N = ToUpperCaseI18N; | |
| 2088 to.ToLocaleLowerCaseI18N = ToLocaleLowerCaseI18N; | |
| 2089 to.ToLocaleUpperCaseI18N = ToLocaleUpperCaseI18N; | |
| 2090 }); | |
| 2091 | |
| 2092 | 2081 |
| 2093 /** | 2082 /** |
| 2094 * Formats a Number object (this) using locale and options values. | 2083 * Formats a Number object (this) using locale and options values. |
| 2095 * If locale or options are omitted, defaults are used. | 2084 * If locale or options are omitted, defaults are used. |
| 2096 */ | 2085 */ |
| 2097 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { | 2086 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
| 2098 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { | 2087 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { |
| 2099 throw %make_type_error(kMethodInvokedOnWrongType, "Number"); | 2088 throw %make_type_error(kMethodInvokedOnWrongType, "Number"); |
| 2100 } | 2089 } |
| 2101 | 2090 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2162 */ | 2151 */ |
| 2163 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { | 2152 OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { |
| 2164 var locales = arguments[0]; | 2153 var locales = arguments[0]; |
| 2165 var options = arguments[1]; | 2154 var options = arguments[1]; |
| 2166 return toLocaleDateTime( | 2155 return toLocaleDateTime( |
| 2167 this, locales, options, 'time', 'time', 'dateformattime'); | 2156 this, locales, options, 'time', 'time', 'dateformattime'); |
| 2168 } | 2157 } |
| 2169 ); | 2158 ); |
| 2170 | 2159 |
| 2171 %FunctionRemovePrototype(FormatDateToParts); | 2160 %FunctionRemovePrototype(FormatDateToParts); |
| 2161 %FunctionRemovePrototype(ToLowerCaseI18N); |
| 2162 %FunctionRemovePrototype(ToUpperCaseI18N); |
| 2163 %FunctionRemovePrototype(ToLocaleLowerCaseI18N); |
| 2164 %FunctionRemovePrototype(ToLocaleUpperCaseI18N); |
| 2165 |
| 2166 utils.SetFunctionName(FormatDateToParts, "formatToParts"); |
| 2167 utils.SetFunctionName(ToLowerCaseI18N, "toLowerCase"); |
| 2168 utils.SetFunctionName(ToUpperCaseI18N, "toUpperCase"); |
| 2169 utils.SetFunctionName(ToLocaleLowerCaseI18N, "toLocaleLowerCase"); |
| 2170 utils.SetFunctionName(ToLocaleUpperCaseI18N, "toLocaleUpperCase"); |
| 2172 | 2171 |
| 2173 utils.Export(function(to) { | 2172 utils.Export(function(to) { |
| 2174 to.FormatDateToParts = FormatDateToParts; | 2173 to.FormatDateToParts = FormatDateToParts; |
| 2174 to.ToLowerCaseI18N = ToLowerCaseI18N; |
| 2175 to.ToUpperCaseI18N = ToUpperCaseI18N; |
| 2176 to.ToLocaleLowerCaseI18N = ToLocaleLowerCaseI18N; |
| 2177 to.ToLocaleUpperCaseI18N = ToLocaleUpperCaseI18N; |
| 2175 }); | 2178 }); |
| 2176 | 2179 |
| 2177 }) | 2180 }) |
| OLD | NEW |