/src/serenity/Userland/Libraries/LibWeb/WebAssembly/Module.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org> |
3 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #include <LibJS/Runtime/Realm.h> |
9 | | #include <LibJS/Runtime/VM.h> |
10 | | #include <LibWeb/Bindings/Intrinsics.h> |
11 | | #include <LibWeb/Bindings/ModulePrototype.h> |
12 | | #include <LibWeb/WebAssembly/Module.h> |
13 | | #include <LibWeb/WebAssembly/WebAssembly.h> |
14 | | #include <LibWeb/WebIDL/Buffers.h> |
15 | | |
16 | | namespace Web::WebAssembly { |
17 | | |
18 | | JS_DEFINE_ALLOCATOR(Module); |
19 | | |
20 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<Module>> Module::construct_impl(JS::Realm& realm, JS::Handle<WebIDL::BufferSource>& bytes) |
21 | 0 | { |
22 | 0 | auto& vm = realm.vm(); |
23 | |
|
24 | 0 | auto compiled_module = TRY(Detail::parse_module(vm, bytes->raw_object())); |
25 | 0 | return vm.heap().allocate<Module>(realm, realm, move(compiled_module)); |
26 | 0 | } |
27 | | |
28 | | Module::Module(JS::Realm& realm, NonnullRefPtr<Detail::CompiledWebAssemblyModule> compiled_module) |
29 | 0 | : Bindings::PlatformObject(realm) |
30 | 0 | , m_compiled_module(move(compiled_module)) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | void Module::initialize(JS::Realm& realm) |
35 | 0 | { |
36 | 0 | Base::initialize(realm); |
37 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE_WITH_CUSTOM_NAME(Module, WebAssembly.Module); |
38 | 0 | } |
39 | | |
40 | | } |