| 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 */ |
| 11 (function() { | 11 (function() { |
| 12 | 12 |
| 13 "use strict"; | 13 "use strict"; |
| 14 | 14 |
| 15 %CheckIsBootstrapping(); | 15 %CheckIsBootstrapping(); |
| 16 | 16 |
| 17 var GlobalBoolean = global.Boolean; |
| 17 var GlobalDate = global.Date; | 18 var GlobalDate = global.Date; |
| 19 var GlobalNumber = global.Number; |
| 18 var GlobalRegExp = global.RegExp; | 20 var GlobalRegExp = global.RegExp; |
| 19 var GlobalString = global.String; | 21 var GlobalString = global.String; |
| 20 | 22 |
| 21 var undefined = global.undefined; | 23 var undefined = global.undefined; |
| 22 | 24 |
| 23 var Intl = {}; | 25 var Intl = {}; |
| 24 | 26 |
| 25 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); | 27 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
| 26 | 28 |
| 27 var AVAILABLE_SERVICES = ['collator', | 29 var AVAILABLE_SERVICES = ['collator', |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 if (options === undefined) { | 369 if (options === undefined) { |
| 368 throw new $Error('Internal ' + caller + ' error. ' + | 370 throw new $Error('Internal ' + caller + ' error. ' + |
| 369 'Default options are missing.'); | 371 'Default options are missing.'); |
| 370 } | 372 } |
| 371 | 373 |
| 372 var getOption = function getOption(property, type, values, defaultValue) { | 374 var getOption = function getOption(property, type, values, defaultValue) { |
| 373 if (options[property] !== undefined) { | 375 if (options[property] !== undefined) { |
| 374 var value = options[property]; | 376 var value = options[property]; |
| 375 switch (type) { | 377 switch (type) { |
| 376 case 'boolean': | 378 case 'boolean': |
| 377 value = $Boolean(value); | 379 value = GlobalBoolean(value); |
| 378 break; | 380 break; |
| 379 case 'string': | 381 case 'string': |
| 380 value = GlobalString(value); | 382 value = GlobalString(value); |
| 381 break; | 383 break; |
| 382 case 'number': | 384 case 'number': |
| 383 value = $Number(value); | 385 value = GlobalNumber(value); |
| 384 break; | 386 break; |
| 385 default: | 387 default: |
| 386 throw new $Error('Internal error. Wrong value type.'); | 388 throw new $Error('Internal error. Wrong value type.'); |
| 387 } | 389 } |
| 388 if (values !== undefined && values.indexOf(value) === -1) { | 390 if (values !== undefined && values.indexOf(value) === -1) { |
| 389 throw new $RangeError('Value ' + value + ' out of range for ' + caller + | 391 throw new $RangeError('Value ' + value + ' out of range for ' + caller + |
| 390 ' options property ' + property); | 392 ' options property ' + property); |
| 391 } | 393 } |
| 392 | 394 |
| 393 return value; | 395 return value; |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 } | 1051 } |
| 1050 | 1052 |
| 1051 | 1053 |
| 1052 /** | 1054 /** |
| 1053 * Returns the valid digit count for a property, or throws RangeError on | 1055 * Returns the valid digit count for a property, or throws RangeError on |
| 1054 * a value out of the range. | 1056 * a value out of the range. |
| 1055 */ | 1057 */ |
| 1056 function getNumberOption(options, property, min, max, fallback) { | 1058 function getNumberOption(options, property, min, max, fallback) { |
| 1057 var value = options[property]; | 1059 var value = options[property]; |
| 1058 if (value !== undefined) { | 1060 if (value !== undefined) { |
| 1059 value = $Number(value); | 1061 value = GlobalNumber(value); |
| 1060 if ($isNaN(value) || value < min || value > max) { | 1062 if ($isNaN(value) || value < min || value > max) { |
| 1061 throw new $RangeError(property + ' value is out of range.'); | 1063 throw new $RangeError(property + ' value is out of range.'); |
| 1062 } | 1064 } |
| 1063 return $floor(value); | 1065 return $floor(value); |
| 1064 } | 1066 } |
| 1065 | 1067 |
| 1066 return fallback; | 1068 return fallback; |
| 1067 } | 1069 } |
| 1068 | 1070 |
| 1069 | 1071 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); | 1267 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
| 1266 | 1268 |
| 1267 | 1269 |
| 1268 /** | 1270 /** |
| 1269 * Returns a String value representing the result of calling ToNumber(value) | 1271 * Returns a String value representing the result of calling ToNumber(value) |
| 1270 * according to the effective locale and the formatting options of this | 1272 * according to the effective locale and the formatting options of this |
| 1271 * NumberFormat. | 1273 * NumberFormat. |
| 1272 */ | 1274 */ |
| 1273 function formatNumber(formatter, value) { | 1275 function formatNumber(formatter, value) { |
| 1274 // Spec treats -0 and +0 as 0. | 1276 // Spec treats -0 and +0 as 0. |
| 1275 var number = $Number(value) + 0; | 1277 var number = GlobalNumber(value) + 0; |
| 1276 | 1278 |
| 1277 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), | 1279 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), |
| 1278 number); | 1280 number); |
| 1279 } | 1281 } |
| 1280 | 1282 |
| 1281 | 1283 |
| 1282 /** | 1284 /** |
| 1283 * Returns a Number that represents string value that was passed in. | 1285 * Returns a Number that represents string value that was passed in. |
| 1284 */ | 1286 */ |
| 1285 function parseNumber(formatter, value) { | 1287 function parseNumber(formatter, value) { |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 /** | 1663 /** |
| 1662 * Returns a String value representing the result of calling ToNumber(date) | 1664 * Returns a String value representing the result of calling ToNumber(date) |
| 1663 * according to the effective locale and the formatting options of this | 1665 * according to the effective locale and the formatting options of this |
| 1664 * DateTimeFormat. | 1666 * DateTimeFormat. |
| 1665 */ | 1667 */ |
| 1666 function formatDate(formatter, dateValue) { | 1668 function formatDate(formatter, dateValue) { |
| 1667 var dateMs; | 1669 var dateMs; |
| 1668 if (dateValue === undefined) { | 1670 if (dateValue === undefined) { |
| 1669 dateMs = GlobalDate.now(); | 1671 dateMs = GlobalDate.now(); |
| 1670 } else { | 1672 } else { |
| 1671 dateMs = $Number(dateValue); | 1673 dateMs = GlobalNumber(dateValue); |
| 1672 } | 1674 } |
| 1673 | 1675 |
| 1674 if (!$isFinite(dateMs)) { | 1676 if (!$isFinite(dateMs)) { |
| 1675 throw new $RangeError('Provided date is not in valid range.'); | 1677 throw new $RangeError('Provided date is not in valid range.'); |
| 1676 } | 1678 } |
| 1677 | 1679 |
| 1678 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), | 1680 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), |
| 1679 new GlobalDate(dateMs)); | 1681 new GlobalDate(dateMs)); |
| 1680 } | 1682 } |
| 1681 | 1683 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 | 1975 |
| 1974 return %StringNormalize(this, normalizationForm); | 1976 return %StringNormalize(this, normalizationForm); |
| 1975 } | 1977 } |
| 1976 ); | 1978 ); |
| 1977 | 1979 |
| 1978 | 1980 |
| 1979 /** | 1981 /** |
| 1980 * Formats a Number object (this) using locale and options values. | 1982 * Formats a Number object (this) using locale and options values. |
| 1981 * If locale or options are omitted, defaults are used. | 1983 * If locale or options are omitted, defaults are used. |
| 1982 */ | 1984 */ |
| 1983 OverrideFunction($Number.prototype, 'toLocaleString', function() { | 1985 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
| 1984 if (%_IsConstructCall()) { | 1986 if (%_IsConstructCall()) { |
| 1985 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | 1987 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
| 1986 } | 1988 } |
| 1987 | 1989 |
| 1988 if (!(this instanceof $Number) && typeof(this) !== 'number') { | 1990 if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { |
| 1989 throw new $TypeError('Method invoked on an object that is not Number.'); | 1991 throw new $TypeError('Method invoked on an object that is not Number.'); |
| 1990 } | 1992 } |
| 1991 | 1993 |
| 1992 var locales = %_Arguments(0); | 1994 var locales = %_Arguments(0); |
| 1993 var options = %_Arguments(1); | 1995 var options = %_Arguments(1); |
| 1994 var numberFormat = cachedOrNewService('numberformat', locales, options); | 1996 var numberFormat = cachedOrNewService('numberformat', locales, options); |
| 1995 return formatNumber(numberFormat, this); | 1997 return formatNumber(numberFormat, this); |
| 1996 } | 1998 } |
| 1997 ); | 1999 ); |
| 1998 | 2000 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 } | 2067 } |
| 2066 | 2068 |
| 2067 var locales = %_Arguments(0); | 2069 var locales = %_Arguments(0); |
| 2068 var options = %_Arguments(1); | 2070 var options = %_Arguments(1); |
| 2069 return toLocaleDateTime( | 2071 return toLocaleDateTime( |
| 2070 this, locales, options, 'time', 'time', 'dateformattime'); | 2072 this, locales, options, 'time', 'time', 'dateformattime'); |
| 2071 } | 2073 } |
| 2072 ); | 2074 ); |
| 2073 | 2075 |
| 2074 })(); | 2076 })(); |
| OLD | NEW |