/* * Copyright (c) 2021, Ali Mohammad Pur * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace Web::WebAssembly { void visit_edges(JS::Cell::Visitor&); bool validate(JS::VM&, JS::Handle& bytes); WebIDL::ExceptionOr compile(JS::VM&, JS::Handle& bytes); WebIDL::ExceptionOr instantiate(JS::VM&, JS::Handle& bytes, Optional>& import_object); WebIDL::ExceptionOr instantiate(JS::VM&, Module const& module_object, Optional>& import_object); namespace Detail { JS::ThrowCompletionOr instantiate_module(JS::VM&, Wasm::Module const&); JS::ThrowCompletionOr parse_module(JS::VM&, JS::Object* buffer); JS::NativeFunction* create_native_function(JS::VM&, Wasm::FunctionAddress address, DeprecatedString const& name); JS::ThrowCompletionOr to_webassembly_value(JS::VM&, JS::Value value, Wasm::ValueType const& type); JS::Value to_js_value(JS::VM&, Wasm::Value& wasm_value); struct CompiledWebAssemblyModule { explicit CompiledWebAssemblyModule(Wasm::Module&& module) : module(move(module)) { } Wasm::Module module; }; // FIXME: These should just be members of the module (instance) object, but the module needs to stick // around while its instance is alive so ideally this would be a refcounted object, shared between // WebAssemblyModuleObject's and WebAssemblyInstantiatedModuleObject's. struct ModuleCache { HashMap> function_instances; HashMap> memory_instances; HashMap> table_instances; }; struct GlobalModuleCache { HashMap> function_instances; }; extern Vector> s_compiled_modules; extern Vector> s_instantiated_modules; extern Vector s_module_caches; extern GlobalModuleCache s_global_cache; extern Wasm::AbstractMachine s_abstract_machine; } }