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

Unified Diff: src/js/i18n.js

Issue 2717613005: [intl] Fix NumberFormat options handling spec compliance issues (Closed)
Patch Set: Remove test262 failure expectation line Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/i18n.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/i18n.js
diff --git a/src/js/i18n.js b/src/js/i18n.js
index 4d56dd0623777f63e1b2f3df5aa49f06a0186f1e..4323cf6e8af526f03157513b61d4a556560dd8f5 100644
--- a/src/js/i18n.js
+++ b/src/js/i18n.js
@@ -32,6 +32,7 @@ var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol");
var InstallFunctions = utils.InstallFunctions;
var InstallGetter = utils.InstallGetter;
var InternalArray = utils.InternalArray;
+var MaxSimple;
var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty");
var OverrideFunction = utils.OverrideFunction;
var patternSymbol = utils.ImportNow("intl_pattern_symbol");
@@ -43,6 +44,7 @@ var StringSubstring = GlobalString.prototype.substring;
utils.Import(function(from) {
ArrayJoin = from.ArrayJoin;
ArrayPush = from.ArrayPush;
+ MaxSimple = from.MaxSimple;
});
// Utilities for definitions
@@ -934,16 +936,6 @@ function BuildLanguageTagREs() {
LANGUAGE_TAG_RE = new GlobalRegExp(languageTag, 'i');
}
-var resolvedAccessor = {
- get() {
- %IncrementUseCounter(kIntlResolved);
- return this[resolvedSymbol];
- },
- set(value) {
- this[resolvedSymbol] = value;
- }
-};
-
// ECMA 402 section 8.2.1
InstallFunction(GlobalIntl, 'getCanonicalLocales', function(locales) {
return makeArray(canonicalizeLocaleList(locales));
@@ -1137,7 +1129,6 @@ function defaultNumberOption(value, min, max, fallback, property) {
return fallback;
}
-
/**
* Returns the valid digit count for a property, or throws RangeError on
* a value out of the range.
@@ -1147,15 +1138,35 @@ function getNumberOption(options, property, min, max, fallback) {
return defaultNumberOption(value, min, max, fallback, property);
}
-var patternAccessor = {
- get() {
- %IncrementUseCounter(kIntlPattern);
- return this[patternSymbol];
- },
- set(value) {
- this[patternSymbol] = value;
+// ECMA 402 #sec-setnfdigitoptions
+// SetNumberFormatDigitOptions ( intlObj, options, mnfdDefault, mxfdDefault )
+function SetNumberFormatDigitOptions(internalOptions, options,
+ mnfdDefault, mxfdDefault) {
+ // Digit ranges.
+ var mnid = getNumberOption(options, 'minimumIntegerDigits', 1, 21, 1);
+ defineWEProperty(internalOptions, 'minimumIntegerDigits', mnid);
+
+ var mnfd = getNumberOption(options, 'minimumFractionDigits', 0, 20,
+ mnfdDefault);
+ defineWEProperty(internalOptions, 'minimumFractionDigits', mnfd);
+
+ var mxfdActualDefault = MaxSimple(mnfd, mxfdDefault);
+
+ var mxfd = getNumberOption(options, 'maximumFractionDigits', mnfd, 20,
+ mxfdActualDefault);
+
+ defineWEProperty(internalOptions, 'maximumFractionDigits', mxfd);
+
+ var mnsd = options['minimumSignificantDigits'];
+ var mxsd = options['maximumSignificantDigits'];
+ if (!IS_UNDEFINED(mnsd) || !IS_UNDEFINED(mxsd)) {
+ mnsd = defaultNumberOption(mnsd, 1, 21, 1, 'minimumSignificantDigits');
+ defineWEProperty(internalOptions, 'minimumSignificantDigits', mnsd);
+
+ mxsd = defaultNumberOption(mxsd, mnsd, 21, 21, 'maximumSignificantDigits');
+ defineWEProperty(internalOptions, 'maximumSignificantDigits', mxsd);
}
-};
+}
/**
* Initializes the given object so it's a valid NumberFormat instance.
@@ -1183,41 +1194,22 @@ function CreateNumberFormat(locales, options) {
throw %make_type_error(kCurrencyCode);
}
+ var mnfdDefault, mxfdDefault;
+
var currencyDisplay = getOption(
'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol');
if (internalOptions.style === 'currency') {
defineWEProperty(internalOptions, 'currency', %StringToUpperCaseI18N(currency));
defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay);
- }
-
- // Digit ranges.
- var mnid = getNumberOption(options, 'minimumIntegerDigits', 1, 21, 1);
- defineWEProperty(internalOptions, 'minimumIntegerDigits', mnid);
-
- var mnfd = options['minimumFractionDigits'];
- var mxfd = options['maximumFractionDigits'];
- if (!IS_UNDEFINED(mnfd) || internalOptions.style !== 'currency') {
- mnfd = getNumberOption(options, 'minimumFractionDigits', 0, 20, 0);
- defineWEProperty(internalOptions, 'minimumFractionDigits', mnfd);
- }
- if (!IS_UNDEFINED(mxfd) || internalOptions.style !== 'currency') {
- var min_mxfd = internalOptions.style === 'percent' ? 0 : 3;
- mnfd = IS_UNDEFINED(mnfd) ? 0 : mnfd;
- var fallback_limit = (mnfd > min_mxfd) ? mnfd : min_mxfd;
- mxfd = getNumberOption(options, 'maximumFractionDigits', mnfd, 20, fallback_limit);
- defineWEProperty(internalOptions, 'maximumFractionDigits', mxfd);
+ mnfdDefault = mxfdDefault = %CurrencyDigits(internalOptions.currency);
+ } else {
+ mnfdDefault = 0;
+ mxfdDefault = internalOptions.style === 'percent' ? 0 : 3;
}
- var mnsd = options['minimumSignificantDigits'];
- var mxsd = options['maximumSignificantDigits'];
- if (!IS_UNDEFINED(mnsd) || !IS_UNDEFINED(mxsd)) {
- mnsd = defaultNumberOption(mnsd, 1, 21, 1, 'minimumSignificantDigits');
- defineWEProperty(internalOptions, 'minimumSignificantDigits', mnsd);
-
- mxsd = defaultNumberOption(mxsd, mnsd, 21, 21, 'maximumSignificantDigits');
- defineWEProperty(internalOptions, 'maximumSignificantDigits', mxsd);
- }
+ SetNumberFormatDigitOptions(internalOptions, options, mnfdDefault,
+ mxfdDefault);
// Grouping.
defineWEProperty(internalOptions, 'useGrouping', getOption(
« no previous file with comments | « src/i18n.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698