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.
When the caller of
Amount.p.toLocaleStringsuppliesstyle, 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, soGetNumberFormatPatternthrowsnew 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.
GetNumberFormatPatterncompares the unit and currency of its argument against the formatter's own[[Unit]]and[[Currency]]internal slots, throwing aTypeErroron mismatch. But nothing intoLocaleStringever attaches a unit or currency to the value being formatted, so the intended checks never get called.