mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-16 23:39:44 +00:00
LibJS: Implement the AsyncDisposableStack interface
This is very similar to the DisposableStack interface, except disposal of resources is promise-based.
This commit is contained in:
parent
5ea0aa5f08
commit
26c2484c2f
Notes:
github-actions[bot]
2025-01-17 19:47:28 +00:00
Author: https://github.com/trflynn89
Commit: 26c2484c2f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3290
22 changed files with 873 additions and 0 deletions
41
Libraries/LibJS/Runtime/AsyncDisposableStack.h
Normal file
41
Libraries/LibJS/Runtime/AsyncDisposableStack.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class AsyncDisposableStack final : public Object {
|
||||
JS_OBJECT(AsyncDisposableStack, Object);
|
||||
GC_DECLARE_ALLOCATOR(AsyncDisposableStack);
|
||||
|
||||
public:
|
||||
virtual ~AsyncDisposableStack() override = default;
|
||||
|
||||
enum class AsyncDisposableState {
|
||||
Pending,
|
||||
Disposed
|
||||
};
|
||||
|
||||
[[nodiscard]] AsyncDisposableState async_disposable_state() const { return m_async_disposable_state; }
|
||||
void set_disposed() { m_async_disposable_state = AsyncDisposableState::Disposed; }
|
||||
|
||||
[[nodiscard]] DisposeCapability const& dispose_capability() const { return m_dispose_capability; }
|
||||
[[nodiscard]] DisposeCapability& dispose_capability() { return m_dispose_capability; }
|
||||
|
||||
private:
|
||||
AsyncDisposableStack(DisposeCapability, Object& prototype);
|
||||
|
||||
virtual void visit_edges(Visitor& visitor) override;
|
||||
|
||||
DisposeCapability m_dispose_capability;
|
||||
AsyncDisposableState m_async_disposable_state { AsyncDisposableState::Pending };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue