mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 04:52:06 +02:00
LibJS: Use Intl.PluralRules within Intl.RelativeFormat
The Polish test cases added here cover previous failures from test262, due to the way that 0 is specified to be "many" in Polish.
This commit is contained in:
committed by
Linus Groh
parent
36abcd820d
commit
bf85bf2a9e
Notes:
sideshowbarker
2024-07-17 09:37:16 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/bf85bf2a9e Pull-request: https://github.com/SerenityOS/serenity/pull/14512 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg
@@ -10,8 +10,8 @@
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
||||
#include <LibJS/Runtime/Intl/NumberFormatConstructor.h>
|
||||
#include <LibJS/Runtime/Intl/PluralRules.h>
|
||||
#include <LibJS/Runtime/Intl/RelativeTimeFormat.h>
|
||||
#include <LibUnicode/NumberFormat.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
@@ -26,6 +26,8 @@ void RelativeTimeFormat::visit_edges(Cell::Visitor& visitor)
|
||||
Base::visit_edges(visitor);
|
||||
if (m_number_format)
|
||||
visitor.visit(m_number_format);
|
||||
if (m_plural_rules)
|
||||
visitor.visit(m_plural_rules);
|
||||
}
|
||||
|
||||
void RelativeTimeFormat::set_numeric(StringView numeric)
|
||||
@@ -179,10 +181,11 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt
|
||||
auto value_partitions = partition_number_pattern(global_object, relative_time_format.number_format(), Value(value));
|
||||
|
||||
// 21. Let pr be ! ResolvePlural(relativeTimeFormat.[[PluralRules]], value).
|
||||
auto plurality = resolve_plural(global_object, relative_time_format.plural_rules(), Value(value));
|
||||
|
||||
// 22. Let pattern be po.[[<pr>]].
|
||||
// FIXME: Use ResolvePlural when Intl.PluralRules is implemented.
|
||||
auto pattern = Unicode::select_pattern_with_plurality(patterns, value);
|
||||
if (!pattern.has_value())
|
||||
auto pattern = patterns.find_if([&](auto& p) { return p.plurality == plurality; });
|
||||
if (pattern == patterns.end())
|
||||
return Vector<PatternPartitionWithUnit> {};
|
||||
|
||||
// 23. Return ! MakePartsList(pattern, unit, fv).
|
||||
|
||||
Reference in New Issue
Block a user