-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathWasmtimeModule.cs
More file actions
41 lines (32 loc) · 1.01 KB
/
WasmtimeModule.cs
File metadata and controls
41 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using HakoJS.Backend.Core;
using Wasmtime;
namespace HakoJS.Backend.Wasmtime;
public sealed class WasmtimeModule : WasmModule
{
private readonly Module _module;
private bool _disposed;
internal WasmtimeModule(Module module, string name)
{
_module = module;
Name = name;
}
public override string Name { get; }
public override WasmInstance Instantiate(WasmLinker linker)
{
ObjectDisposedException.ThrowIf(_disposed, this);
if (linker is not WasmtimeLinker wasmtimeLinker)
throw new ArgumentException("Linker must be a WasmtimeLinker instance", nameof(linker));
var instance = wasmtimeLinker.UnderlyingLinker.Instantiate(wasmtimeLinker.UnderlyingStore, _module);
return new WasmtimeInstance(instance);
}
protected override void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing) _module.Dispose();
_disposed = true;
}
base.Dispose(disposing);
}
}