LibJS: Allow JS::create_heap_function to accept a lambda

This helps us avoid from needing to construct a Function<T> when
invoking `create_heap_function` with a lambda.

Co-Authored-By: Ali Mohammad Pur <mpfard@serenityos.org>
This commit is contained in:
Shannon Booth 2024-01-26 22:42:32 +13:00 committed by Tim Flynn
parent c6319d68c3
commit e118430648
Notes: sideshowbarker 2024-07-17 05:03:11 +09:00

View file

@ -41,10 +41,10 @@ private:
Function<T> m_function;
};
template<typename T>
static NonnullGCPtr<HeapFunction<T>> create_heap_function(Heap& heap, Function<T> function)
template<typename Callable, typename T = EquivalentFunctionType<Callable>>
static NonnullGCPtr<HeapFunction<T>> create_heap_function(Heap& heap, Callable&& function)
{
return HeapFunction<T>::create(heap, move(function));
return HeapFunction<T>::create(heap, Function<T> { forward<Callable>(function) });
}
}