mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +00:00
LibWeb/WebAssembly: Use wasm funcaddr of exported functions on import
Previously this was proxying the call through javascript, which lead to unexpected crashes when functions returned things that js-api did not like. This commit also adds in the spec comments and fixes a few inaccuracies that were present in the process.
This commit is contained in:
parent
c0285f4a7e
commit
e32a9b2c6f
Notes:
github-actions[bot]
2024-12-21 19:17:04 +00:00
Author: https://github.com/alimpfard
Commit: e32a9b2c6f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3003
2 changed files with 135 additions and 53 deletions
|
@ -11,9 +11,9 @@
|
|||
#include <LibGC/Root.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWasm/AbstractMachine/AbstractMachine.h>
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::WebAssembly {
|
||||
|
@ -62,6 +62,23 @@ private:
|
|||
Wasm::AbstractMachine m_abstract_machine;
|
||||
};
|
||||
|
||||
class ExportedWasmFunction final : public JS::NativeFunction {
|
||||
JS_OBJECT(ExportedWasmFunction, JS::NativeFunction);
|
||||
GC_DECLARE_ALLOCATOR(ExportedWasmFunction);
|
||||
|
||||
public:
|
||||
static GC::Ref<ExportedWasmFunction> create(JS::Realm&, DeprecatedFlyString const& name, ESCAPING Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>, Wasm::FunctionAddress);
|
||||
virtual ~ExportedWasmFunction() override = default;
|
||||
|
||||
Wasm::FunctionAddress exported_address() const { return m_exported_address; }
|
||||
|
||||
protected:
|
||||
ExportedWasmFunction(DeprecatedFlyString name, GC::Ptr<GC::Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>>, Wasm::FunctionAddress, Object& prototype);
|
||||
|
||||
private:
|
||||
Wasm::FunctionAddress m_exported_address;
|
||||
};
|
||||
|
||||
WebAssemblyCache& get_cache(JS::Realm&);
|
||||
|
||||
JS::ThrowCompletionOr<NonnullOwnPtr<Wasm::ModuleInstance>> instantiate_module(JS::VM&, Wasm::Module const&, GC::Ptr<JS::Object> import_object);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue