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

LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr

This commit is contained in:
Matthew Olsson 2023-02-26 16:09:02 -07:00 committed by Andreas Kling
parent 1df3652e27
commit 7c0c1c8f49
214 changed files with 825 additions and 827 deletions

View file

@ -59,7 +59,7 @@ void AccessibilityTreeNode::serialize_tree_as_json(JsonObjectSerializer<StringBu
if (value()->has_child_nodes()) {
auto node_children = MUST(object.add_array("children"sv));
for (auto* child : children()) {
for (auto& child : children()) {
if (child->value()->is_uninteresting_whitespace_node())
continue;
JsonObjectSerializer<StringBuilder> child_object = MUST(node_children.add_object());

View file

@ -22,7 +22,7 @@ public:
JS::GCPtr<DOM::Node const> value() const { return m_value; }
void set_value(JS::GCPtr<DOM::Node const> value) { m_value = value; }
Vector<AccessibilityTreeNode*> children() const { return m_children; }
Vector<JS::GCPtr<AccessibilityTreeNode>> children() const { return m_children; }
void append_child(AccessibilityTreeNode* child) { m_children.append(child); }
void serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object, Document const&) const;
@ -34,7 +34,7 @@ private:
explicit AccessibilityTreeNode(JS::GCPtr<DOM::Node const>);
JS::GCPtr<DOM::Node const> m_value;
Vector<AccessibilityTreeNode*> m_children;
Vector<JS::GCPtr<AccessibilityTreeNode>> m_children;
};
}

View file

@ -36,7 +36,7 @@ private:
Document& document() { return m_document; }
Document const& document() const { return m_document; }
Document& m_document;
JS::NonnullGCPtr<Document> m_document;
};
}

View file

@ -567,7 +567,7 @@ private:
bool m_needs_full_style_update { false };
HashTable<NodeIterator*> m_node_iterators;
HashTable<JS::GCPtr<NodeIterator>> m_node_iterators;
// https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank
bool m_is_initial_about_blank { false };

View file

@ -83,7 +83,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<JS::Handle<DOM::DOMEvent
// 6. Let global be listener callbacks associated Realms global object.
auto& callback = listener->callback->callback();
auto& realm = callback.callback.shape().realm();
auto& realm = callback.callback->shape().realm();
auto& global = realm.global_object();
// 7. Let currentEvent be undefined.

View file

@ -464,12 +464,12 @@ WebIDL::CallbackType* EventTarget::get_current_value_of_event_handler(Deprecated
function->set_script_or_module({});
// 12. Set eventHandler's value to the result of creating a Web IDL EventHandler callback function object whose object reference is function and whose callback context is settings object.
event_handler->value = realm.heap().allocate_without_realm<WebIDL::CallbackType>(*function, settings_object).ptr();
event_handler->value = JS::GCPtr(realm.heap().allocate_without_realm<WebIDL::CallbackType>(*function, settings_object));
}
// 4. Return eventHandler's value.
VERIFY(event_handler->value.has<WebIDL::CallbackType*>());
return *event_handler->value.get_pointer<WebIDL::CallbackType*>();
VERIFY(event_handler->value.has<JS::GCPtr<WebIDL::CallbackType>>());
return *event_handler->value.get_pointer<JS::GCPtr<WebIDL::CallbackType>>();
}
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attributes:event-handler-idl-attributes-3
@ -512,7 +512,7 @@ void EventTarget::set_event_handler_attribute(DeprecatedFlyString const& name, W
auto& event_handler = event_handler_iterator->value;
event_handler->value = value;
event_handler->value = JS::GCPtr(value);
// 4. Activate an event handler given eventTarget and name.
// NOTE: See the optimization comment above.

View file

@ -80,7 +80,7 @@ WebIDL::ExceptionOr<void> MutationObserver::observe(Node& target, MutationObserv
// 7. For each registered of targets registered observer list, if registereds observer is this:
bool updated_existing_observer = false;
for (auto& registered_observer : target.registered_observers_list()) {
if (registered_observer.observer().ptr() != this)
if (registered_observer->observer().ptr() != this)
continue;
updated_existing_observer = true;
@ -92,12 +92,12 @@ WebIDL::ExceptionOr<void> MutationObserver::observe(Node& target, MutationObserv
continue;
node->registered_observers_list().remove_all_matching([&registered_observer](RegisteredObserver& observer) {
return is<TransientRegisteredObserver>(observer) && verify_cast<TransientRegisteredObserver>(observer).source().ptr() == &registered_observer;
return is<TransientRegisteredObserver>(observer) && verify_cast<TransientRegisteredObserver>(observer).source().ptr() == registered_observer;
});
}
// 2. Set registereds options to options.
registered_observer.set_options(options);
registered_observer->set_options(options);
break;
}

View file

@ -602,8 +602,8 @@ void Node::remove(bool suppress_observers)
// whose observer is registereds observer, options is registereds options, and source is registered to nodes registered observer list.
for (auto* inclusive_ancestor = parent; inclusive_ancestor; inclusive_ancestor = inclusive_ancestor->parent()) {
for (auto& registered : inclusive_ancestor->m_registered_observer_list) {
if (registered.options().subtree) {
auto transient_observer = TransientRegisteredObserver::create(registered.observer(), registered.options(), registered);
if (registered->options().subtree) {
auto transient_observer = TransientRegisteredObserver::create(registered->observer(), registered->options(), registered);
m_registered_observer_list.append(move(transient_observer));
}
}
@ -1411,7 +1411,7 @@ void Node::queue_mutation_record(DeprecatedFlyString const& type, DeprecatedStri
for (auto& node : nodes) {
for (auto& registered_observer : node->m_registered_observer_list) {
// 1. Let options be registereds options.
auto& options = registered_observer.options();
auto& options = registered_observer->options();
// 2. If none of the following are true
// - node is not target and options["subtree"] is false
@ -1426,7 +1426,7 @@ void Node::queue_mutation_record(DeprecatedFlyString const& type, DeprecatedStri
&& !(type == MutationType::characterData && (!options.character_data.has_value() || !options.character_data.value()))
&& !(type == MutationType::childList && !options.child_list)) {
// 1. Let mo be registereds observer.
auto mutation_observer = registered_observer.observer();
auto mutation_observer = registered_observer->observer();
// 2. If interestedObservers[mo] does not exist, then set interestedObservers[mo] to null.
if (!interested_observers.contains(mutation_observer))

View file

@ -645,7 +645,7 @@ protected:
// https://dom.spec.whatwg.org/#registered-observer-list
// "Nodes have a strong reference to registered observers in their registered observer list." https://dom.spec.whatwg.org/#garbage-collection
Vector<RegisteredObserver&> m_registered_observer_list;
Vector<JS::NonnullGCPtr<RegisteredObserver>> m_registered_observer_list;
void build_accessibility_tree(AccessibilityTreeNode& parent);

View file

@ -24,7 +24,7 @@ NodeFilter::NodeFilter(JS::Realm& realm, WebIDL::CallbackType& callback)
void NodeFilter::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(&m_callback);
visitor.visit(m_callback);
}
}

View file

@ -46,7 +46,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
WebIDL::CallbackType& m_callback;
JS::NonnullGCPtr<WebIDL::CallbackType> m_callback;
};
AK_ENUM_BITWISE_OPERATORS(NodeFilter::WhatToShow);

View file

@ -42,7 +42,7 @@ Node const* StaticNodeList::item(u32 index) const
// The item(index) method must return the indexth node in the collection. If there is no indexth node in the collection, then the method must return null.
if (index >= m_static_nodes.size())
return nullptr;
return &m_static_nodes[index];
return m_static_nodes[index];
}
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-indices

View file

@ -29,7 +29,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
Vector<Node&> m_static_nodes;
Vector<JS::NonnullGCPtr<Node>> m_static_nodes;
};
}