diff --git a/src/objects/js-date-time-format.cc b/src/objects/js-date-time-format.cc index 8217f75b9a..9580c1f9d3 100644 --- a/src/objects/js-date-time-format.cc +++ b/src/objects/js-date-time-format.cc @@ -545,6 +545,7 @@ MaybeHandle 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 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 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; } diff --git a/test/intl/regress-10438.js b/test/intl/regress-10438.js new file mode 100644 index 0000000000..81419180cf --- /dev/null +++ b/test/intl/regress-10438.js @@ -0,0 +1,51 @@ +// 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);