diff --git a/Libraries/LibJS/Runtime/NativeFunction.cpp b/Libraries/LibJS/Runtime/NativeFunction.cpp index 1f49345dd77..6ff303cb446 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2025, Andreas Kling * Copyright (c) 2021-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -26,7 +25,7 @@ void NativeFunction::initialize(Realm& realm) void NativeFunction::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(m_native_function); + visitor.visit_possible_values(m_native_function.raw_capture_range()); visitor.visit(m_realm); visitor.visit(m_name_string); } @@ -52,7 +51,7 @@ GC::Ref NativeFunction::create(Realm& allocating_realm, Function // 7. Set func.[[Extensible]] to true. // 8. Set func.[[Realm]] to realm. // 9. Set func.[[InitialName]] to null. - auto function = allocating_realm.create(GC::create_function(vm.heap(), move(behaviour)), prototype, *realm.value()); + auto function = allocating_realm.create(move(behaviour), prototype, *realm.value()); function->unsafe_set_shape(realm.value()->intrinsics().native_function_shape()); @@ -71,10 +70,10 @@ GC::Ref NativeFunction::create(Realm& allocating_realm, Function GC::Ref NativeFunction::create(Realm& realm, FlyString const& name, Function(VM&)> function) { - return realm.create(name, GC::create_function(realm.heap(), move(function)), realm.intrinsics().function_prototype()); + return realm.create(name, move(function), realm.intrinsics().function_prototype()); } -NativeFunction::NativeFunction(GC::Ptr(VM&)>> native_function, Object* prototype, Realm& realm) +NativeFunction::NativeFunction(AK::Function(VM&)> native_function, Object* prototype, Realm& realm) : FunctionObject(realm, prototype) , m_native_function(move(native_function)) , m_realm(&realm) @@ -91,7 +90,7 @@ NativeFunction::NativeFunction(Object& prototype) { } -NativeFunction::NativeFunction(FlyString name, GC::Ptr(VM&)>> native_function, Object& prototype) +NativeFunction::NativeFunction(FlyString name, AK::Function(VM&)> native_function, Object& prototype) : FunctionObject(prototype) , m_name(move(name)) , m_native_function(move(native_function)) @@ -231,7 +230,7 @@ ThrowCompletionOr> NativeFunction::internal_construct(ReadonlySp ThrowCompletionOr NativeFunction::call() { VERIFY(m_native_function); - return m_native_function->function()(vm()); + return m_native_function(vm()); } ThrowCompletionOr> NativeFunction::construct(FunctionObject&) diff --git a/Libraries/LibJS/Runtime/NativeFunction.h b/Libraries/LibJS/Runtime/NativeFunction.h index 19875d56ad3..502be0d77e9 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.h +++ b/Libraries/LibJS/Runtime/NativeFunction.h @@ -44,8 +44,8 @@ public: protected: NativeFunction(FlyString name, Object& prototype); - NativeFunction(GC::Ptr(VM&)>>, Object* prototype, Realm& realm); - NativeFunction(FlyString name, GC::Ptr(VM&)>>, Object& prototype); + NativeFunction(AK::Function(VM&)>, Object* prototype, Realm& realm); + NativeFunction(FlyString name, AK::Function(VM&)>, Object& prototype); explicit NativeFunction(Object& prototype); virtual void initialize(Realm&) override; @@ -57,7 +57,7 @@ private: FlyString m_name; GC::Ptr m_name_string; Optional m_initial_name; // [[InitialName]] - GC::Ptr(VM&)>> m_native_function; + AK::Function(VM&)> m_native_function; GC::Ptr m_realm; }; diff --git a/Libraries/LibWeb/WebAssembly/WebAssembly.cpp b/Libraries/LibWeb/WebAssembly/WebAssembly.cpp index 50eb5262e39..a9520929dd0 100644 --- a/Libraries/LibWeb/WebAssembly/WebAssembly.cpp +++ b/Libraries/LibWeb/WebAssembly/WebAssembly.cpp @@ -375,16 +375,15 @@ GC_DEFINE_ALLOCATOR(ExportedWasmFunction); GC::Ref ExportedWasmFunction::create(JS::Realm& realm, FlyString const& name, Function(JS::VM&)> behavior, Wasm::FunctionAddress exported_address) { - auto& vm = realm.vm(); auto prototype = realm.intrinsics().function_prototype(); return realm.create( name, - GC::create_function(vm.heap(), move(behavior)), + move(behavior), exported_address, prototype); } -ExportedWasmFunction::ExportedWasmFunction(FlyString name, GC::Ptr(JS::VM&)>> behavior, Wasm::FunctionAddress exported_address, JS::Object& prototype) +ExportedWasmFunction::ExportedWasmFunction(FlyString name, AK::Function(JS::VM&)> behavior, Wasm::FunctionAddress exported_address, JS::Object& prototype) : NativeFunction(move(name), move(behavior), prototype) , m_exported_address(exported_address) { diff --git a/Libraries/LibWeb/WebAssembly/WebAssembly.h b/Libraries/LibWeb/WebAssembly/WebAssembly.h index 45ff067db9b..1689e7b42c9 100644 --- a/Libraries/LibWeb/WebAssembly/WebAssembly.h +++ b/Libraries/LibWeb/WebAssembly/WebAssembly.h @@ -77,7 +77,7 @@ public: Wasm::FunctionAddress exported_address() const { return m_exported_address; } protected: - ExportedWasmFunction(FlyString name, GC::Ptr(JS::VM&)>>, Wasm::FunctionAddress, Object& prototype); + ExportedWasmFunction(FlyString name, AK::Function(JS::VM&)>, Wasm::FunctionAddress, Object& prototype); private: Wasm::FunctionAddress m_exported_address;