/* * Copyright (c) 2021, Ali Mohammad Pur * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include namespace Web::WebAssembly { WebIDL::ExceptionOr> Module::construct_impl(JS::Realm& realm, JS::Handle& bytes) { auto& vm = realm.vm(); auto index = TRY(Detail::parse_module(vm, bytes.cell())); return MUST_OR_THROW_OOM(vm.heap().allocate(realm, realm, index)); } Module::Module(JS::Realm& realm, size_t index) : Bindings::PlatformObject(realm) , m_index(index) { } JS::ThrowCompletionOr Module::initialize(JS::Realm& realm) { MUST_OR_THROW_OOM(Base::initialize(realm)); set_prototype(&Bindings::ensure_web_prototype(realm, "WebAssembly.Module"sv)); return {}; } Wasm::Module const& Module::module() const { return Detail::s_compiled_modules.at(index())->module; } }