mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:47:34 +00:00
LibJS+LibUnicode: Don't remove {currency} keys in GetNumberFormatPattern
In order to implement Intl.NumberFormat.prototype.formatToParts, do not replace {currency} keys in the format pattern before ECMA-402 tells us to. Otherwise, the array return by formatToParts will not contain the expected currency key. Early replacement was done to avoid resolving the currency display more than once, as it involves a couple of round trips to search through LibUnicode data. So this adds a non-standard method to NumberFormat to do this resolution and cache the result. Another side effect of this change is that LibUnicode must replace unit format patterns of the form "{0} {1}" during code generation. These were previously skipped during code generation because LibJS would just replace the keys with the currency display at runtime. But now that the currency display injection is delayed, any {0} or {1} keys in the format pattern will cause PartitionNumberPattern to abort.
This commit is contained in:
parent
d872d030f1
commit
c65dea64bd
5 changed files with 58 additions and 50 deletions
|
@ -97,6 +97,7 @@ public:
|
|||
CurrencyDisplay currency_display() const { return *m_currency_display; }
|
||||
StringView currency_display_string() const;
|
||||
void set_currency_display(StringView currency_display);
|
||||
StringView resolve_currency_display();
|
||||
|
||||
bool has_currency_sign() const { return m_currency_sign.has_value(); }
|
||||
CurrencySign currency_sign() const { return *m_currency_sign; }
|
||||
|
@ -177,6 +178,9 @@ private:
|
|||
Optional<CompactDisplay> m_compact_display {}; // [[CompactDisplay]]
|
||||
SignDisplay m_sign_display { SignDisplay::Invalid }; // [[SignDisplay]]
|
||||
NativeFunction* m_bound_format { nullptr }; // [[BoundFormat]]
|
||||
|
||||
// Non-standard. Stores the resolved currency display string based on [[Locale]], [[Currency]], and [[CurrencyDisplay]].
|
||||
Optional<StringView> m_resolved_currency_display;
|
||||
};
|
||||
|
||||
struct FormatResult {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue