Favor using non-braced using statement.
This commit is contained in:
@@ -165,10 +165,8 @@ Alternatively, the `run` function could be invoked without using the runtime bin
|
|||||||
|
|
||||||
```c#
|
```c#
|
||||||
...
|
...
|
||||||
using (var instance = module.Instantiate(new Host()))
|
using var instance = module.Instantiate(new Host());
|
||||||
{
|
|
||||||
instance.Externs.Functions[0].Invoke();
|
instance.Externs.Functions[0].Invoke();
|
||||||
}
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ namespace Wasmtime.Bindings
|
|||||||
{
|
{
|
||||||
var parameters = Interop.ToValueTypeVec(Import.Parameters);
|
var parameters = Interop.ToValueTypeVec(Import.Parameters);
|
||||||
var results = Interop.ToValueTypeVec(Import.Results);
|
var results = Interop.ToValueTypeVec(Import.Results);
|
||||||
using (var funcType = Interop.wasm_functype_new(ref parameters, ref results))
|
using var funcType = Interop.wasm_functype_new(ref parameters, ref results);
|
||||||
{
|
|
||||||
var callback = CreateCallback(store, host);
|
var callback = CreateCallback(store, host);
|
||||||
var func = Interop.wasm_func_new(store.Handle, funcType, callback);
|
var func = Interop.wasm_func_new(store.Handle, funcType, callback);
|
||||||
// Store the callback with the safe handle to keep the delegate GC reachable
|
// Store the callback with the safe handle to keep the delegate GC reachable
|
||||||
@@ -61,7 +60,6 @@ namespace Wasmtime.Bindings
|
|||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void Validate()
|
private void Validate()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,16 +59,16 @@ namespace Wasmtime.Bindings
|
|||||||
var valueTypeHandle = valueType.DangerousGetHandle();
|
var valueTypeHandle = valueType.DangerousGetHandle();
|
||||||
valueType.SetHandleAsInvalid();
|
valueType.SetHandleAsInvalid();
|
||||||
|
|
||||||
using (var globalType = Interop.wasm_globaltype_new(
|
using var globalType = Interop.wasm_globaltype_new(
|
||||||
valueTypeHandle,
|
valueTypeHandle,
|
||||||
Import.IsMutable ? Interop.wasm_mutability_t.WASM_VAR : Interop.wasm_mutability_t.WASM_CONST))
|
Import.IsMutable ? Interop.wasm_mutability_t.WASM_VAR : Interop.wasm_mutability_t.WASM_CONST
|
||||||
{
|
);
|
||||||
|
|
||||||
var handle = Interop.wasm_global_new(store.Handle, globalType, &v);
|
var handle = Interop.wasm_global_new(store.Handle, globalType, &v);
|
||||||
global.Handle = handle;
|
global.Handle = handle;
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void Validate()
|
private void Validate()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,14 +68,13 @@ namespace Wasmtime.Bindings
|
|||||||
Interop.wasm_limits_t limits = new Interop.wasm_limits_t();
|
Interop.wasm_limits_t limits = new Interop.wasm_limits_t();
|
||||||
limits.min = min;
|
limits.min = min;
|
||||||
limits.max = max;
|
limits.max = max;
|
||||||
using (var memoryType = Interop.wasm_memorytype_new(&limits))
|
|
||||||
{
|
using var memoryType = Interop.wasm_memorytype_new(&limits);
|
||||||
var handle = Interop.wasm_memory_new(store.Handle, memoryType);
|
var handle = Interop.wasm_memory_new(store.Handle, memoryType);
|
||||||
memory.Handle = handle;
|
memory.Handle = handle;
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void Validate()
|
private void Validate()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ namespace Wasmtime.Tests
|
|||||||
public void ItBindsImportMethodsAndCallsThemCorrectly()
|
public void ItBindsImportMethodsAndCallsThemCorrectly()
|
||||||
{
|
{
|
||||||
var host = new MyHost();
|
var host = new MyHost();
|
||||||
using (var instance = Fixture.Module.Instantiate(host))
|
using var instance = Fixture.Module.Instantiate(host);
|
||||||
{
|
|
||||||
var add_func = instance.Externs.Functions.Where(f => f.Name == "add_wrapper").Single();
|
var add_func = instance.Externs.Functions.Where(f => f.Name == "add_wrapper").Single();
|
||||||
int invoke_add(int x, int y) => (int)add_func.Invoke(new object[] { x, y });
|
int invoke_add(int x, int y) => (int)add_func.Invoke(new object[] { x, y });
|
||||||
|
|
||||||
@@ -50,14 +50,13 @@ namespace Wasmtime.Tests
|
|||||||
|
|
||||||
invoke_add(1970, 50).Should().Be(2020);
|
invoke_add(1970, 50).Should().Be(2020);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItPropagatesExceptionsToCallersViaTraps()
|
public void ItPropagatesExceptionsToCallersViaTraps()
|
||||||
{
|
{
|
||||||
var host = new MyHost();
|
var host = new MyHost();
|
||||||
using (var instance = Fixture.Module.Instantiate(host))
|
using var instance = Fixture.Module.Instantiate(host);
|
||||||
{
|
|
||||||
var throw_func = instance.Externs.Functions.Where(f => f.Name == "do_throw_wrapper").Single();
|
var throw_func = instance.Externs.Functions.Where(f => f.Name == "do_throw_wrapper").Single();
|
||||||
Action action = () => throw_func.Invoke();
|
Action action = () => throw_func.Invoke();
|
||||||
|
|
||||||
@@ -68,4 +67,3 @@ namespace Wasmtime.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItCreatesExternsForTheGlobals()
|
public void ItCreatesExternsForTheGlobals()
|
||||||
{
|
{
|
||||||
using (var instance = Fixture.Module.Instantiate(new Host()))
|
using var instance = Fixture.Module.Instantiate(new Host());
|
||||||
{
|
|
||||||
dynamic dyn = instance;
|
dynamic dyn = instance;
|
||||||
var globals = instance.Externs.Globals;
|
var globals = instance.Externs.Globals;
|
||||||
globals.Count.Should().Be(8);
|
globals.Count.Should().Be(8);
|
||||||
@@ -164,7 +164,6 @@ namespace Wasmtime.Tests
|
|||||||
.Throw<InvalidOperationException>()
|
.Throw<InvalidOperationException>()
|
||||||
.WithMessage("The value of global 'global_f64' cannot be modified.");
|
.WithMessage("The value of global 'global_f64' cannot be modified.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<object[]> GetGlobalExports()
|
public static IEnumerable<object[]> GetGlobalExports()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithMissingImport()
|
public void ItFailsToInstantiateWithMissingImport()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NoImportsHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new NoImportsHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -129,7 +129,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithStaticField()
|
public void ItFailsToInstantiateWithStaticField()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new GlobalIsStaticHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new GlobalIsStaticHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -140,7 +140,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithNonReadOnlyField()
|
public void ItFailsToInstantiateWithNonReadOnlyField()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new GlobalIsNotReadOnlyHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new GlobalIsNotReadOnlyHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -151,7 +151,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithInvalidType()
|
public void ItFailsToInstantiateWithInvalidType()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotAGlobalHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotAGlobalHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -162,7 +162,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithInvalidGlobalType()
|
public void ItFailsToInstantiateWithInvalidGlobalType()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotAValidGlobalTypeHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotAValidGlobalTypeHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -173,7 +173,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithGlobalTypeMismatch()
|
public void ItFailsToInstantiateWithGlobalTypeMismatch()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new TypeMismatchHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new TypeMismatchHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -184,7 +184,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWhenGlobalIsNotMut()
|
public void ItFailsToInstantiateWhenGlobalIsNotMut()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotMutHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotMutHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -195,7 +195,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWhenGlobalIsMut()
|
public void ItFailsToInstantiateWhenGlobalIsMut()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MutHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new MutHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -207,8 +207,8 @@ namespace Wasmtime.Tests
|
|||||||
public void ItBindsTheGlobalsCorrectly()
|
public void ItBindsTheGlobalsCorrectly()
|
||||||
{
|
{
|
||||||
var host = new ValidHost();
|
var host = new ValidHost();
|
||||||
using (dynamic instance = Fixture.Module.Instantiate(host))
|
using dynamic instance = Fixture.Module.Instantiate(host);
|
||||||
{
|
|
||||||
host.Int32Mut.Value.Should().Be(0);
|
host.Int32Mut.Value.Should().Be(0);
|
||||||
((int)instance.get_global_i32_mut()).Should().Be(0);
|
((int)instance.get_global_i32_mut()).Should().Be(0);
|
||||||
host.Int32.Value.Should().Be(1);
|
host.Int32.Value.Should().Be(1);
|
||||||
@@ -256,4 +256,3 @@ namespace Wasmtime.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ namespace Wasmtime.Tests
|
|||||||
public void ItCreatesExternsForTheMemories()
|
public void ItCreatesExternsForTheMemories()
|
||||||
{
|
{
|
||||||
var host = new Host();
|
var host = new Host();
|
||||||
using (var instance = Fixture.Module.Instantiate(host))
|
using var instance = Fixture.Module.Instantiate(host);
|
||||||
{
|
|
||||||
instance.Externs.Memories.Count.Should().Be(1);
|
instance.Externs.Memories.Count.Should().Be(1);
|
||||||
|
|
||||||
var memory = instance.Externs.Memories[0];
|
var memory = instance.Externs.Memories[0];
|
||||||
@@ -82,7 +82,6 @@ namespace Wasmtime.Tests
|
|||||||
memory.WriteIntPtr(48, (IntPtr)17);
|
memory.WriteIntPtr(48, (IntPtr)17);
|
||||||
memory.ReadIntPtr(48).Should().Be((IntPtr)17);
|
memory.ReadIntPtr(48).Should().Be((IntPtr)17);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<object[]> GetMemoryExports()
|
public static IEnumerable<object[]> GetMemoryExports()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithMissingImport()
|
public void ItFailsToInstantiateWithMissingImport()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MissingImportsHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new MissingImportsHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -85,7 +85,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithStaticField()
|
public void ItFailsToInstantiateWithStaticField()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MemoryIsStaticHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new MemoryIsStaticHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -96,7 +96,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithNonReadOnlyField()
|
public void ItFailsToInstantiateWithNonReadOnlyField()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MemoryIsNotReadOnlyHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new MemoryIsNotReadOnlyHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -107,7 +107,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWithInvalidType()
|
public void ItFailsToInstantiateWithInvalidType()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotAMemoryHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotAMemoryHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -118,7 +118,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWhenMemoryHasInvalidMinimum()
|
public void ItFailsToInstantiateWhenMemoryHasInvalidMinimum()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new InvalidMinimumHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new InvalidMinimumHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -129,7 +129,7 @@ namespace Wasmtime.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ItFailsToInstantiateWhenMemoryHasInvalidMaximum()
|
public void ItFailsToInstantiateWhenMemoryHasInvalidMaximum()
|
||||||
{
|
{
|
||||||
Action action = () => { using (var instance = Fixture.Module.Instantiate(new InvalidMaximumHost())) { } };
|
Action action = () => { using var instance = Fixture.Module.Instantiate(new InvalidMaximumHost()); };
|
||||||
|
|
||||||
action
|
action
|
||||||
.Should()
|
.Should()
|
||||||
@@ -141,8 +141,8 @@ namespace Wasmtime.Tests
|
|||||||
public void ItBindsTheGlobalsCorrectly()
|
public void ItBindsTheGlobalsCorrectly()
|
||||||
{
|
{
|
||||||
var host = new ValidHost();
|
var host = new ValidHost();
|
||||||
using (dynamic instance = Fixture.Module.Instantiate(host))
|
using dynamic instance = Fixture.Module.Instantiate(host);
|
||||||
{
|
|
||||||
host.Mem.ReadString(0, 11).Should().Be("Hello World");
|
host.Mem.ReadString(0, 11).Should().Be("Hello World");
|
||||||
int written = host.Mem.WriteString(0, "WebAssembly Rocks!");
|
int written = host.Mem.WriteString(0, "WebAssembly Rocks!");
|
||||||
host.Mem.ReadString(0, written).Should().Be("WebAssembly Rocks!");
|
host.Mem.ReadString(0, written).Should().Be("WebAssembly Rocks!");
|
||||||
@@ -184,4 +184,3 @@ namespace Wasmtime.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -145,8 +145,7 @@ namespace Wasmtime.Tests
|
|||||||
{
|
{
|
||||||
const string MESSAGE = "WASM IS VERY COOL";
|
const string MESSAGE = "WASM IS VERY COOL";
|
||||||
|
|
||||||
using (var file = new TempFile())
|
using var file = new TempFile();
|
||||||
{
|
|
||||||
File.WriteAllText(file.Path, MESSAGE);
|
File.WriteAllText(file.Path, MESSAGE);
|
||||||
|
|
||||||
var wasi = new WasiBuilder()
|
var wasi = new WasiBuilder()
|
||||||
@@ -164,7 +163,6 @@ namespace Wasmtime.Tests
|
|||||||
Assert.Equal(MESSAGE.Length, memory.ReadInt32(32));
|
Assert.Equal(MESSAGE.Length, memory.ReadInt32(32));
|
||||||
Assert.Equal(MESSAGE, memory.ReadString(8, MESSAGE.Length));
|
Assert.Equal(MESSAGE, memory.ReadString(8, MESSAGE.Length));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(1)]
|
[InlineData(1)]
|
||||||
@@ -173,8 +171,8 @@ namespace Wasmtime.Tests
|
|||||||
{
|
{
|
||||||
const string MESSAGE = "WASM IS VERY COOL";
|
const string MESSAGE = "WASM IS VERY COOL";
|
||||||
|
|
||||||
using (var file = new TempFile())
|
using var file = new TempFile();
|
||||||
{
|
|
||||||
var builder = new WasiBuilder();
|
var builder = new WasiBuilder();
|
||||||
if (fd == 1)
|
if (fd == 1)
|
||||||
{
|
{
|
||||||
@@ -200,15 +198,14 @@ namespace Wasmtime.Tests
|
|||||||
Assert.Equal(0, inst.call_fd_close(fd));
|
Assert.Equal(0, inst.call_fd_close(fd));
|
||||||
Assert.Equal(MESSAGE, File.ReadAllText(file.Path));
|
Assert.Equal(MESSAGE, File.ReadAllText(file.Path));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItSetsPreopenDirectories()
|
public void ItSetsPreopenDirectories()
|
||||||
{
|
{
|
||||||
const string MESSAGE = "WASM IS VERY COOL";
|
const string MESSAGE = "WASM IS VERY COOL";
|
||||||
|
|
||||||
using (var file = new TempFile())
|
using var file = new TempFile();
|
||||||
{
|
|
||||||
var wasi = new WasiBuilder()
|
var wasi = new WasiBuilder()
|
||||||
.WithPreopenedDirectory(Path.GetDirectoryName(file.Path), "/foo")
|
.WithPreopenedDirectory(Path.GetDirectoryName(file.Path), "/foo")
|
||||||
.Build(Fixture.Module.Store);
|
.Build(Fixture.Module.Store);
|
||||||
@@ -247,4 +244,3 @@ namespace Wasmtime.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user