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

LibWeb: Restore proper functionality of legacy platform objects

With the GC heap conversion, the functionality of legacy platform
objects was broken. This is because the generated implementation of one
of them was used for all of them, removing functionality such as
deletion.

This re-adds all functionality, where questions such as "does the
object support indexed properties?" is instead answered by virtual
functions instead of by the IDL generator checking the presence of
certain keywords/attributes.
This commit is contained in:
Luke Wilde 2023-02-28 00:05:39 +00:00 committed by Andreas Kling
parent 7e76a51cb0
commit 54f58e2662
23 changed files with 450 additions and 132 deletions

View file

@ -183,7 +183,7 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window)
return any_media_queries_changed_match_state;
}
JS::Value CSSRuleList::item_value(size_t index) const
WebIDL::ExceptionOr<JS::Value> CSSRuleList::item_value(size_t index) const
{
return item(index);
}

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -54,7 +55,7 @@ public:
Iterator end() { return m_rules.end(); }
virtual bool is_supported_property_index(u32 index) const override;
virtual JS::Value item_value(size_t index) const override;
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
WebIDL::ExceptionOr<void> remove_a_css_rule(u32 index);
WebIDL::ExceptionOr<unsigned> insert_a_css_rule(Variant<StringView, CSSRule*>, u32 index);
@ -69,6 +70,19 @@ private:
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
// ^Bindings::LegacyPlatformObject
virtual bool supports_indexed_properties() const override { return true; }
virtual bool supports_named_properties() const override { return false; }
virtual bool has_indexed_property_setter() const override { return false; }
virtual bool has_named_property_setter() const override { return false; }
virtual bool has_named_property_deleter() const override { return false; }
virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
virtual bool has_global_interface_extended_attribute() const override { return false; }
virtual bool indexed_property_setter_has_identifier() const override { return false; }
virtual bool named_property_setter_has_identifier() const override { return false; }
virtual bool named_property_deleter_has_identifier() const override { return false; }
Vector<CSSRule&> m_rules;
};

View file

@ -115,7 +115,7 @@ bool MediaList::matches() const
return false;
}
JS::Value MediaList::item_value(size_t index) const
WebIDL::ExceptionOr<JS::Value> MediaList::item_value(size_t index) const
{
if (index >= m_media.size())
return JS::js_undefined();

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -31,7 +32,7 @@ public:
void delete_medium(DeprecatedString);
virtual bool is_supported_property_index(u32 index) const override;
virtual JS::Value item_value(size_t index) const override;
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
bool evaluate(HTML::Window const&);
bool matches() const;
@ -41,6 +42,19 @@ private:
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
// ^Bindings::LegacyPlatformObject
virtual bool supports_indexed_properties() const override { return true; }
virtual bool supports_named_properties() const override { return false; }
virtual bool has_indexed_property_setter() const override { return false; }
virtual bool has_named_property_setter() const override { return false; }
virtual bool has_named_property_deleter() const override { return false; }
virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
virtual bool has_global_interface_extended_attribute() const override { return false; }
virtual bool indexed_property_setter_has_identifier() const override { return false; }
virtual bool named_property_setter_has_identifier() const override { return false; }
virtual bool named_property_deleter_has_identifier() const override { return false; }
NonnullRefPtrVector<MediaQuery> m_media;
};

View file

@ -84,7 +84,7 @@ bool StyleSheetList::is_supported_property_index(u32 index) const
return index < m_sheets.size();
}
JS::Value StyleSheetList::item_value(size_t index) const
WebIDL::ExceptionOr<JS::Value> StyleSheetList::item_value(size_t index) const
{
if (index >= m_sheets.size())
return JS::js_undefined();

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -33,7 +34,7 @@ public:
size_t length() const { return m_sheets.size(); }
virtual bool is_supported_property_index(u32 index) const override;
virtual JS::Value item_value(size_t index) const override;
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
DOM::Document& document() { return m_document; }
DOM::Document const& document() const { return m_document; }
@ -44,6 +45,19 @@ private:
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
// ^Bindings::LegacyPlatformObject
virtual bool supports_indexed_properties() const override { return true; }
virtual bool supports_named_properties() const override { return false; }
virtual bool has_indexed_property_setter() const override { return false; }
virtual bool has_named_property_setter() const override { return false; }
virtual bool has_named_property_deleter() const override { return false; }
virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
virtual bool has_global_interface_extended_attribute() const override { return false; }
virtual bool indexed_property_setter_has_identifier() const override { return false; }
virtual bool named_property_setter_has_identifier() const override { return false; }
virtual bool named_property_deleter_has_identifier() const override { return false; }
void sort_sheets();
DOM::Document& m_document;