Commit c75296f6 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[intl] Change the r/w order of fractionalSecondDigits

1. read and output into option after timeZoneName
2. Not output into resolvedOptions if dateStyle or timeStyle is presented.
3. Add unit test

Spec: https://github.com/tc39/ecma402/pull/347

Bug: v8:10438
Change-Id: Ie7fecdb5b6dc83dc9a6dfd8ced26679a4051c833
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2161509
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67344}
parent 9d36d8a3
......@@ -545,6 +545,7 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
// [[Minute]] "minute"
// [[Second]] "second"
// [[TimeZoneName]] "timeZoneName"
// [[FractionalSecondDigits]] "fractionalSecondDigits"
CHECK(JSReceiver::CreateDataProperty(isolate, options,
factory->locale_string(), locale,
Just(kDontThrow))
......@@ -615,6 +616,13 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
}
}
}
if (FLAG_harmony_intl_dateformat_fractional_second_digits) {
int fsd = FractionalSecondDigitsFromPattern(pattern);
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->fractionalSecondDigits_string(),
factory->NewNumberFromInt(fsd), Just(kDontThrow))
.FromJust());
}
}
// dateStyle
......@@ -634,14 +642,6 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
Just(kDontThrow))
.FromJust());
}
if (FLAG_harmony_intl_dateformat_fractional_second_digits) {
int fsd = FractionalSecondDigitsFromPattern(pattern);
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->fractionalSecondDigits_string(),
factory->NewNumberFromInt(fsd), Just(kDontThrow))
.FromJust());
}
return options;
}
......
// 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.
// Flags: --harmony_intl_dateformat_fractional_second_digits
assertEquals(
0,
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: 0}))
.resolvedOptions().fractionalSecondDigits);
assertEquals(
1,
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: 1}))
.resolvedOptions().fractionalSecondDigits);
assertEquals(
2,
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: 2}))
.resolvedOptions().fractionalSecondDigits);
assertEquals(
3,
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: 3}))
.resolvedOptions().fractionalSecondDigits);
// When timeStyle and dateStyle is not present, GetNumberOption will fallback
// to 0 as default regardless fractionalSecondDigits is present in the option or
// not.
assertEquals(
0,
(new Intl.DateTimeFormat()).resolvedOptions().fractionalSecondDigits);
assertEquals(
0,
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: undefined}))
.resolvedOptions().fractionalSecondDigits);
// When timeStyle or dateStyle is present, the code should not read
// fractionalSecondDigits from the option.
assertEquals(
undefined,
(new Intl.DateTimeFormat(
"en", {timeStyle: "short", fractionalSecondDigits: 3}))
.resolvedOptions().fractionalSecondDigits);
assertEquals(
undefined,
(new Intl.DateTimeFormat(
"en", {dateStyle: "short", fractionalSecondDigits: 3}))
.resolvedOptions().fractionalSecondDigits);
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