ladybird/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
Linus Groh fc9d587e39 LibJS: Make PromiseCapability GC-allocated
A struct with three raw pointers to other GC'd types is a pretty big
liability, let's just turn this into a Cell itself.
This comes with the additional benefit of being able to capture it in
a lambda effortlessly, without having to create handles for individual
members.
2022-10-02 23:02:27 +01:00

46 lines
1.2 KiB
C++

/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Runtime/JobCallback.h>
namespace JS {
// 27.2.1.2 PromiseReaction Records, https://tc39.es/ecma262/#sec-promisereaction-records
class PromiseReaction final : public Cell {
JS_CELL(PromiseReaction, Cell);
public:
enum class Type {
Fulfill,
Reject,
};
static PromiseReaction* create(VM& vm, Type type, GCPtr<PromiseCapability> capability, Optional<JobCallback> handler);
virtual ~PromiseReaction() = default;
Type type() const { return m_type; }
GCPtr<PromiseCapability> capability() const { return m_capability; }
Optional<JobCallback>& handler() { return m_handler; }
Optional<JobCallback> const& handler() const { return m_handler; }
private:
PromiseReaction(Type type, GCPtr<PromiseCapability> capability, Optional<JobCallback> handler);
virtual void visit_edges(Visitor&) override;
Type m_type;
GCPtr<PromiseCapability> m_capability;
Optional<JobCallback> m_handler;
};
}