LibWeb: Make IntersectionObserver GC-allocated

This commit is contained in:
Andreas Kling 2022-09-04 14:14:22 +02:00
parent fe9c5395d4
commit 25daa14a05
Notes: sideshowbarker 2024-07-17 07:24:50 +09:00
4 changed files with 24 additions and 14 deletions

View File

@ -449,7 +449,6 @@ class URLSearchParamsIterator;
namespace Web::Bindings {
class DOMExceptionWrapper;
class IntersectionObserverWrapper;
class LocationObject;
class OptionConstructor;
class RangePrototype;

View File

@ -5,20 +5,29 @@
*/
#include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/IntersectionObserver/IntersectionObserver.h>
namespace Web::IntersectionObserver {
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-intersectionobserver
NonnullRefPtr<IntersectionObserver> IntersectionObserver::create_with_global_object(HTML::Window&, Bindings::CallbackType* callback, IntersectionObserverInit const& options)
JS::NonnullGCPtr<IntersectionObserver> IntersectionObserver::create_with_global_object(HTML::Window& window, Bindings::CallbackType* callback, IntersectionObserverInit const& options)
{
// FIXME: Implement
(void)callback;
(void)options;
return adopt_ref(*new IntersectionObserver);
return *window.heap().allocate<IntersectionObserver>(window.realm(), window);
}
IntersectionObserver::IntersectionObserver(HTML::Window& window)
: PlatformObject(window.realm())
{
set_prototype(&window.cached_web_prototype("IntersectionObserver"));
}
IntersectionObserver::~IntersectionObserver() = default;
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-observe
void IntersectionObserver::observe(DOM::Element& target)
{

View File

@ -6,10 +6,7 @@
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::IntersectionObserver {
@ -20,17 +17,22 @@ struct IntersectionObserverInit {
};
// https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
class IntersectionObserver
: public RefCounted<IntersectionObserver>
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::IntersectionObserverWrapper;
class IntersectionObserver : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject);
static NonnullRefPtr<IntersectionObserver> create_with_global_object(HTML::Window&, Bindings::CallbackType* callback, IntersectionObserverInit const& options = {});
public:
static JS::NonnullGCPtr<IntersectionObserver> create_with_global_object(HTML::Window&, Bindings::CallbackType* callback, IntersectionObserverInit const& options = {});
virtual ~IntersectionObserver() override;
void observe(DOM::Element& target);
void unobserve(DOM::Element& target);
void disconnect();
private:
explicit IntersectionObserver(HTML::Window&);
};
}
WRAPPER_HACK(IntersectionObserver, Web::IntersectionObserver)

View File

@ -155,7 +155,7 @@ libweb_js_wrapper(HTML/WorkerGlobalScope NO_INSTANCE)
libweb_js_wrapper(HTML/WorkerLocation)
libweb_js_wrapper(HTML/WorkerNavigator)
libweb_js_wrapper(HighResolutionTime/Performance NO_INSTANCE)
libweb_js_wrapper(IntersectionObserver/IntersectionObserver)
libweb_js_wrapper(IntersectionObserver/IntersectionObserver NO_INSTANCE)
libweb_js_wrapper(NavigationTiming/PerformanceTiming NO_INSTANCE)
libweb_js_wrapper(RequestIdleCallback/IdleDeadline NO_INSTANCE)
libweb_js_wrapper(ResizeObserver/ResizeObserver NO_INSTANCE)