Commit 1f17cfae authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Change the order of the DateTimeFormat resolved

Move fractionalSecondsDigits between second and timeZoneName
Change order of reading options.
To sync with the July 20 PR change in
https://github.com/tc39/ecma402/commit/ba085a91117d4da403b8ece9cb59589091806e59
Latest ECMA402 PR https://github.com/tc39/ecma402/pull/347

Bug: v8:10836
Change-Id: Ia414e0c7cc18502ccabaf02abd19861410b87cae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2378460Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69591}
parent fc213390
......@@ -568,8 +568,8 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
// [[Hour]] "hour"
// [[Minute]] "minute"
// [[Second]] "second"
// [[TimeZoneName]] "timeZoneName"
// [[FractionalSecondDigits]] "fractionalSecondDigits"
// [[TimeZoneName]] "timeZoneName"
Maybe<bool> maybe_create_locale = JSReceiver::CreateDataProperty(
isolate, options, factory->locale_string(), locale, Just(kDontThrow));
DCHECK(maybe_create_locale.FromJust());
......@@ -636,6 +636,18 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
if (date_time_format->date_style() == DateTimeStyle::kUndefined &&
date_time_format->time_style() == DateTimeStyle::kUndefined) {
for (const auto& item : GetPatternItems()) {
// fractionalSecondsDigits need to be added before timeZoneName
if (item.property == "timeZoneName") {
int fsd = FractionalSecondDigitsFromPattern(pattern);
if (fsd > 0) {
Maybe<bool> maybe_create_fractional_seconds_digits =
JSReceiver::CreateDataProperty(
isolate, options, factory->fractionalSecondDigits_string(),
factory->NewNumberFromInt(fsd), Just(kDontThrow));
DCHECK(maybe_create_fractional_seconds_digits.FromJust());
USE(maybe_create_fractional_seconds_digits);
}
}
for (const auto& pair : item.pairs) {
if (pattern.find(pair.pattern) != std::string::npos) {
Maybe<bool> maybe_create_property = JSReceiver::CreateDataProperty(
......@@ -649,15 +661,6 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
}
}
}
int fsd = FractionalSecondDigitsFromPattern(pattern);
if (fsd > 0) {
Maybe<bool> maybe_create_fractional_seconds_digits =
JSReceiver::CreateDataProperty(
isolate, options, factory->fractionalSecondDigits_string(),
factory->NewNumberFromInt(fsd), Just(kDontThrow));
DCHECK(maybe_create_fractional_seconds_digits.FromJust());
USE(maybe_create_fractional_seconds_digits);
}
}
// dateStyle
......@@ -1653,6 +1656,19 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
bool has_hour_option = false;
std::string skeleton;
for (const PatternData& item : GetPatternData(hc)) {
// Need to read fractionalSecondDigits before reading the timeZoneName
if (item.property == "timeZoneName") {
// Let _value_ be ? GetNumberOption(options, "fractionalSecondDigits", 1,
// 3, *undefined*). The *undefined* is represented by value 0 here.
Maybe<int> maybe_fsd = Intl::GetNumberOption(
isolate, options, factory->fractionalSecondDigits_string(), 1, 3, 0);
MAYBE_RETURN(maybe_fsd, MaybeHandle<JSDateTimeFormat>());
// Convert fractionalSecondDigits to skeleton.
int fsd = maybe_fsd.FromJust();
for (int i = 0; i < fsd; i++) {
skeleton += "S";
}
}
std::unique_ptr<char[]> input;
// i. Let prop be the name given in the Property column of the row.
// ii. Let value be ? GetOption(options, prop, "string", « the strings
......@@ -1670,16 +1686,6 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
skeleton += item.map.find(input.get())->second;
}
}
// Let _value_ be ? GetNumberOption(options, "fractionalSecondDigits", 1, 3,
// *undefined*). The *undefined* is represented by value 0 here.
Maybe<int> maybe_fsd = Intl::GetNumberOption(
isolate, options, factory->fractionalSecondDigits_string(), 1, 3, 0);
MAYBE_RETURN(maybe_fsd, MaybeHandle<JSDateTimeFormat>());
// Convert fractionalSecondDigits to skeleton.
int fsd = maybe_fsd.FromJust();
for (int i = 0; i < fsd; i++) {
skeleton += "S";
}
// 29. Let matcher be ? GetOption(options, "formatMatcher", "string", «
// "basic", "best fit" », "best fit").
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Verify the order of resolvedOptions()
let df = new Intl.DateTimeFormat("en", {
weekday: "narrow",
era: "narrow",
year: "2-digit",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
fractionalSecondDigits: 2,
timeZoneName: "short"});
let resolvedOptionsKeys = Object.keys(df.resolvedOptions()).join(":");
assertEquals(
"locale:calendar:numberingSystem:timeZone:hourCycle:hour12:weekday:era:" +
"year:month:day:hour:minute:second:fractionalSecondDigits:timeZoneName",
resolvedOptionsKeys);
// Verify the order of reading the options.
let read = [];
let options = {
get second() {
read.push("second");
return undefined;
},
get fractionalSecondDigits() {
read.push("fractionalSecondDigits");
return undefined;
},
get timeZoneName() {
read.push("timeZoneName");
return undefined;
}
};
df = new Intl.DateTimeFormat("en", options);
assertEquals(
"second:fractionalSecondDigits:second:fractionalSecondDigits:timeZoneName",
read.join(":"));
......@@ -453,6 +453,9 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=7472
'intl402/NumberFormat/currency-digits': [FAIL],
# http://crbug/v8/10836
'intl402/DateTimeFormat/constructor-options-order-fractionalSecondDigits': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7831
'language/statements/generators/generator-created-after-decl-inst': [FAIL],
'language/expressions/generators/generator-created-after-decl-inst': [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