mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:07:43 +00:00
LibJS: Don't register SafeFunction-to-function-pointer with JS::Heap
Direct function pointers don't have captures, so we don't need to register the SafeFunction with the Heap when it's just wrapping a function pointer.
This commit is contained in:
parent
be5a39657e
commit
202cc025e5
1 changed files with 16 additions and 4 deletions
|
@ -35,12 +35,16 @@ public:
|
||||||
|
|
||||||
void register_closure()
|
void register_closure()
|
||||||
{
|
{
|
||||||
|
if (!m_size)
|
||||||
|
return;
|
||||||
if (auto* wrapper = callable_wrapper())
|
if (auto* wrapper = callable_wrapper())
|
||||||
register_safe_function_closure(wrapper, m_size);
|
register_safe_function_closure(wrapper, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_closure()
|
void unregister_closure()
|
||||||
{
|
{
|
||||||
|
if (!m_size)
|
||||||
|
return;
|
||||||
if (auto* wrapper = callable_wrapper())
|
if (auto* wrapper = callable_wrapper())
|
||||||
unregister_safe_function_closure(wrapper, m_size);
|
unregister_safe_function_closure(wrapper, m_size);
|
||||||
}
|
}
|
||||||
|
@ -48,13 +52,13 @@ public:
|
||||||
template<typename CallableType>
|
template<typename CallableType>
|
||||||
SafeFunction(CallableType&& callable) requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...> && !IsSame<RemoveCVReference<CallableType>, SafeFunction>))
|
SafeFunction(CallableType&& callable) requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...> && !IsSame<RemoveCVReference<CallableType>, SafeFunction>))
|
||||||
{
|
{
|
||||||
init_with_callable(forward<CallableType>(callable));
|
init_with_callable(forward<CallableType>(callable), CallableKind::FunctionObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FunctionType>
|
template<typename FunctionType>
|
||||||
SafeFunction(FunctionType f) requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...> && !IsSame<RemoveCVReference<FunctionType>, SafeFunction>))
|
SafeFunction(FunctionType f) requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...> && !IsSame<RemoveCVReference<FunctionType>, SafeFunction>))
|
||||||
{
|
{
|
||||||
init_with_callable(move(f));
|
init_with_callable(move(f), CallableKind::FunctionPointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeFunction(SafeFunction&& other)
|
SafeFunction(SafeFunction&& other)
|
||||||
|
@ -110,6 +114,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum class CallableKind {
|
||||||
|
FunctionPointer,
|
||||||
|
FunctionObject,
|
||||||
|
};
|
||||||
|
|
||||||
class CallableWrapperBase {
|
class CallableWrapperBase {
|
||||||
public:
|
public:
|
||||||
virtual ~CallableWrapperBase() = default;
|
virtual ~CallableWrapperBase() = default;
|
||||||
|
@ -195,7 +204,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callable>
|
template<typename Callable>
|
||||||
void init_with_callable(Callable&& callable)
|
void init_with_callable(Callable&& callable, CallableKind kind)
|
||||||
{
|
{
|
||||||
VERIFY(m_call_nesting_level == 0);
|
VERIFY(m_call_nesting_level == 0);
|
||||||
VERIFY(m_kind == FunctionKind::NullPointer);
|
VERIFY(m_kind == FunctionKind::NullPointer);
|
||||||
|
@ -207,7 +216,10 @@ private:
|
||||||
new (m_storage) WrapperType(forward<Callable>(callable));
|
new (m_storage) WrapperType(forward<Callable>(callable));
|
||||||
m_kind = FunctionKind::Inline;
|
m_kind = FunctionKind::Inline;
|
||||||
}
|
}
|
||||||
m_size = sizeof(WrapperType);
|
if (kind == CallableKind::FunctionObject)
|
||||||
|
m_size = sizeof(WrapperType);
|
||||||
|
else
|
||||||
|
m_size = 0;
|
||||||
register_closure();
|
register_closure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue