mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibWeb: Make AbortController GC-allocated
This commit is contained in:
parent
18ca15b2cc
commit
b8d485e6f0
Notes:
sideshowbarker
2024-07-17 07:27:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b8d485e6f0 Pull-request: https://github.com/SerenityOS/serenity/pull/14816 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg ✅
@ -4,15 +4,32 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/AbortControllerPrototype.h>
|
||||
#include <LibWeb/DOM/AbortController.h>
|
||||
#include <LibWeb/DOM/AbortSignal.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller
|
||||
AbortController::AbortController(HTML::Window& window)
|
||||
: m_signal(JS::make_handle(*AbortSignal::create_with_global_object(window)))
|
||||
JS::NonnullGCPtr<AbortController> AbortController::create_with_global_object(HTML::Window& window)
|
||||
{
|
||||
auto signal = AbortSignal::create_with_global_object(window);
|
||||
return *window.heap().allocate<AbortController>(window.realm(), window, move(signal));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller
|
||||
AbortController::AbortController(HTML::Window& window, JS::NonnullGCPtr<AbortSignal> signal)
|
||||
: PlatformObject(window.realm())
|
||||
, m_signal(move(signal))
|
||||
{
|
||||
set_prototype(&window.ensure_web_prototype<Bindings::AbortControllerPrototype>("AbortController"));
|
||||
}
|
||||
|
||||
AbortController::~AbortController() = default;
|
||||
|
||||
void AbortController::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_signal.ptr());
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-abortcontroller-abort
|
||||
|
@ -6,29 +6,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/AbortSignal.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
// https://dom.spec.whatwg.org/#abortcontroller
|
||||
class AbortController final
|
||||
: public RefCounted<AbortController>
|
||||
, public Weakable<AbortController>
|
||||
, public Bindings::Wrappable {
|
||||
class AbortController final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(AbortController, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
using WrapperType = Bindings::AbortControllerWrapper;
|
||||
static JS::NonnullGCPtr<AbortController> create_with_global_object(HTML::Window&);
|
||||
|
||||
static NonnullRefPtr<AbortController> create_with_global_object(HTML::Window& window)
|
||||
{
|
||||
return adopt_ref(*new AbortController(window));
|
||||
}
|
||||
|
||||
virtual ~AbortController() override = default;
|
||||
virtual ~AbortController() override;
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-abortcontroller-signal
|
||||
JS::NonnullGCPtr<AbortSignal> signal() const { return *m_signal; }
|
||||
@ -36,10 +26,14 @@ public:
|
||||
void abort(JS::Value reason);
|
||||
|
||||
private:
|
||||
explicit AbortController(HTML::Window&);
|
||||
AbortController(HTML::Window&, JS::NonnullGCPtr<AbortSignal>);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
// https://dom.spec.whatwg.org/#abortcontroller-signal
|
||||
JS::Handle<AbortSignal> m_signal;
|
||||
JS::NonnullGCPtr<AbortSignal> m_signal;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(AbortController, Web::DOM)
|
||||
|
@ -448,7 +448,6 @@ class URLSearchParamsIterator;
|
||||
}
|
||||
|
||||
namespace Web::Bindings {
|
||||
class AbortControllerWrapper;
|
||||
class BlobWrapper;
|
||||
class CanvasGradientWrapper;
|
||||
class CanvasRenderingContext2DWrapper;
|
||||
|
@ -22,7 +22,7 @@ libweb_js_wrapper(CSS/StyleSheet NO_INSTANCE)
|
||||
libweb_js_wrapper(CSS/StyleSheetList NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/AbstractRange NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/Attribute NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/AbortController)
|
||||
libweb_js_wrapper(DOM/AbortController NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/AbortSignal NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/CDATASection NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/CharacterData NO_INSTANCE)
|
||||
|
Loading…
Reference in New Issue
Block a user