regress-10438.js 1.76 KB
Newer Older
1 2 3 4
// 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.

5 6 7 8 9 10 11 12 13
assertThrows(
    () => (new Intl.DateTimeFormat("en", {fractionalSecondDigits: 0})),
    RangeError,
    "fractionalSecondDigits value is out of range.");

assertThrows(
    () => (new Intl.DateTimeFormat("en", {fractionalSecondDigits: 4})),
    RangeError,
    "fractionalSecondDigits value is out of range.");
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

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
31
// to undefined as default regardless fractionalSecondDigits is present in the option or
32 33
// not.
assertEquals(
34
    undefined,
35 36 37
    (new Intl.DateTimeFormat()).resolvedOptions().fractionalSecondDigits);

assertEquals(
38
    undefined,
39 40 41
    (new Intl.DateTimeFormat("en", {fractionalSecondDigits: undefined}))
        .resolvedOptions().fractionalSecondDigits);

42 43 44 45 46
// When timeStyle or dateStyle is present, we should throw TypeError
assertThrows(
    () => (new Intl.DateTimeFormat(
        "en", {timeStyle: "short", fractionalSecondDigits: 3})),
    TypeError,
47
    "Can't set option fractionalSecondDigits when timeStyle is used");
48 49 50 51 52

assertThrows(
    () => (new Intl.DateTimeFormat(
        "en", {dateStyle: "short", fractionalSecondDigits: 3})),
    TypeError,
53
    "Can't set option fractionalSecondDigits when dateStyle is used");