mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
LibJS: Separate raw and capturing native functions
NativeFunction previously stored an AK::Function for every builtin, even when the callable was just a plain C++ entry point. That mixed together two different representations, made simple builtins carry capture storage they did not need, and forced the GC to treat every native function as if it might contain captured JS values. Introduce RawNativeFunction for plain NativeFunctionPointer callees and keep AK::Function-backed callables on a CapturingNativeFunction subclass. Update the straightforward native registrations in LibJS and LibWeb to use the raw representation, while leaving exported Wasm functions on the capturing path because they still capture state. Wrap UniversalGlobalScope's byte-length strategy lambda in Function<...> explicitly so it keeps selecting the capturing NativeFunction::create overload.
This commit is contained in:
committed by
Andreas Kling
parent
fadea53343
commit
8a9d5ee1a1
Notes:
github-actions[bot]
2026-04-15 13:59:08 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/8a9d5ee1a12 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8922 Reviewed-by: https://github.com/shannonbooth
@@ -1404,6 +1404,17 @@ 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, NativeFunctionPointer getter, NativeFunctionPointer setter, PropertyAttributes attribute)
|
||||
{
|
||||
FunctionObject* getter_function = nullptr;
|
||||
if (getter)
|
||||
getter_function = NativeFunction::create(realm, move(getter), 0, property_key, &realm, "get"sv);
|
||||
FunctionObject* setter_function = nullptr;
|
||||
if (setter)
|
||||
setter_function = NativeFunction::create(realm, move(setter), 1, property_key, &realm, "set"sv);
|
||||
define_direct_accessor(property_key, getter_function, setter_function, attribute);
|
||||
}
|
||||
|
||||
void Object::define_native_accessor(Realm& realm, PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&)> getter, Function<ThrowCompletionOr<Value>(VM&)> setter, PropertyAttributes attribute)
|
||||
{
|
||||
FunctionObject* getter_function = nullptr;
|
||||
@@ -1510,6 +1521,12 @@ Value Object::get_without_side_effects(PropertyKey const& property_key) const
|
||||
return {};
|
||||
}
|
||||
|
||||
void Object::define_native_function(Realm& realm, PropertyKey const& property_key, NativeFunctionPointer native_function, i32 length, PropertyAttributes attribute, Optional<Bytecode::Builtin> builtin)
|
||||
{
|
||||
auto function = NativeFunction::create(realm, move(native_function), length, property_key, &realm, {}, builtin);
|
||||
define_direct_property(property_key, function, attribute);
|
||||
}
|
||||
|
||||
void Object::define_native_function(Realm& realm, PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&)> native_function, i32 length, PropertyAttributes attribute, Optional<Bytecode::Builtin> builtin)
|
||||
{
|
||||
auto function = NativeFunction::create(realm, move(native_function), length, property_key, &realm, {}, builtin);
|
||||
|
||||
Reference in New Issue
Block a user