mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
LibJS: Make define_native_foo() take SafeFunctions
We were taking AK::Function and then passing them along to NativeFunction, which takes a SafeFunction. This works, since SafeFunction will transparently wrap AK::Function in a CallableWrapper when assigned, but it was causing us to accumulate thousands of pointless wrappers around direct function pointers. By using SafeFunction at every step of the setup call chain, we no longer create any CallableWrappers for the majority of native functions in LibJS. Also, the number of heap-registered SafeFunctions in a new realm goes down from ~5000 to 5. :^)
This commit is contained in:
parent
202cc025e5
commit
e23fe8cf87
2 changed files with 5 additions and 4 deletions
|
@ -1069,7 +1069,7 @@ void Object::set_prototype(Object* new_prototype)
|
|||
m_shape = shape.create_prototype_transition(new_prototype);
|
||||
}
|
||||
|
||||
void Object::define_native_accessor(Realm& realm, PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&)> getter, Function<ThrowCompletionOr<Value>(VM&)> setter, PropertyAttributes attribute)
|
||||
void Object::define_native_accessor(Realm& realm, PropertyKey const& property_key, SafeFunction<ThrowCompletionOr<Value>(VM&)> getter, SafeFunction<ThrowCompletionOr<Value>(VM&)> setter, PropertyAttributes attribute)
|
||||
{
|
||||
FunctionObject* getter_function = nullptr;
|
||||
if (getter)
|
||||
|
@ -1118,7 +1118,7 @@ Value Object::get_without_side_effects(PropertyKey const& property_key) const
|
|||
return {};
|
||||
}
|
||||
|
||||
void Object::define_native_function(Realm& realm, PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&)> native_function, i32 length, PropertyAttributes attribute)
|
||||
void Object::define_native_function(Realm& realm, PropertyKey const& property_key, SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, i32 length, PropertyAttributes attribute)
|
||||
{
|
||||
auto* function = NativeFunction::create(realm, move(native_function), length, property_key, &realm);
|
||||
define_direct_property(property_key, function, attribute);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue