Represent WebIDL C++ types with a single CppType model that tracks nullability, optional presence, and contained storage. GC-like values now use GC::Ref/GC::Ptr directly, while containers choose "plain", "Root", or "Conservative" container types depending on what they contain. For example, sequence<Element> becomes a RootVector of GC::Ref values, while sequence<SomeDictionary> becomes a ConservativeVector only when the dictionary contains GC-like values. This moves the generated bindings away from wrapping GC values in GC::Root by default. This has broad fallout as the types passed to interfaces for GC objects changes almost fully across the board.
43 lines
1.4 KiB
C++
43 lines
1.4 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, GC::Ptr<JS::Object> import_object);
|
|
|
|
Object const* exports() const { return m_exports.ptr(); }
|
|
Wasm::ModuleInstance const* module_instance() const { return m_module_instance.ptr(); }
|
|
|
|
private:
|
|
Instance(JS::Realm&, NonnullRefPtr<Wasm::ModuleInstance>);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
GC::Ref<Object> m_exports;
|
|
NonnullRefPtr<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;
|
|
};
|
|
|
|
}
|