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

LibWeb: Add initial support for AbortController and AbortSignal

The DOM specification says that the primary use case for these is to
give Promises abort semantics. It is also a prerequisite for Fetch,
as it is used to make Fetch abortable.
a
This commit is contained in:
Luke Wilde 2021-09-02 02:12:49 +01:00 committed by Andreas Kling
parent dd1a49ff93
commit 1d8f8ea5b1
11 changed files with 254 additions and 0 deletions

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/RefCounted.h>
#include <AK/Weakable.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/AbortSignal.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
// https://dom.spec.whatwg.org/#abortcontroller
class AbortController final
: public RefCounted<AbortController>
, public Weakable<AbortController>
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::AbortControllerWrapper;
static NonnullRefPtr<AbortController> create(Document& document)
{
return adopt_ref(*new AbortController(document));
}
static NonnullRefPtr<AbortController> create_with_global_object(Bindings::WindowObject& window_object)
{
return AbortController::create(window_object.impl().document());
}
virtual ~AbortController() override;
// https://dom.spec.whatwg.org/#dom-abortcontroller-signal
NonnullRefPtr<AbortSignal> signal() const { return m_signal; }
void abort();
private:
AbortController(Document& document);
// https://dom.spec.whatwg.org/#abortcontroller-signal
NonnullRefPtr<AbortSignal> m_signal;
};
}