mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:37:35 +00:00
LibWeb: Move setting of Web object prototypes to initialize()
This needs to happen before prototype/constructor intitialization can be made lazy. Otherwise, GC could run during the C++ constructor and try to collect the object currently being created.
This commit is contained in:
parent
7bd8fd000f
commit
834202aeb9
339 changed files with 1294 additions and 187 deletions
|
@ -21,11 +21,16 @@ AbortController::AbortController(JS::Realm& realm, JS::NonnullGCPtr<AbortSignal>
|
|||
: PlatformObject(realm)
|
||||
, m_signal(move(signal))
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "AbortController"));
|
||||
}
|
||||
|
||||
AbortController::~AbortController() = default;
|
||||
|
||||
void AbortController::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::AbortControllerPrototype>(realm, "AbortController"));
|
||||
}
|
||||
|
||||
void AbortController::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
private:
|
||||
AbortController(JS::Realm&, JS::NonnullGCPtr<AbortSignal>);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
// https://dom.spec.whatwg.org/#abortcontroller-signal
|
||||
|
|
|
@ -20,7 +20,12 @@ JS::NonnullGCPtr<AbortSignal> AbortSignal::construct_impl(JS::Realm& realm)
|
|||
AbortSignal::AbortSignal(JS::Realm& realm)
|
||||
: EventTarget(realm)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "AbortSignal"));
|
||||
}
|
||||
|
||||
void AbortSignal::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::AbortSignalPrototype>(realm, "AbortSignal"));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#abortsignal-add
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
private:
|
||||
explicit AbortSignal(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
||||
// https://dom.spec.whatwg.org/#abortsignal-abort-reason
|
||||
|
|
|
@ -29,7 +29,12 @@ Attr::Attr(Document& document, QualifiedName qualified_name, DeprecatedString va
|
|||
, m_value(move(value))
|
||||
, m_owner_element(owner_element)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(document.realm(), "Attr"));
|
||||
}
|
||||
|
||||
void Attr::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::AttrPrototype>(realm, "Attr"));
|
||||
}
|
||||
|
||||
void Attr::visit_edges(Cell::Visitor& visitor)
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
private:
|
||||
Attr(Document&, QualifiedName, DeprecatedString value, Element const*);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
QualifiedName m_qualified_name;
|
||||
|
|
|
@ -12,9 +12,14 @@ namespace Web::DOM {
|
|||
CDATASection::CDATASection(Document& document, DeprecatedString const& data)
|
||||
: Text(document, NodeType::CDATA_SECTION_NODE, data)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm(), "CDATASection"));
|
||||
}
|
||||
|
||||
CDATASection::~CDATASection() = default;
|
||||
|
||||
void CDATASection::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::CDATASectionPrototype>(realm, "CDATASection"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ public:
|
|||
|
||||
private:
|
||||
CDATASection(Document&, DeprecatedString const&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -17,7 +17,12 @@ CharacterData::CharacterData(Document& document, NodeType type, DeprecatedString
|
|||
: Node(document, type)
|
||||
, m_data(data)
|
||||
{
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::CharacterDataPrototype>(document.realm(), "CharacterData"));
|
||||
}
|
||||
|
||||
void CharacterData::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::CharacterDataPrototype>(realm, "CharacterData"));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-characterdata-data
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
protected:
|
||||
CharacterData(Document&, NodeType, DeprecatedString const&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
private:
|
||||
DeprecatedString m_data;
|
||||
};
|
||||
|
|
|
@ -25,11 +25,16 @@ CustomEvent::CustomEvent(JS::Realm& realm, DeprecatedFlyString const& event_name
|
|||
: Event(realm, event_name, event_init)
|
||||
, m_detail(event_init.detail)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "CustomEvent"));
|
||||
}
|
||||
|
||||
CustomEvent::~CustomEvent() = default;
|
||||
|
||||
void CustomEvent::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::CustomEventPrototype>(realm, "CustomEvent"));
|
||||
}
|
||||
|
||||
void CustomEvent::visit_edges(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
// https://dom.spec.whatwg.org/#dom-customevent-detail
|
||||
JS::Value detail() const { return m_detail; }
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
||||
void init_custom_event(DeprecatedString const& type, bool bubbles, bool cancelable, JS::Value detail);
|
||||
|
|
|
@ -297,8 +297,6 @@ Document::Document(JS::Realm& realm, const AK::URL& url)
|
|||
, m_style_computer(make<CSS::StyleComputer>(*this))
|
||||
, m_url(url)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "Document"));
|
||||
|
||||
HTML::main_thread_event_loop().register_document({}, *this);
|
||||
|
||||
m_style_update_timer = Platform::Timer::create_single_shot(0, [this] {
|
||||
|
@ -315,6 +313,12 @@ Document::~Document()
|
|||
HTML::main_thread_event_loop().unregister_document({}, *this);
|
||||
}
|
||||
|
||||
void Document::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::DocumentPrototype>(realm, "Document"));
|
||||
}
|
||||
|
||||
void Document::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -450,6 +450,7 @@ public:
|
|||
DeprecatedString dump_accessibility_tree_as_json();
|
||||
|
||||
protected:
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -12,7 +12,12 @@ namespace Web::DOM {
|
|||
DocumentFragment::DocumentFragment(Document& document)
|
||||
: ParentNode(document, NodeType::DOCUMENT_FRAGMENT_NODE)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm(), "DocumentFragment"));
|
||||
}
|
||||
|
||||
void DocumentFragment::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::DocumentFragmentPrototype>(realm, "DocumentFragment"));
|
||||
}
|
||||
|
||||
void DocumentFragment::visit_edges(Cell::Visitor& visitor)
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
protected:
|
||||
explicit DocumentFragment(Document& document);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -17,7 +17,12 @@ JS::NonnullGCPtr<DocumentType> DocumentType::create(Document& document)
|
|||
DocumentType::DocumentType(Document& document)
|
||||
: Node(document, NodeType::DOCUMENT_TYPE_NODE)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm(), "DocumentType"));
|
||||
}
|
||||
|
||||
void DocumentType::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::DocumentTypePrototype>(realm, "DocumentType"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
private:
|
||||
explicit DocumentType(Document&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
DeprecatedString m_name;
|
||||
DeprecatedString m_public_id;
|
||||
DeprecatedString m_system_id;
|
||||
|
|
|
@ -56,7 +56,6 @@ Element::Element(Document& document, DOM::QualifiedName qualified_name)
|
|||
: ParentNode(document, NodeType::ELEMENT_NODE)
|
||||
, m_qualified_name(move(qualified_name))
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(document.realm(), "Element"));
|
||||
make_html_uppercased_qualified_name();
|
||||
}
|
||||
|
||||
|
@ -65,6 +64,8 @@ Element::~Element() = default;
|
|||
void Element::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::ElementPrototype>(realm, "Element"));
|
||||
|
||||
m_attributes = NamedNodeMap::create(*this);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ MutationObserver::MutationObserver(JS::Realm& realm, JS::GCPtr<WebIDL::CallbackT
|
|||
: PlatformObject(realm)
|
||||
, m_callback(move(callback))
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "MutationObserver"));
|
||||
|
||||
// 1. Set this’s callback to callback.
|
||||
|
||||
|
@ -32,6 +31,12 @@ MutationObserver::MutationObserver(JS::Realm& realm, JS::GCPtr<WebIDL::CallbackT
|
|||
|
||||
MutationObserver::~MutationObserver() = default;
|
||||
|
||||
void MutationObserver::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::MutationObserverPrototype>(realm, "MutationObserver"));
|
||||
}
|
||||
|
||||
void MutationObserver::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
private:
|
||||
MutationObserver(JS::Realm&, JS::GCPtr<WebIDL::CallbackType>);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-mo-callback
|
||||
|
@ -81,6 +82,7 @@ public:
|
|||
|
||||
protected:
|
||||
RegisteredObserver(MutationObserver& observer, MutationObserverInit const& options);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
|
@ -100,6 +102,7 @@ public:
|
|||
|
||||
private:
|
||||
TransientRegisteredObserver(MutationObserver& observer, MutationObserverInit const& options, RegisteredObserver& source);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
JS::NonnullGCPtr<RegisteredObserver> m_source;
|
||||
|
|
|
@ -29,11 +29,16 @@ MutationRecord::MutationRecord(JS::Realm& realm, DeprecatedFlyString const& type
|
|||
, m_attribute_namespace(attribute_namespace)
|
||||
, m_old_value(old_value)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "MutationRecord"));
|
||||
}
|
||||
|
||||
MutationRecord::~MutationRecord() = default;
|
||||
|
||||
void MutationRecord::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::MutationRecordPrototype>(realm, "MutationRecord"));
|
||||
}
|
||||
|
||||
void MutationRecord::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
|
||||
private:
|
||||
MutationRecord(JS::Realm& realm, DeprecatedFlyString const& type, Node& target, NodeList& added_nodes, NodeList& removed_nodes, Node* previous_sibling, Node* next_sibling, DeprecatedString const& attribute_name, DeprecatedString const& attribute_namespace, DeprecatedString const& old_value);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
DeprecatedFlyString m_type;
|
||||
|
|
|
@ -15,7 +15,12 @@ ProcessingInstruction::ProcessingInstruction(Document& document, DeprecatedStrin
|
|||
: CharacterData(document, NodeType::PROCESSING_INSTRUCTION_NODE, data)
|
||||
, m_target(target)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(document.realm(), "ProcessingInstruction"));
|
||||
}
|
||||
|
||||
void ProcessingInstruction::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::ProcessingInstructionPrototype>(realm, "ProcessingInstruction"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ public:
|
|||
private:
|
||||
ProcessingInstruction(Document&, DeprecatedString const& data, DeprecatedString const& target);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
DeprecatedString m_target;
|
||||
};
|
||||
|
||||
|
|
|
@ -52,13 +52,11 @@ JS::NonnullGCPtr<Range> Range::construct_impl(JS::Realm& realm)
|
|||
Range::Range(Document& document)
|
||||
: Range(document, 0, document, 0)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(document.realm(), "Range"));
|
||||
}
|
||||
|
||||
Range::Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
|
||||
: AbstractRange(start_container, start_offset, end_container, end_offset)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(start_container.realm(), "Range"));
|
||||
live_ranges().set(this);
|
||||
}
|
||||
|
||||
|
@ -67,6 +65,12 @@ Range::~Range()
|
|||
live_ranges().remove(this);
|
||||
}
|
||||
|
||||
void Range::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::RangePrototype>(realm, "Range"));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-range-root
|
||||
Node& Range::root()
|
||||
{
|
||||
|
|
|
@ -88,6 +88,8 @@ private:
|
|||
explicit Range(Document&);
|
||||
Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
Node& root();
|
||||
Node const& root() const;
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace Web::DOM {
|
|||
StaticRange::StaticRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset)
|
||||
: AbstractRange(start_container, start_offset, end_container, end_offset)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(start_container.realm(), "StaticRange"));
|
||||
}
|
||||
|
||||
StaticRange::~StaticRange() = default;
|
||||
|
@ -36,4 +35,10 @@ WebIDL::ExceptionOr<StaticRange*> StaticRange::construct_impl(JS::Realm& realm,
|
|||
return realm.heap().allocate<StaticRange>(realm, *init.start_container, init.start_offset, *init.end_container, init.end_offset).ptr();
|
||||
}
|
||||
|
||||
void StaticRange::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::StaticRangePrototype>(realm, "StaticRange"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ public:
|
|||
|
||||
StaticRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
|
||||
virtual ~StaticRange() override;
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -17,13 +17,17 @@ namespace Web::DOM {
|
|||
Text::Text(Document& document, DeprecatedString const& data)
|
||||
: CharacterData(document, NodeType::TEXT_NODE, data)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm(), "Text"));
|
||||
}
|
||||
|
||||
Text::Text(Document& document, NodeType type, DeprecatedString const& data)
|
||||
: CharacterData(document, type, data)
|
||||
{
|
||||
set_prototype(&Bindings::cached_web_prototype(realm(), "Text"));
|
||||
}
|
||||
|
||||
void Text::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::TextPrototype>(realm, "Text"));
|
||||
}
|
||||
|
||||
void Text::visit_edges(Cell::Visitor& visitor)
|
||||
|
|
|
@ -38,6 +38,7 @@ protected:
|
|||
Text(Document&, DeprecatedString const&);
|
||||
Text(Document&, NodeType, DeprecatedString const&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue