1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

LibJS: Hide all the constructors!

Now that the GC allocator is able to invoke Cell subclass constructors
directly via friendship, we no longer need to keep them public. :^)
This commit is contained in:
Andreas Kling 2022-08-28 23:51:28 +02:00
parent d54ba587f3
commit 35c9aa7c05
196 changed files with 456 additions and 242 deletions

View file

@ -43,7 +43,6 @@ public:
return AK::Array { "co"sv, "kf"sv, "kn"sv };
}
explicit Collator(Object& prototype);
virtual ~Collator() override = default;
String const& locale() const { return m_locale; }
@ -74,6 +73,8 @@ public:
void set_bound_compare(CollatorCompareFunction* bound_compare) { m_bound_compare = bound_compare; }
private:
explicit Collator(Object& prototype);
virtual void visit_edges(Visitor&) override;
String m_locale; // [[Locale]]

View file

@ -16,13 +16,14 @@ class CollatorCompareFunction : public NativeFunction {
public:
static CollatorCompareFunction* create(Realm&, Collator&);
CollatorCompareFunction(Realm&, Collator&);
virtual void initialize(Realm&) override;
virtual ~CollatorCompareFunction() override = default;
virtual ThrowCompletionOr<Value> call() override;
private:
CollatorCompareFunction(Realm&, Collator&);
virtual void visit_edges(Visitor&) override;
Collator& m_collator; // [[Collator]]

View file

@ -14,7 +14,6 @@ class CollatorConstructor final : public NativeFunction {
JS_OBJECT(CollatorConstructor, NativeFunction);
public:
explicit CollatorConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~CollatorConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit CollatorConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -15,11 +15,12 @@ class CollatorPrototype final : public PrototypeObject<CollatorPrototype, Collat
JS_PROTOTYPE_OBJECT(CollatorPrototype, Collator, Collator);
public:
explicit CollatorPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~CollatorPrototype() override = default;
private:
explicit CollatorPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(compare_getter);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);
};

View file

@ -41,7 +41,6 @@ public:
return AK::Array { "ca"sv, "hc"sv, "nu"sv };
}
DateTimeFormat(Object& prototype);
virtual ~DateTimeFormat() override = default;
String const& locale() const { return m_locale; }
@ -128,6 +127,8 @@ public:
void set_bound_format(NativeFunction* bound_format) { m_bound_format = bound_format; }
private:
DateTimeFormat(Object& prototype);
static Style style_from_string(StringView style);
static StringView style_to_string(Style style);

View file

@ -14,7 +14,6 @@ class DateTimeFormatConstructor final : public NativeFunction {
JS_OBJECT(DateTimeFormatConstructor, NativeFunction);
public:
explicit DateTimeFormatConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~DateTimeFormatConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit DateTimeFormatConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -18,13 +18,14 @@ class DateTimeFormatFunction final : public NativeFunction {
public:
static DateTimeFormatFunction* create(Realm&, DateTimeFormat&);
explicit DateTimeFormatFunction(DateTimeFormat&, Object& prototype);
virtual ~DateTimeFormatFunction() override = default;
virtual void initialize(Realm&) override;
virtual ThrowCompletionOr<Value> call() override;
private:
explicit DateTimeFormatFunction(DateTimeFormat&, Object& prototype);
virtual void visit_edges(Visitor&) override;
DateTimeFormat& m_date_time_format; // [[DateTimeFormat]]

View file

@ -15,11 +15,12 @@ class DateTimeFormatPrototype final : public PrototypeObject<DateTimeFormatProto
JS_PROTOTYPE_OBJECT(DateTimeFormatPrototype, DateTimeFormat, Intl.DateTimeFormat);
public:
explicit DateTimeFormatPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~DateTimeFormatPrototype() override = default;
private:
explicit DateTimeFormatPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(format);
JS_DECLARE_NATIVE_FUNCTION(format_to_parts);
JS_DECLARE_NATIVE_FUNCTION(format_range);

View file

@ -39,7 +39,6 @@ class DisplayNames final : public Object {
};
public:
DisplayNames(Object& prototype);
virtual ~DisplayNames() override = default;
String const& locale() const { return m_locale; }
@ -63,6 +62,8 @@ public:
StringView language_display_string() const;
private:
DisplayNames(Object& prototype);
String m_locale; // [[Locale]]
Unicode::Style m_style { Unicode::Style::Long }; // [[Style]]
Type m_type { Type::Invalid }; // [[Type]]

View file

@ -14,7 +14,6 @@ class DisplayNamesConstructor final : public NativeFunction {
JS_OBJECT(DisplayNamesConstructor, NativeFunction);
public:
explicit DisplayNamesConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~DisplayNamesConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit DisplayNamesConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -15,11 +15,12 @@ class DisplayNamesPrototype final : public PrototypeObject<DisplayNamesPrototype
JS_PROTOTYPE_OBJECT(DisplayNamesPrototype, DisplayNames, Intl.DisplayNames);
public:
explicit DisplayNamesPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~DisplayNamesPrototype() override = default;
private:
explicit DisplayNamesPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(of);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);
};

View file

@ -48,7 +48,6 @@ public:
return AK::Array { "nu"sv };
}
explicit DurationFormat(Object& prototype);
virtual ~DurationFormat() override = default;
void set_locale(String locale) { m_locale = move(locale); }
@ -148,6 +147,8 @@ public:
u8 fractional_digits() const { return m_fractional_digits.value(); }
private:
explicit DurationFormat(Object& prototype);
static Style style_from_string(StringView style);
static StringView style_to_string(Style);
static ValueStyle date_style_from_string(StringView date_style);

View file

@ -14,7 +14,6 @@ class DurationFormatConstructor final : public NativeFunction {
JS_OBJECT(DurationFormatConstructor, NativeFunction);
public:
explicit DurationFormatConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~DurationFormatConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit DurationFormatConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -15,11 +15,12 @@ class DurationFormatPrototype final : public PrototypeObject<DurationFormatProto
JS_PROTOTYPE_OBJECT(DurationFormatPrototype, DurationFormat, Intl.DurationFormat);
public:
explicit DurationFormatPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~DurationFormatPrototype() override = default;
private:
explicit DurationFormatPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(format);
JS_DECLARE_NATIVE_FUNCTION(format_to_parts);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);

View file

@ -14,11 +14,12 @@ class Intl final : public Object {
JS_OBJECT(Intl, Object);
public:
explicit Intl(Realm&);
virtual void initialize(Realm&) override;
virtual ~Intl() override = default;
private:
explicit Intl(Realm&);
JS_DECLARE_NATIVE_FUNCTION(get_canonical_locales);
JS_DECLARE_NATIVE_FUNCTION(supported_values_of);
};

View file

@ -28,7 +28,6 @@ public:
Unit,
};
ListFormat(Object& prototype);
virtual ~ListFormat() override = default;
String const& locale() const { return m_locale; }
@ -43,6 +42,8 @@ public:
StringView style_string() const { return Unicode::style_to_string(m_style); }
private:
explicit ListFormat(Object& prototype);
String m_locale; // [[Locale]]
Type m_type { Type::Invalid }; // [[Type]]
Unicode::Style m_style { Unicode::Style::Long }; // [[Style]]

View file

@ -14,7 +14,6 @@ class ListFormatConstructor final : public NativeFunction {
JS_OBJECT(ListFormatConstructor, NativeFunction);
public:
explicit ListFormatConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~ListFormatConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit ListFormatConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -15,11 +15,12 @@ class ListFormatPrototype final : public PrototypeObject<ListFormatPrototype, Li
JS_PROTOTYPE_OBJECT(ListFormatPrototype, ListFormat, Intl.ListFormat);
public:
explicit ListFormatPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~ListFormatPrototype() override = default;
private:
explicit ListFormatPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(format);
JS_DECLARE_NATIVE_FUNCTION(format_to_parts);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);

View file

@ -34,8 +34,6 @@ public:
return AK::Array { "ca"sv, "co"sv, "hc"sv, "kf"sv, "kn"sv, "nu"sv };
}
Locale(Object& prototype);
Locale(Unicode::LocaleID const&, Object& prototype);
virtual ~Locale() override = default;
String const& locale() const { return m_locale; }
@ -65,6 +63,9 @@ public:
void set_numeric(bool numeric) { m_numeric = numeric; }
private:
explicit Locale(Object& prototype);
Locale(Unicode::LocaleID const&, Object& prototype);
String m_locale; // [[Locale]]
Optional<String> m_calendar; // [[Calendar]]
Optional<String> m_case_first; // [[CaseFirst]]

View file

@ -14,7 +14,6 @@ class LocaleConstructor final : public NativeFunction {
JS_OBJECT(LocaleConstructor, NativeFunction);
public:
explicit LocaleConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~LocaleConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit LocaleConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
};

View file

@ -15,11 +15,12 @@ class LocalePrototype final : public PrototypeObject<LocalePrototype, Locale> {
JS_PROTOTYPE_OBJECT(LocalePrototype, Locale, Intl.Locale);
public:
explicit LocalePrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~LocalePrototype() override = default;
private:
explicit LocalePrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(maximize);
JS_DECLARE_NATIVE_FUNCTION(minimize);
JS_DECLARE_NATIVE_FUNCTION(to_string);

View file

@ -56,7 +56,6 @@ public:
StripIfInteger,
};
NumberFormatBase(Object& prototype);
virtual ~NumberFormatBase() override = default;
String const& locale() const { return m_locale; }
@ -99,6 +98,9 @@ public:
StringView trailing_zero_display_string() const;
void set_trailing_zero_display(StringView trailing_zero_display);
protected:
explicit NumberFormatBase(Object& prototype);
private:
String m_locale; // [[Locale]]
String m_data_locale; // [[DataLocale]]
@ -174,7 +176,6 @@ public:
return AK::Array { "nu"sv };
}
NumberFormat(Object& prototype);
virtual ~NumberFormat() override = default;
String const& numbering_system() const { return m_numbering_system; }
@ -233,6 +234,8 @@ public:
Unicode::NumberFormat compact_format() const { return *m_compact_format; }
private:
explicit NumberFormat(Object& prototype);
virtual void visit_edges(Visitor&) override;
String m_locale; // [[Locale]]

View file

@ -15,7 +15,6 @@ class NumberFormatConstructor final : public NativeFunction {
JS_OBJECT(NumberFormatConstructor, NativeFunction);
public:
explicit NumberFormatConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~NumberFormatConstructor() override = default;
@ -23,6 +22,8 @@ public:
virtual ThrowCompletionOr<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);

View file

@ -18,13 +18,14 @@ class NumberFormatFunction final : public NativeFunction {
public:
static NumberFormatFunction* create(Realm&, NumberFormat&);
explicit NumberFormatFunction(NumberFormat&, Object& prototype);
virtual ~NumberFormatFunction() override = default;
virtual void initialize(Realm&) override;
virtual ThrowCompletionOr<Value> call() override;
private:
explicit NumberFormatFunction(NumberFormat&, Object& prototype);
virtual void visit_edges(Visitor&) override;
NumberFormat& m_number_format; // [[NumberFormat]]

View file

@ -15,11 +15,12 @@ class NumberFormatPrototype final : public PrototypeObject<NumberFormatPrototype
JS_PROTOTYPE_OBJECT(NumberFormatPrototype, NumberFormat, Intl.NumberFormat);
public:
explicit NumberFormatPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~NumberFormatPrototype() override = default;
private:
explicit NumberFormatPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(format);
JS_DECLARE_NATIVE_FUNCTION(format_to_parts);
JS_DECLARE_NATIVE_FUNCTION(format_range);

View file

@ -19,7 +19,6 @@ class PluralRules final : public NumberFormatBase {
JS_OBJECT(PluralRules, NumberFormatBase);
public:
PluralRules(Object& prototype);
virtual ~PluralRules() override = default;
Unicode::PluralForm type() const { return m_type; }
@ -27,6 +26,8 @@ public:
void set_type(StringView type) { m_type = Unicode::plural_form_from_string(type); }
private:
explicit PluralRules(Object& prototype);
Unicode::PluralForm m_type { Unicode::PluralForm::Cardinal }; // [[Type]]
};

View file

@ -14,7 +14,6 @@ class PluralRulesConstructor final : public NativeFunction {
JS_OBJECT(PluralRulesConstructor, NativeFunction);
public:
explicit PluralRulesConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~PluralRulesConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit PluralRulesConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -15,11 +15,12 @@ class PluralRulesPrototype final : public PrototypeObject<PluralRulesPrototype,
JS_PROTOTYPE_OBJECT(PluralRulesPrototype, PluralRules, Intl.PluralRules);
public:
explicit PluralRulesPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~PluralRulesPrototype() override = default;
private:
explicit PluralRulesPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(select);
JS_DECLARE_NATIVE_FUNCTION(select_range);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);

View file

@ -33,7 +33,6 @@ public:
return AK::Array { "nu"sv };
}
RelativeTimeFormat(Object& prototype);
virtual ~RelativeTimeFormat() override = default;
String const& locale() const { return m_locale; }
@ -60,6 +59,8 @@ public:
void set_plural_rules(PluralRules* plural_rules) { m_plural_rules = plural_rules; }
private:
explicit RelativeTimeFormat(Object& prototype);
virtual void visit_edges(Cell::Visitor&) override;
String m_locale; // [[Locale]]

View file

@ -14,7 +14,6 @@ class RelativeTimeFormatConstructor final : public NativeFunction {
JS_OBJECT(RelativeTimeFormatConstructor, NativeFunction);
public:
explicit RelativeTimeFormatConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~RelativeTimeFormatConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit RelativeTimeFormatConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -15,11 +15,12 @@ class RelativeTimeFormatPrototype final : public PrototypeObject<RelativeTimeFor
JS_PROTOTYPE_OBJECT(RelativeTimeFormatPrototype, RelativeTimeFormat, Intl.RelativeTimeFormat);
public:
explicit RelativeTimeFormatPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~RelativeTimeFormatPrototype() override = default;
private:
explicit RelativeTimeFormatPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(format);
JS_DECLARE_NATIVE_FUNCTION(format_to_parts);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);

View file

@ -18,7 +18,6 @@ class SegmentIterator final : public Object {
public:
static SegmentIterator* create(Realm&, Segmenter&, Utf16View const&, Segments const&);
SegmentIterator(Realm&, Segmenter&, Utf16View const&, Segments const&);
virtual ~SegmentIterator() override = default;
Segmenter const& iterating_segmenter() const { return m_iterating_segmenter; }
@ -29,6 +28,8 @@ public:
Segments const& segments() { return m_segments; }
private:
SegmentIterator(Realm&, Segmenter&, Utf16View const&, Segments const&);
virtual void visit_edges(Cell::Visitor&) override;
Segmenter& m_iterating_segmenter; // [[IteratingSegmenter]]

View file

@ -15,11 +15,12 @@ class SegmentIteratorPrototype final : public PrototypeObject<SegmentIteratorPro
JS_PROTOTYPE_OBJECT(SegmentIteratorPrototype, SegmentIterator, SegmentIterator);
public:
explicit SegmentIteratorPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~SegmentIteratorPrototype() override = default;
private:
explicit SegmentIteratorPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(next);
};

View file

@ -21,7 +21,6 @@ public:
Sentence,
};
explicit Segmenter(Object& prototype);
virtual ~Segmenter() override = default;
String const& locale() const { return m_locale; }
@ -32,6 +31,8 @@ public:
StringView segmenter_granularity_string() const;
private:
explicit Segmenter(Object& prototype);
String m_locale; // [[Locale]]
SegmenterGranularity m_segmenter_granularity { SegmenterGranularity::Grapheme }; // [[SegmenterGranularity]]
};

View file

@ -14,7 +14,6 @@ class SegmenterConstructor final : public NativeFunction {
JS_OBJECT(SegmenterConstructor, NativeFunction);
public:
explicit SegmenterConstructor(Realm&);
virtual void initialize(Realm&) override;
virtual ~SegmenterConstructor() override = default;
@ -22,6 +21,8 @@ public:
virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
private:
explicit SegmenterConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);

View file

@ -15,11 +15,12 @@ class SegmenterPrototype final : public PrototypeObject<SegmenterPrototype, Segm
JS_PROTOTYPE_OBJECT(SegmenterPrototype, Segmenter, Segmenter);
public:
explicit SegmenterPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~SegmenterPrototype() override = default;
private:
explicit SegmenterPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(segment);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);
};

View file

@ -18,7 +18,6 @@ class Segments final : public Object {
public:
static Segments* create(Realm&, Segmenter&, Utf16String);
Segments(Realm&, Segmenter&, Utf16String);
virtual ~Segments() override = default;
Segmenter& segments_segmenter() const { return m_segments_segmenter; }
@ -28,6 +27,8 @@ public:
Optional<Vector<size_t>>& boundaries_cache() const { return m_boundaries_cache; }
private:
Segments(Realm&, Segmenter&, Utf16String);
virtual void visit_edges(Cell::Visitor&) override;
Segmenter& m_segments_segmenter; // [[SegmentsSegmenter]]

View file

@ -15,11 +15,12 @@ class SegmentsPrototype final : public PrototypeObject<SegmentsPrototype, Segmen
JS_PROTOTYPE_OBJECT(SegmentsPrototype, Segments, Segments);
public:
explicit SegmentsPrototype(Realm&);
virtual void initialize(Realm&) override;
virtual ~SegmentsPrototype() override = default;
private:
explicit SegmentsPrototype(Realm&);
JS_DECLARE_NATIVE_FUNCTION(containing);
JS_DECLARE_NATIVE_FUNCTION(symbol_iterator);
};