mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the namespace change, we now have the following names: * JS::NonnullGCPtr -> GC::Ref * JS::GCPtr -> GC::Ptr * JS::HeapFunction -> GC::Function * JS::CellImpl -> GC::Cell * JS::Handle -> GC::Root
This commit is contained in:
parent
ce23efc5f6
commit
f87041bf3a
Notes:
github-actions[bot]
2024-11-15 13:50:17 +00:00
Author: https://github.com/shannonbooth
Commit: f87041bf3a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2345
1722 changed files with 9939 additions and 9906 deletions
|
@ -16,10 +16,10 @@
|
|||
|
||||
namespace Web::IntersectionObserver {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(IntersectionObserver);
|
||||
GC_DEFINE_ALLOCATOR(IntersectionObserver);
|
||||
|
||||
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-intersectionobserver
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserver>> IntersectionObserver::construct_impl(JS::Realm& realm, JS::GCPtr<WebIDL::CallbackType> callback, IntersectionObserverInit const& options)
|
||||
WebIDL::ExceptionOr<GC::Ref<IntersectionObserver>> IntersectionObserver::construct_impl(JS::Realm& realm, GC::Ptr<WebIDL::CallbackType> callback, IntersectionObserverInit const& options)
|
||||
{
|
||||
// 4. Let thresholds be a list equal to options.threshold.
|
||||
Vector<double> thresholds;
|
||||
|
@ -48,12 +48,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserver>> IntersectionObserver
|
|||
return realm.create<IntersectionObserver>(realm, callback, options.root, move(thresholds));
|
||||
}
|
||||
|
||||
IntersectionObserver::IntersectionObserver(JS::Realm& realm, JS::GCPtr<WebIDL::CallbackType> callback, Optional<Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>>> const& root, Vector<double>&& thresholds)
|
||||
IntersectionObserver::IntersectionObserver(JS::Realm& realm, GC::Ptr<WebIDL::CallbackType> callback, Optional<Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>>> const& root, Vector<double>&& thresholds)
|
||||
: PlatformObject(realm)
|
||||
, m_callback(callback)
|
||||
, m_thresholds(move(thresholds))
|
||||
{
|
||||
m_root = root.has_value() ? root->visit([](auto& value) -> JS::GCPtr<DOM::Node> { return *value; }) : nullptr;
|
||||
m_root = root.has_value() ? root->visit([](auto& value) -> GC::Ptr<DOM::Node> { return *value; }) : nullptr;
|
||||
intersection_root().visit([this](auto& node) {
|
||||
m_document = node->document();
|
||||
});
|
||||
|
@ -89,7 +89,7 @@ void IntersectionObserver::observe(DOM::Element& target)
|
|||
// Run the observe a target Element algorithm, providing this and target.
|
||||
// https://www.w3.org/TR/intersection-observer/#observe-a-target-element
|
||||
// 1. If target is in observer’s internal [[ObservationTargets]] slot, return.
|
||||
if (m_observation_targets.contains_slow(JS::NonnullGCPtr { target }))
|
||||
if (m_observation_targets.contains_slow(GC::Ref { target }))
|
||||
return;
|
||||
|
||||
// 2. Let intersectionObserverRegistration be an IntersectionObserverRegistration record with an observer
|
||||
|
@ -117,7 +117,7 @@ void IntersectionObserver::unobserve(DOM::Element& target)
|
|||
target.unregister_intersection_observer({}, *this);
|
||||
|
||||
// 2. Remove target from this’s internal [[ObservationTargets]] slot, if present
|
||||
m_observation_targets.remove_first_matching([&target](JS::NonnullGCPtr<DOM::Element> const& entry) {
|
||||
m_observation_targets.remove_first_matching([&target](GC::Ref<DOM::Element> const& entry) {
|
||||
return entry.ptr() == ⌖
|
||||
});
|
||||
}
|
||||
|
@ -136,10 +136,10 @@ void IntersectionObserver::disconnect()
|
|||
}
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-takerecords
|
||||
Vector<JS::Handle<IntersectionObserverEntry>> IntersectionObserver::take_records()
|
||||
Vector<GC::Root<IntersectionObserverEntry>> IntersectionObserver::take_records()
|
||||
{
|
||||
// 1. Let queue be a copy of this’s internal [[QueuedEntries]] slot.
|
||||
Vector<JS::Handle<IntersectionObserverEntry>> queue;
|
||||
Vector<GC::Root<IntersectionObserverEntry>> queue;
|
||||
for (auto& entry : m_queued_entries)
|
||||
queue.append(*entry);
|
||||
|
||||
|
@ -150,32 +150,32 @@ Vector<JS::Handle<IntersectionObserverEntry>> IntersectionObserver::take_records
|
|||
return queue;
|
||||
}
|
||||
|
||||
Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>, Empty> IntersectionObserver::root() const
|
||||
Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>, Empty> IntersectionObserver::root() const
|
||||
{
|
||||
if (!m_root)
|
||||
return Empty {};
|
||||
if (m_root->is_element())
|
||||
return JS::make_handle(static_cast<DOM::Element&>(*m_root));
|
||||
return GC::make_root(static_cast<DOM::Element&>(*m_root));
|
||||
if (m_root->is_document())
|
||||
return JS::make_handle(static_cast<DOM::Document&>(*m_root));
|
||||
return GC::make_root(static_cast<DOM::Document&>(*m_root));
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#intersectionobserver-intersection-root
|
||||
Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>> IntersectionObserver::intersection_root() const
|
||||
Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>> IntersectionObserver::intersection_root() const
|
||||
{
|
||||
// The intersection root for an IntersectionObserver is the value of its root attribute
|
||||
// if the attribute is non-null;
|
||||
if (m_root) {
|
||||
if (m_root->is_element())
|
||||
return JS::make_handle(static_cast<DOM::Element&>(*m_root));
|
||||
return GC::make_root(static_cast<DOM::Element&>(*m_root));
|
||||
if (m_root->is_document())
|
||||
return JS::make_handle(static_cast<DOM::Document&>(*m_root));
|
||||
return GC::make_root(static_cast<DOM::Document&>(*m_root));
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// otherwise, it is the top-level browsing context’s document node, referred to as the implicit root.
|
||||
return JS::make_handle(verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).page().top_level_browsing_context().active_document());
|
||||
return GC::make_root(verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).page().top_level_browsing_context().active_document());
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#intersectionobserver-root-intersection-rectangle
|
||||
|
@ -189,8 +189,8 @@ CSSPixelRect IntersectionObserver::root_intersection_rectangle() const
|
|||
|
||||
// If the intersection root is a document,
|
||||
// it’s the size of the document's viewport (note that this processing step can only be reached if the document is fully active).
|
||||
if (intersection_root.has<JS::Handle<DOM::Document>>()) {
|
||||
auto document = intersection_root.get<JS::Handle<DOM::Document>>();
|
||||
if (intersection_root.has<GC::Root<DOM::Document>>()) {
|
||||
auto document = intersection_root.get<GC::Root<DOM::Document>>();
|
||||
|
||||
// Since the spec says that this is only reach if the document is fully active, that means it must have a navigable.
|
||||
VERIFY(document->navigable());
|
||||
|
@ -199,8 +199,8 @@ CSSPixelRect IntersectionObserver::root_intersection_rectangle() const
|
|||
// as intersections are computed using viewport-relative element rects.
|
||||
rect = CSSPixelRect { CSSPixelPoint { 0, 0 }, document->viewport_rect().size() };
|
||||
} else {
|
||||
VERIFY(intersection_root.has<JS::Handle<DOM::Element>>());
|
||||
auto element = intersection_root.get<JS::Handle<DOM::Element>>();
|
||||
VERIFY(intersection_root.has<GC::Root<DOM::Element>>());
|
||||
auto element = intersection_root.get<GC::Root<DOM::Element>>();
|
||||
|
||||
// FIXME: Otherwise, if the intersection root has a content clip,
|
||||
// it’s the element’s content area.
|
||||
|
@ -220,7 +220,7 @@ CSSPixelRect IntersectionObserver::root_intersection_rectangle() const
|
|||
return rect;
|
||||
}
|
||||
|
||||
void IntersectionObserver::queue_entry(Badge<DOM::Document>, JS::NonnullGCPtr<IntersectionObserverEntry> entry)
|
||||
void IntersectionObserver::queue_entry(Badge<DOM::Document>, GC::Ref<IntersectionObserverEntry> entry)
|
||||
{
|
||||
m_queued_entries.append(entry);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibGC/Root.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/IntersectionObserver/IntersectionObserverEntry.h>
|
||||
#include <LibWeb/PixelUnits.h>
|
||||
|
@ -14,7 +14,7 @@
|
|||
namespace Web::IntersectionObserver {
|
||||
|
||||
struct IntersectionObserverInit {
|
||||
Optional<Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>>> root;
|
||||
Optional<Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>>> root;
|
||||
String root_margin { "0px"_string };
|
||||
Variant<double, Vector<double>> threshold { 0 };
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ struct IntersectionObserverInit {
|
|||
struct IntersectionObserverRegistration {
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverregistration-observer
|
||||
// [A]n observer property holding an IntersectionObserver.
|
||||
JS::NonnullGCPtr<IntersectionObserver> observer;
|
||||
GC::Ref<IntersectionObserver> observer;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverregistration-observer
|
||||
// NOTE: Optional is used in place of the spec using -1 to indicate no previous index.
|
||||
|
@ -38,51 +38,51 @@ struct IntersectionObserverRegistration {
|
|||
// https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
|
||||
class IntersectionObserver final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(IntersectionObserver);
|
||||
GC_DECLARE_ALLOCATOR(IntersectionObserver);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserver>> construct_impl(JS::Realm&, JS::GCPtr<WebIDL::CallbackType> callback, IntersectionObserverInit const& options = {});
|
||||
static WebIDL::ExceptionOr<GC::Ref<IntersectionObserver>> construct_impl(JS::Realm&, GC::Ptr<WebIDL::CallbackType> callback, IntersectionObserverInit const& options = {});
|
||||
|
||||
virtual ~IntersectionObserver() override;
|
||||
|
||||
void observe(DOM::Element& target);
|
||||
void unobserve(DOM::Element& target);
|
||||
void disconnect();
|
||||
Vector<JS::Handle<IntersectionObserverEntry>> take_records();
|
||||
Vector<GC::Root<IntersectionObserverEntry>> take_records();
|
||||
|
||||
Vector<JS::NonnullGCPtr<DOM::Element>> const& observation_targets() const { return m_observation_targets; }
|
||||
Vector<GC::Ref<DOM::Element>> const& observation_targets() const { return m_observation_targets; }
|
||||
|
||||
Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>, Empty> root() const;
|
||||
Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>, Empty> root() const;
|
||||
Vector<double> const& thresholds() const { return m_thresholds; }
|
||||
|
||||
Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>> intersection_root() const;
|
||||
Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>> intersection_root() const;
|
||||
CSSPixelRect root_intersection_rectangle() const;
|
||||
|
||||
void queue_entry(Badge<DOM::Document>, JS::NonnullGCPtr<IntersectionObserverEntry>);
|
||||
void queue_entry(Badge<DOM::Document>, GC::Ref<IntersectionObserverEntry>);
|
||||
|
||||
WebIDL::CallbackType& callback() { return *m_callback; }
|
||||
|
||||
private:
|
||||
explicit IntersectionObserver(JS::Realm&, JS::GCPtr<WebIDL::CallbackType> callback, Optional<Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>>> const& root, Vector<double>&& thresholds);
|
||||
explicit IntersectionObserver(JS::Realm&, GC::Ptr<WebIDL::CallbackType> callback, Optional<Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>>> const& root, Vector<double>&& thresholds);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
virtual void finalize() override;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-callback-slot
|
||||
JS::GCPtr<WebIDL::CallbackType> m_callback;
|
||||
GC::Ptr<WebIDL::CallbackType> m_callback;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-root
|
||||
JS::GCPtr<DOM::Node> m_root;
|
||||
GC::Ptr<DOM::Node> m_root;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-thresholds
|
||||
Vector<double> m_thresholds;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-queuedentries-slot
|
||||
Vector<JS::NonnullGCPtr<IntersectionObserverEntry>> m_queued_entries;
|
||||
Vector<GC::Ref<IntersectionObserverEntry>> m_queued_entries;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-observationtargets-slot
|
||||
Vector<JS::NonnullGCPtr<DOM::Element>> m_observation_targets;
|
||||
Vector<GC::Ref<DOM::Element>> m_observation_targets;
|
||||
|
||||
// AD-HOC: This is the document where we've registered the IntersectionObserver.
|
||||
WeakPtr<DOM::Document> m_document;
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
|
||||
namespace Web::IntersectionObserver {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(IntersectionObserverEntry);
|
||||
GC_DEFINE_ALLOCATOR(IntersectionObserverEntry);
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserverEntry>> IntersectionObserverEntry::construct_impl(JS::Realm& realm, Web::IntersectionObserver::IntersectionObserverEntryInit const& options)
|
||||
WebIDL::ExceptionOr<GC::Ref<IntersectionObserverEntry>> IntersectionObserverEntry::construct_impl(JS::Realm& realm, Web::IntersectionObserver::IntersectionObserverEntryInit const& options)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
|
||||
JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds;
|
||||
GC::Ptr<Geometry::DOMRectReadOnly> root_bounds;
|
||||
if (options.root_bounds.has_value())
|
||||
root_bounds = Geometry::DOMRectReadOnly::from_rect(vm, options.root_bounds.value());
|
||||
|
||||
|
@ -26,7 +26,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserverEntry>> IntersectionObs
|
|||
return realm.create<IntersectionObserverEntry>(realm, options.time, root_bounds, bounding_client_rect, intersection_rect, options.is_intersecting, options.intersection_ratio, *options.target);
|
||||
}
|
||||
|
||||
IntersectionObserverEntry::IntersectionObserverEntry(JS::Realm& realm, HighResolutionTime::DOMHighResTimeStamp time, JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> bounding_client_rect, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> intersection_rect, bool is_intersecting, double intersection_ratio, JS::NonnullGCPtr<DOM::Element> target)
|
||||
IntersectionObserverEntry::IntersectionObserverEntry(JS::Realm& realm, HighResolutionTime::DOMHighResTimeStamp time, GC::Ptr<Geometry::DOMRectReadOnly> root_bounds, GC::Ref<Geometry::DOMRectReadOnly> bounding_client_rect, GC::Ref<Geometry::DOMRectReadOnly> intersection_rect, bool is_intersecting, double intersection_ratio, GC::Ref<DOM::Element> target)
|
||||
: Bindings::PlatformObject(realm)
|
||||
, m_time(time)
|
||||
, m_root_bounds(root_bounds)
|
||||
|
|
|
@ -32,28 +32,28 @@ struct IntersectionObserverEntryInit {
|
|||
double intersection_ratio { 0.0 };
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-target
|
||||
JS::Handle<DOM::Element> target;
|
||||
GC::Root<DOM::Element> target;
|
||||
};
|
||||
|
||||
class IntersectionObserverEntry final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(IntersectionObserverEntry, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(IntersectionObserverEntry);
|
||||
GC_DECLARE_ALLOCATOR(IntersectionObserverEntry);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserverEntry>> construct_impl(JS::Realm&, IntersectionObserverEntryInit const& options);
|
||||
static WebIDL::ExceptionOr<GC::Ref<IntersectionObserverEntry>> construct_impl(JS::Realm&, IntersectionObserverEntryInit const& options);
|
||||
|
||||
virtual ~IntersectionObserverEntry() override;
|
||||
|
||||
HighResolutionTime::DOMHighResTimeStamp time() const { return m_time; }
|
||||
JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds() const { return m_root_bounds; }
|
||||
JS::NonnullGCPtr<Geometry::DOMRectReadOnly> bounding_client_rect() const { return m_bounding_client_rect; }
|
||||
JS::NonnullGCPtr<Geometry::DOMRectReadOnly> intersection_rect() const { return m_intersection_rect; }
|
||||
GC::Ptr<Geometry::DOMRectReadOnly> root_bounds() const { return m_root_bounds; }
|
||||
GC::Ref<Geometry::DOMRectReadOnly> bounding_client_rect() const { return m_bounding_client_rect; }
|
||||
GC::Ref<Geometry::DOMRectReadOnly> intersection_rect() const { return m_intersection_rect; }
|
||||
bool is_intersecting() const { return m_is_intersecting; }
|
||||
double intersection_ratio() const { return m_intersection_ratio; }
|
||||
JS::NonnullGCPtr<DOM::Element> target() const { return m_target; }
|
||||
GC::Ref<DOM::Element> target() const { return m_target; }
|
||||
|
||||
private:
|
||||
IntersectionObserverEntry(JS::Realm&, HighResolutionTime::DOMHighResTimeStamp time, JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> bounding_client_rect, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> intersection_rect, bool is_intersecting, double intersection_ratio, JS::NonnullGCPtr<DOM::Element> target);
|
||||
IntersectionObserverEntry(JS::Realm&, HighResolutionTime::DOMHighResTimeStamp time, GC::Ptr<Geometry::DOMRectReadOnly> root_bounds, GC::Ref<Geometry::DOMRectReadOnly> bounding_client_rect, GC::Ref<Geometry::DOMRectReadOnly> intersection_rect, bool is_intersecting, double intersection_ratio, GC::Ref<DOM::Element> target);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
@ -62,13 +62,13 @@ private:
|
|||
HighResolutionTime::DOMHighResTimeStamp m_time { 0.0 };
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-rootbounds
|
||||
JS::GCPtr<Geometry::DOMRectReadOnly> m_root_bounds;
|
||||
GC::Ptr<Geometry::DOMRectReadOnly> m_root_bounds;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-boundingclientrect
|
||||
JS::NonnullGCPtr<Geometry::DOMRectReadOnly> m_bounding_client_rect;
|
||||
GC::Ref<Geometry::DOMRectReadOnly> m_bounding_client_rect;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-intersectionrect
|
||||
JS::NonnullGCPtr<Geometry::DOMRectReadOnly> m_intersection_rect;
|
||||
GC::Ref<Geometry::DOMRectReadOnly> m_intersection_rect;
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-isintersecting
|
||||
bool m_is_intersecting { false };
|
||||
|
@ -77,7 +77,7 @@ private:
|
|||
double m_intersection_ratio { 0.0 };
|
||||
|
||||
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-target
|
||||
JS::NonnullGCPtr<DOM::Element> m_target;
|
||||
GC::Ref<DOM::Element> m_target;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue