mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 11:37:16 +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
@@ -575,11 +575,24 @@ GC::Ref<ExportedWasmFunction> ExportedWasmFunction::create(JS::Realm& realm, Utf
|
||||
}
|
||||
|
||||
ExportedWasmFunction::ExportedWasmFunction(Utf16FlyString name, AK::Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)> behavior, Wasm::FunctionAddress exported_address, JS::Object& prototype)
|
||||
: NativeFunction(move(name), move(behavior), prototype)
|
||||
: NativeFunction(move(name), prototype)
|
||||
, m_behavior(move(behavior))
|
||||
, m_exported_address(exported_address)
|
||||
{
|
||||
}
|
||||
|
||||
void ExportedWasmFunction::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
NativeFunction::visit_edges(visitor);
|
||||
visitor.visit_possible_values(m_behavior.raw_capture_range());
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Value> ExportedWasmFunction::call()
|
||||
{
|
||||
VERIFY(m_behavior);
|
||||
return m_behavior(vm());
|
||||
}
|
||||
|
||||
JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress address, Utf16FlyString name, Instance* instance)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
Reference in New Issue
Block a user