ladybird/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp
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

31 lines
806 B
C++

/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/PromiseCapability.h>
#include <LibJS/Runtime/PromiseReaction.h>
#include <LibJS/Runtime/VM.h>
namespace JS {
PromiseReaction* PromiseReaction::create(VM& vm, Type type, GCPtr<PromiseCapability> capability, Optional<JobCallback> handler)
{
return vm.heap().allocate_without_realm<PromiseReaction>(type, capability, move(handler));
}
PromiseReaction::PromiseReaction(Type type, GCPtr<PromiseCapability> capability, Optional<JobCallback> handler)
: m_type(type)
, m_capability(capability)
, m_handler(move(handler))
{
}
void PromiseReaction::visit_edges(Cell::Visitor& visitor)
{
Cell::visit_edges(visitor);
visitor.visit(m_capability);
}
}