mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:27:45 +00:00
LibWeb: Delete LegacyPlatformObject and move behavior to PlatformObject
We have two known PlatformObjects that need to implement some of the behavior of LegacyPlatformObjects to date: Window, and HTMLFormElement. To make this not require double (or virtual) inheritance of PlatformObject, move the behavior of LegacyPlatformObject into PlatformObject. The selection of LegacyPlatformObject behavior is done with a new bitfield of feature flags instead of a dozen virtual functions that return bool. This change simplifies every class involved in the diff with the notable exception of Window, which now needs some ugly const casts to implement named property access.
This commit is contained in:
parent
6047f1adcb
commit
521ed0e911
41 changed files with 684 additions and 801 deletions
|
@ -62,10 +62,12 @@ JS::NonnullGCPtr<DOMTokenList> DOMTokenList::create(Element& associated_element,
|
|||
|
||||
// https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2
|
||||
DOMTokenList::DOMTokenList(Element& associated_element, FlyString associated_attribute)
|
||||
: Bindings::LegacyPlatformObject(associated_element.realm())
|
||||
: Bindings::PlatformObject(associated_element.realm())
|
||||
, m_associated_element(associated_element)
|
||||
, m_associated_attribute(move(associated_attribute))
|
||||
{
|
||||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = 1 };
|
||||
|
||||
auto value = associated_element.deprecated_get_attribute(m_associated_attribute);
|
||||
associated_attribute_changed(value);
|
||||
}
|
||||
|
|
|
@ -13,15 +13,15 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/Bindings/LegacyPlatformObject.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
// https://dom.spec.whatwg.org/#domtokenlist
|
||||
class DOMTokenList final : public Bindings::LegacyPlatformObject {
|
||||
WEB_PLATFORM_OBJECT(DOMTokenList, Bindings::LegacyPlatformObject);
|
||||
class DOMTokenList final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(DOMTokenList, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(DOMTokenList);
|
||||
|
||||
public:
|
||||
|
@ -50,19 +50,6 @@ private:
|
|||
virtual 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; }
|
||||
|
||||
WebIDL::ExceptionOr<void> validate_token(StringView token) const;
|
||||
void run_update_steps();
|
||||
|
||||
|
|
|
@ -21,11 +21,16 @@ JS::NonnullGCPtr<HTMLCollection> HTMLCollection::create(ParentNode& root, Scope
|
|||
}
|
||||
|
||||
HTMLCollection::HTMLCollection(ParentNode& root, Scope scope, Function<bool(Element const&)> filter)
|
||||
: LegacyPlatformObject(root.realm())
|
||||
: PlatformObject(root.realm())
|
||||
, m_root(root)
|
||||
, m_filter(move(filter))
|
||||
, m_scope(scope)
|
||||
{
|
||||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
|
||||
.supports_indexed_properties = true,
|
||||
.supports_named_properties = true,
|
||||
.has_legacy_unenumerable_named_properties_interface_extended_attribute = true,
|
||||
};
|
||||
}
|
||||
|
||||
HTMLCollection::~HTMLCollection() = default;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <AK/Function.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibWeb/Bindings/LegacyPlatformObject.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
@ -25,8 +25,8 @@ namespace Web::DOM {
|
|||
// We should teach it how to cache results. The main challenge is invalidating
|
||||
// these caches, since this needs to happen on various kinds of DOM mutation.
|
||||
|
||||
class HTMLCollection : public Bindings::LegacyPlatformObject {
|
||||
WEB_PLATFORM_OBJECT(HTMLCollection, Bindings::LegacyPlatformObject);
|
||||
class HTMLCollection : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(HTMLCollection, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(HTMLCollection);
|
||||
|
||||
public:
|
||||
|
@ -60,19 +60,6 @@ protected:
|
|||
private:
|
||||
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 true; }
|
||||
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 true; }
|
||||
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; }
|
||||
|
||||
JS::NonnullGCPtr<ParentNode> m_root;
|
||||
Function<bool(Element const&)> m_filter;
|
||||
|
||||
|
|
|
@ -23,9 +23,14 @@ JS::NonnullGCPtr<NamedNodeMap> NamedNodeMap::create(Element& element)
|
|||
}
|
||||
|
||||
NamedNodeMap::NamedNodeMap(Element& element)
|
||||
: Bindings::LegacyPlatformObject(element.realm())
|
||||
: Bindings::PlatformObject(element.realm())
|
||||
, m_element(element)
|
||||
{
|
||||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
|
||||
.supports_indexed_properties = true,
|
||||
.supports_named_properties = true,
|
||||
.has_legacy_unenumerable_named_properties_interface_extended_attribute = true,
|
||||
};
|
||||
}
|
||||
|
||||
void NamedNodeMap::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/LegacyPlatformObject.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-namednodemap
|
||||
class NamedNodeMap : public Bindings::LegacyPlatformObject {
|
||||
WEB_PLATFORM_OBJECT(NamedNodeMap, Bindings::LegacyPlatformObject);
|
||||
class NamedNodeMap : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(NamedNodeMap, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(NamedNodeMap);
|
||||
|
||||
public:
|
||||
|
@ -60,19 +60,6 @@ private:
|
|||
virtual 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 true; }
|
||||
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 true; }
|
||||
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; }
|
||||
|
||||
Element& associated_element() { return *m_element; }
|
||||
Element const& associated_element() const { return *m_element; }
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
namespace Web::DOM {
|
||||
|
||||
NodeList::NodeList(JS::Realm& realm)
|
||||
: LegacyPlatformObject(realm)
|
||||
: PlatformObject(realm)
|
||||
{
|
||||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = true };
|
||||
}
|
||||
|
||||
NodeList::~NodeList() = default;
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/LegacyPlatformObject.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
// https://dom.spec.whatwg.org/#nodelist
|
||||
class NodeList : public Bindings::LegacyPlatformObject {
|
||||
WEB_PLATFORM_OBJECT(NodeList, Bindings::LegacyPlatformObject);
|
||||
class NodeList : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(NodeList, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
virtual ~NodeList() override;
|
||||
|
@ -28,19 +28,6 @@ protected:
|
|||
explicit NodeList(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
// ^Bindings::LegacyPlatformObject
|
||||
virtual bool supports_indexed_properties() const final override { return true; }
|
||||
virtual bool supports_named_properties() const final override { return false; }
|
||||
virtual bool has_indexed_property_setter() const final override { return false; }
|
||||
virtual bool has_named_property_setter() const final override { return false; }
|
||||
virtual bool has_named_property_deleter() const final override { return false; }
|
||||
virtual bool has_legacy_override_built_ins_interface_extended_attribute() const final override { return false; }
|
||||
virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const final override { return false; }
|
||||
virtual bool has_global_interface_extended_attribute() const final override { return false; }
|
||||
virtual bool indexed_property_setter_has_identifier() const final override { return false; }
|
||||
virtual bool named_property_setter_has_identifier() const final override { return false; }
|
||||
virtual bool named_property_deleter_has_identifier() const final override { return false; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue