/* * Copyright (c) 2021, Ali Mohammad Pur * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include namespace Web::WebAssembly { GC_DEFINE_ALLOCATOR(Module); WebIDL::ExceptionOr> Module::construct_impl(JS::Realm& realm, GC::Root& bytes) { auto& vm = realm.vm(); auto stable_bytes_or_error = WebIDL::get_buffer_source_copy(bytes->raw_object()); if (stable_bytes_or_error.is_error()) { VERIFY(stable_bytes_or_error.error().code() == ENOMEM); return vm.throw_completion(vm.error_message(JS::VM::ErrorMessage::OutOfMemory)); } auto stable_bytes = stable_bytes_or_error.release_value(); auto compiled_module = TRY(Detail::compile_a_webassembly_module(vm, move(stable_bytes))); return realm.create(realm, move(compiled_module)); } Module::Module(JS::Realm& realm, NonnullRefPtr compiled_module) : Bindings::PlatformObject(realm) , m_compiled_module(move(compiled_module)) { } void Module::initialize(JS::Realm& realm) { Base::initialize(realm); WEB_SET_PROTOTYPE_FOR_INTERFACE_WITH_CUSTOM_NAME(Module, WebAssembly.Module); } }