mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-24 03:02:23 +00:00
This uses ICU for the Intl.NumberFormat `format` and `formatToParts` prototypes. It does not yet port the range formatter prototypes. Most of the new code in LibLocale/NumberFormat is simply mapping from ECMA-402 types to ICU types. Beyond that, the only algorithmic change is that we have to mutate the output from ICU for `formatToParts` to match what is expected by ECMA-402. This is explained in NumberFormat.cpp in `flatten_partitions`. This lets us remove most data from our number format generator. All that remains are numbering system digits and symbols, which are relied upon still for other interfaces (e.g. Intl.DateTimeFormat). So they will be removed in a future patch. Note: All of the changes to the test files in this patch are now aligned with both Chrome and Safari.
37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021-2024, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
|
#include <LibJS/Runtime/NativeFunction.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
class NumberFormatConstructor final : public NativeFunction {
|
|
JS_OBJECT(NumberFormatConstructor, NativeFunction);
|
|
JS_DECLARE_ALLOCATOR(NumberFormatConstructor);
|
|
|
|
public:
|
|
virtual void initialize(Realm&) override;
|
|
virtual ~NumberFormatConstructor() override = default;
|
|
|
|
virtual ThrowCompletionOr<Value> call() override;
|
|
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
|
|
|
|
private:
|
|
explicit NumberFormatConstructor(Realm&);
|
|
|
|
virtual bool has_constructor() const override { return true; }
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);
|
|
};
|
|
|
|
ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM&, NumberFormat&, Value locales_value, Value options_value);
|
|
ThrowCompletionOr<void> set_number_format_digit_options(VM&, NumberFormatBase& intl_object, Object const& options, int default_min_fraction_digits, int default_max_fraction_digits, ::Locale::Notation notation);
|
|
ThrowCompletionOr<void> set_number_format_unit_options(VM&, NumberFormat& intl_object, Object const& options);
|
|
|
|
}
|