ladybird/Libraries/LibJS/Runtime/JobCallback.cpp
Shannon Booth f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00

41 lines
1.3 KiB
C++

/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/JobCallback.h>
namespace JS {
GC_DEFINE_ALLOCATOR(JobCallback);
GC::Ref<JobCallback> JobCallback::create(JS::VM& vm, FunctionObject& callback, OwnPtr<CustomData> custom_data)
{
return vm.heap().allocate<JobCallback>(callback, move(custom_data));
}
void JobCallback::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_callback);
}
// 9.5.2 HostMakeJobCallback ( callback ), https://tc39.es/ecma262/#sec-hostmakejobcallback
GC::Ref<JobCallback> make_job_callback(FunctionObject& callback)
{
// 1. Return the JobCallback Record { [[Callback]]: callback, [[HostDefined]]: empty }.
return JobCallback::create(callback.vm(), callback, {});
}
// 9.5.3 HostCallJobCallback ( jobCallback, V, argumentsList ), https://tc39.es/ecma262/#sec-hostcalljobcallback
ThrowCompletionOr<Value> call_job_callback(VM& vm, GC::Ref<JobCallback> job_callback, Value this_value, ReadonlySpan<Value> arguments_list)
{
// 1. Assert: IsCallable(jobCallback.[[Callback]]) is true.
// 2. Return ? Call(jobCallback.[[Callback]], V, argumentsList).
return call(vm, job_callback->callback(), this_value, arguments_list);
}
}