Commit 511b7cb5 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Fix order of NumberFormat resolvedOptions

Change the order of creating property for the return object
of Intl.NumberFormat.property.resolvedOptions()
according to the table in the spec.
This is due to spec change in from "any order" to "table "
in https://github.com/tc39/ecma402/pull/279
Failure w/o fixing it will happen once we land
test262/intl402/NumberFormat/prototype/resolvedOptions/order

Bug: v8:8378
Change-Id: Ic68fcfeba78af87d9bbd13c935ad9a91e76f4965
Reviewed-on: https://chromium-review.googlesource.com/c/1303195
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57195}
parent 18ac1468
...@@ -60,14 +60,13 @@ bool IsWellFormedCurrencyCode(const std::string& currency) { ...@@ -60,14 +60,13 @@ bool IsWellFormedCurrencyCode(const std::string& currency) {
} // anonymous namespace } // anonymous namespace
// static // static
// ecma402 #sec-intl.numberformat.prototype.resolvedoptions
Handle<JSObject> JSNumberFormat::ResolvedOptions( Handle<JSObject> JSNumberFormat::ResolvedOptions(
Isolate* isolate, Handle<JSNumberFormat> number_format_holder) { Isolate* isolate, Handle<JSNumberFormat> number_format_holder) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
// 4. Let options be ! ObjectCreate(%ObjectPrototype%).
Handle<JSObject> options = factory->NewJSObject(isolate->object_function()); Handle<JSObject> options = factory->NewJSObject(isolate->object_function());
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->style_string(),
number_format_holder->StyleAsString(), kDontThrow)
.FromJust());
icu::NumberFormat* number_format = icu::NumberFormat* number_format =
number_format_holder->icu_number_format()->raw(); number_format_holder->icu_number_format()->raw();
...@@ -78,14 +77,30 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions( ...@@ -78,14 +77,30 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
Handle<String> locale = Handle<String> locale =
Handle<String>(number_format_holder->locale(), isolate); Handle<String>(number_format_holder->locale(), isolate);
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->locale_string(), locale, kDontThrow)
.FromJust());
UErrorCode error = U_ZERO_ERROR; UErrorCode error = U_ZERO_ERROR;
icu::Locale icu_locale = number_format->getLocale(ULOC_VALID_LOCALE, error); icu::Locale icu_locale = number_format->getLocale(ULOC_VALID_LOCALE, error);
DCHECK(U_SUCCESS(error)); DCHECK(U_SUCCESS(error));
std::string numbering_system = Intl::GetNumberingSystem(icu_locale); std::string numbering_system = Intl::GetNumberingSystem(icu_locale);
// 5. For each row of Table 4, except the header row, in table order, do
// Table 4: Resolved Options of NumberFormat Instances
// Internal Slot Property
// [[Locale]] "locale"
// [[NumberingSystem]] "numberingSystem"
// [[Style]] "style"
// [[Currency]] "currency"
// [[CurrencyDisplay]] "currencyDisplay"
// [[MinimumIntegerDigits]] "minimumIntegerDigits"
// [[MinimumFractionDigits]] "minimumFractionDigits"
// [[MaximumFractionDigits]] "maximumFractionDigits"
// [[MinimumSignificantDigits]] "minimumSignificantDigits"
// [[MaximumSignificantDigits]] "maximumSignificantDigits"
// [[UseGrouping]] "useGrouping"
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->locale_string(), locale, kDontThrow)
.FromJust());
if (!numbering_system.empty()) { if (!numbering_system.empty()) {
CHECK(JSReceiver::CreateDataProperty( CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->numberingSystem_string(), isolate, options, factory->numberingSystem_string(),
...@@ -93,12 +108,11 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions( ...@@ -93,12 +108,11 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
kDontThrow) kDontThrow)
.FromJust()); .FromJust());
} }
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->style_string(),
number_format_holder->StyleAsString(), kDontThrow)
.FromJust());
if (number_format_holder->style() == Style::CURRENCY) { if (number_format_holder->style() == Style::CURRENCY) {
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->currencyDisplay_string(),
number_format_holder->CurrencyDisplayAsString(), kDontThrow)
.FromJust());
icu::UnicodeString currency(number_format->getCurrency()); icu::UnicodeString currency(number_format->getCurrency());
DCHECK(!currency.isEmpty()); DCHECK(!currency.isEmpty());
CHECK(JSReceiver::CreateDataProperty( CHECK(JSReceiver::CreateDataProperty(
...@@ -110,8 +124,12 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions( ...@@ -110,8 +124,12 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
.ToHandleChecked(), .ToHandleChecked(),
kDontThrow) kDontThrow)
.FromJust()); .FromJust());
}
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->currencyDisplay_string(),
number_format_holder->CurrencyDisplayAsString(), kDontThrow)
.FromJust());
}
CHECK(JSReceiver::CreateDataProperty( CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->minimumIntegerDigits_string(), isolate, options, factory->minimumIntegerDigits_string(),
factory->NewNumberFromInt(number_format->getMinimumIntegerDigits()), factory->NewNumberFromInt(number_format->getMinimumIntegerDigits()),
...@@ -148,7 +166,6 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions( ...@@ -148,7 +166,6 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
factory->ToBoolean((number_format->isGroupingUsed() == TRUE)), factory->ToBoolean((number_format->isGroupingUsed() == TRUE)),
kDontThrow) kDontThrow)
.FromJust()); .FromJust());
return options; return options;
} }
......
...@@ -75,7 +75,6 @@ ...@@ -75,7 +75,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=8378 # https://bugs.chromium.org/p/v8/issues/detail?id=8378
'intl402/DateTimeFormat/prototype/resolvedOptions/order': [FAIL], 'intl402/DateTimeFormat/prototype/resolvedOptions/order': [FAIL],
'intl402/NumberFormat/prototype/resolvedOptions/order': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4251 # https://code.google.com/p/v8/issues/detail?id=4251
'language/expressions/postfix-increment/S11.3.1_A5_T1': [FAIL], 'language/expressions/postfix-increment/S11.3.1_A5_T1': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment