1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:28:11 +00:00

LibWasm+LibWeb: Partially resolve memory exports

This allows the JS side to access the wasm memory, assuming it's
exported by the module.
This can be used to draw stuff on the wasm side and display them from
the js side, for example :^)
This commit is contained in:
Ali Mohammad Pur 2021-05-17 21:42:56 +04:30 committed by Ali Mohammad Pur
parent 4a459d2430
commit cf8b75c2e5
6 changed files with 173 additions and 49 deletions

View file

@ -9,6 +9,7 @@
#include <LibJS/Runtime/Object.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebAssembly/WebAssemblyObjectPrototype.h>
namespace Web::Bindings {
@ -58,21 +59,6 @@ private:
size_t m_index { 0 };
};
class WebAssemblyInstancePrototype final : public JS::Object {
JS_OBJECT(WebAssemblyInstancePrototype, JS::Object);
public:
explicit WebAssemblyInstancePrototype(JS::GlobalObject& global_object)
: JS::Object(global_object)
{
}
virtual void initialize(JS::GlobalObject&) override;
private:
JS_DECLARE_NATIVE_GETTER(exports_getter);
};
class WebAssemblyInstanceObject final : public JS::Object {
JS_OBJECT(WebAssemblyInstanceObject, JS::Object);
@ -93,4 +79,21 @@ private:
JS::Object* m_exports_object { nullptr };
};
class WebAssemblyMemoryObject final : public JS::Object {
JS_OBJECT(WebAssemblyModuleObject, JS::Object);
public:
explicit WebAssemblyMemoryObject(JS::GlobalObject&, Wasm::MemoryAddress);
virtual void initialize(JS::GlobalObject&) override;
virtual ~WebAssemblyMemoryObject() override = default;
auto address() const { return m_address; }
private:
JS_DECLARE_NATIVE_FUNCTION(grow);
JS_DECLARE_NATIVE_GETTER(buffer);
Wasm::MemoryAddress m_address;
};
}