mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 06:29:43 +00:00
This cache is referenced by a few parts of the JS API spec, including the threads spec (such as in toFixedLengthBuffer), as well as the "refresh the Memory buffer" algorithm, which was implemented as a method of Memory before this change. Now, this algorithm can be implemented in a spec-like fashion (though it mostly seems to add extra complexity). This change also fixes a bug where memories that were re-exported from an imported WebAssembly.Memory were given a distinct WebAssembly.Memory object, since the caching that existed in Instance.cpp was instance-local, not global to the realm. We also make Memory::m_buffer non-lazy, since we have to implement "initialize a memory object" correctly anyway.
42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Optional.h>
|
|
#include <LibGC/Ptr.h>
|
|
#include <LibGC/Root.h>
|
|
#include <LibJS/Forward.h>
|
|
#include <LibWasm/AbstractMachine/AbstractMachine.h>
|
|
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
#include <LibWeb/WebAssembly/WebAssembly.h>
|
|
|
|
namespace Web::WebAssembly {
|
|
|
|
class Instance : public Bindings::PlatformObject {
|
|
WEB_PLATFORM_OBJECT(Instance, Bindings::PlatformObject);
|
|
GC_DECLARE_ALLOCATOR(Instance);
|
|
|
|
public:
|
|
static WebIDL::ExceptionOr<GC::Ref<Instance>> construct_impl(JS::Realm&, Module& module, Optional<GC::Root<JS::Object>>& import_object);
|
|
|
|
Object const* exports() const { return m_exports.ptr(); }
|
|
|
|
private:
|
|
Instance(JS::Realm&, NonnullOwnPtr<Wasm::ModuleInstance>);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
GC::Ref<Object> m_exports;
|
|
NonnullOwnPtr<Wasm::ModuleInstance> m_module_instance;
|
|
HashMap<Wasm::FunctionAddress, GC::Ptr<JS::FunctionObject>> m_function_instances;
|
|
HashMap<Wasm::TableAddress, GC::Ptr<WebAssembly::Table>> m_table_instances;
|
|
};
|
|
|
|
}
|