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

LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated

This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
This commit is contained in:
Andreas Kling 2022-08-28 13:42:07 +02:00
parent bb547ce1c4
commit 6f433c8656
445 changed files with 4797 additions and 4268 deletions

View file

@ -5,22 +5,22 @@
*/
#include <LibWeb/Bindings/WebGLContextEventPrototype.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/WebGL/WebGLContextEvent.h>
namespace Web::WebGL {
WebGLContextEvent* WebGLContextEvent::create(Bindings::WindowObject& window_object, FlyString const& event_name, WebGLContextEventInit const& event_init)
WebGLContextEvent* WebGLContextEvent::create(HTML::Window& window_object, FlyString const& event_name, WebGLContextEventInit const& event_init)
{
return window_object.heap().allocate<WebGLContextEvent>(window_object.realm(), window_object, event_name, event_init);
}
WebGLContextEvent* WebGLContextEvent::create_with_global_object(Bindings::WindowObject& window_object, FlyString const& event_name, WebGLContextEventInit const& event_init)
WebGLContextEvent* WebGLContextEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, WebGLContextEventInit const& event_init)
{
return create(window_object, event_name, event_init);
}
WebGLContextEvent::WebGLContextEvent(Bindings::WindowObject& window_object, FlyString const& type, WebGLContextEventInit const& event_init)
WebGLContextEvent::WebGLContextEvent(HTML::Window& window_object, FlyString const& type, WebGLContextEventInit const& event_init)
: DOM::Event(window_object, type, event_init)
, m_status_message(event_init.status_message)
{

View file

@ -16,18 +16,16 @@ struct WebGLContextEventInit final : public DOM::EventInit {
};
class WebGLContextEvent final : public DOM::Event {
JS_OBJECT(WebGLContextEvent, DOM::Event);
WEB_PLATFORM_OBJECT(WebGLContextEvent, DOM::Event);
public:
static WebGLContextEvent* create(Bindings::WindowObject&, FlyString const& type, WebGLContextEventInit const& event_init);
static WebGLContextEvent* create_with_global_object(Bindings::WindowObject&, FlyString const& type, WebGLContextEventInit const& event_init);
static WebGLContextEvent* create(HTML::Window&, FlyString const& type, WebGLContextEventInit const& event_init);
static WebGLContextEvent* create_with_global_object(HTML::Window&, FlyString const& type, WebGLContextEventInit const& event_init);
WebGLContextEvent(Bindings::WindowObject&, FlyString const& type, WebGLContextEventInit const& event_init);
WebGLContextEvent(HTML::Window&, FlyString const& type, WebGLContextEventInit const& event_init);
virtual ~WebGLContextEvent() override;
WebGLContextEvent& impl() { return *this; }
String const& status_message() const { return m_status_message; }
private:

View file

@ -17,7 +17,7 @@ static void fire_webgl_context_event(HTML::HTMLCanvasElement& canvas_element, Fl
{
// To fire a WebGL context event named e means that an event using the WebGLContextEvent interface, with its type attribute [DOM4] initialized to e, its cancelable attribute initialized to true, and its isTrusted attribute [DOM4] initialized to true, is to be dispatched at the given object.
// FIXME: Consider setting a status message.
auto event = WebGLContextEvent::create(canvas_element.document().preferred_window_object(), type, WebGLContextEventInit {});
auto event = WebGLContextEvent::create(canvas_element.document().window(), type, WebGLContextEventInit {});
event->set_is_trusted(true);
event->set_cancelable(true);
canvas_element.dispatch_event(*event);
@ -33,8 +33,7 @@ static void fire_webgl_context_creation_error(HTML::HTMLCanvasElement& canvas_el
JS::ThrowCompletionOr<RefPtr<WebGLRenderingContext>> WebGLRenderingContext::create(HTML::HTMLCanvasElement& canvas_element, JS::Value options)
{
// We should be coming here from getContext being called on a wrapped <canvas> element.
VERIFY(canvas_element.wrapper());
auto context_attributes = TRY(convert_value_to_context_attributes_dictionary(canvas_element.wrapper()->vm(), options));
auto context_attributes = TRY(convert_value_to_context_attributes_dictionary(canvas_element.vm(), options));
bool created_bitmap = canvas_element.create_bitmap(/* minimum_width= */ 1, /* minimum_height= */ 1);
if (!created_bitmap) {

View file

@ -12,7 +12,7 @@
namespace Web::WebGL {
WebGLRenderingContextBase::WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
: RefCountForwarder(canvas_element)
: m_canvas_element(canvas_element)
, m_context(move(context))
, m_context_creation_parameters(move(context_creation_parameters))
, m_actual_context_parameters(move(actual_context_parameters))
@ -69,17 +69,17 @@ void WebGLRenderingContextBase::present()
HTML::HTMLCanvasElement& WebGLRenderingContextBase::canvas_element()
{
return ref_count_target();
return *m_canvas_element;
}
HTML::HTMLCanvasElement const& WebGLRenderingContextBase::canvas_element() const
{
return ref_count_target();
return *m_canvas_element;
}
NonnullRefPtr<HTML::HTMLCanvasElement> WebGLRenderingContextBase::canvas_for_binding() const
JS::NonnullGCPtr<HTML::HTMLCanvasElement> WebGLRenderingContextBase::canvas_for_binding() const
{
return canvas_element();
return *m_canvas_element;
}
void WebGLRenderingContextBase::needs_to_present()

View file

@ -16,14 +16,14 @@
namespace Web::WebGL {
class WebGLRenderingContextBase
: public RefCountForwarder<HTML::HTMLCanvasElement>
: public RefCounted<WebGLRenderingContextBase>
, public Weakable<WebGLRenderingContextBase> {
public:
virtual ~WebGLRenderingContextBase();
void present();
NonnullRefPtr<HTML::HTMLCanvasElement> canvas_for_binding() const;
JS::NonnullGCPtr<HTML::HTMLCanvasElement> canvas_for_binding() const;
bool is_context_lost() const;
@ -65,6 +65,8 @@ protected:
WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
private:
JS::Handle<HTML::HTMLCanvasElement> m_canvas_element;
NonnullOwnPtr<GL::GLContext> m_context;
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#context-creation-parameters