
Instead of passing a GlobalObject everywhere, we will simply pass a VM, from which we can get everything we need: common names, the current realm, symbols, arguments, the heap, and a few other things. In some places we already don't actually need a global object and just do it for consistency - no more `auto& vm = global_object.vm();`! This will eventually automatically fix the "wrong realm" issue we have in some places where we (incorrectly) use the global object from the allocating object, e.g. in call() / construct() implementations. When only ever a VM is passed around, this issue can't happen :^) I've decided to split this change into a series of patches that should keep each commit down do a somewhat manageable size.
40 lines
1.5 KiB
C++
40 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <AK/StringView.h>
|
|
#include <LibJS/Runtime/Completion.h>
|
|
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
#include <LibUnicode/PluralRules.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
class PluralRules final : public NumberFormatBase {
|
|
JS_OBJECT(PluralRules, NumberFormatBase);
|
|
|
|
public:
|
|
PluralRules(Object& prototype);
|
|
virtual ~PluralRules() override = default;
|
|
|
|
Unicode::PluralForm type() const { return m_type; }
|
|
StringView type_string() const { return Unicode::plural_form_to_string(m_type); }
|
|
void set_type(StringView type) { m_type = Unicode::plural_form_from_string(type); }
|
|
|
|
private:
|
|
Unicode::PluralForm m_type { Unicode::PluralForm::Cardinal }; // [[Type]]
|
|
};
|
|
|
|
Unicode::PluralOperands get_operands(String const& string);
|
|
Unicode::PluralCategory plural_rule_select(StringView locale, Unicode::PluralForm type, Value number, Unicode::PluralOperands operands);
|
|
Unicode::PluralCategory resolve_plural(PluralRules const&, Value number);
|
|
Unicode::PluralCategory resolve_plural(NumberFormatBase const& number_format, Unicode::PluralForm type, Value number);
|
|
Unicode::PluralCategory plural_rule_select_range(StringView locale, Unicode::PluralForm, Unicode::PluralCategory start, Unicode::PluralCategory end);
|
|
ThrowCompletionOr<Unicode::PluralCategory> resolve_plural_range(VM&, PluralRules const&, Value start, Value end);
|
|
|
|
}
|