Skip to content

GetNumberFormatPattern's unit reconciliation unreachable from Amount.p.toLocaleString #154

Description

@jessealama

When the caller of Amount.p.toLocaleString supplies style, the Amount's unit gets dropped. While making some unit tests for the Amount polyfill on some currency examples, I found some weird results:

  • new Amount(5, "USD").toLocaleString("en-US", { style: "currency" }): [[Currency]] isn't set, so GetNumberFormatPattern throws
  • new Amount(5, "USD").toLocaleString("en-US", { style: "currency", currency: "EUR" }): formats as "€5.00"; the Amount's unit gets silently ignored rather than treated as a conflict.

Similar to the second example, but not explicitly related to currency:

  • new Amount(5, "kilogram").toLocaleString("en-US", { style: "unit", unit: "mile" }): formats as "5 mi". Similar to the previous error, but this time we're switching from two unrelated unit types.

The spec intends conflicts like the second and third cases to throw. GetNumberFormatPattern compares the unit and currency of its argument against the formatter's own [[Unit]] and [[Currency]] internal slots, throwing a TypeError on mismatch. But nothing in toLocaleString ever attaches a unit or currency to the value being formatted, so the intended checks never get called.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions