File tree Expand file tree Collapse file tree 8 files changed +65
-5
lines changed Expand file tree Collapse file tree 8 files changed +65
-5
lines changed Original file line number Diff line number Diff line change @@ -353,7 +353,7 @@ internal Handle NativeHandle
353
353
{
354
354
get
355
355
{
356
- if ( handle . IsInvalid )
356
+ if ( handle . IsInvalid || handle . IsClosed )
357
357
{
358
358
throw new ObjectDisposedException ( typeof ( Config ) . FullName ) ;
359
359
}
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ internal Handle NativeHandle
48
48
{
49
49
get
50
50
{
51
- if ( handle . IsInvalid )
51
+ if ( handle . IsInvalid || handle . IsClosed )
52
52
{
53
53
throw new ObjectDisposedException ( typeof ( Engine ) . FullName ) ;
54
54
}
Original file line number Diff line number Diff line change @@ -387,7 +387,7 @@ internal Handle NativeHandle
387
387
{
388
388
get
389
389
{
390
- if ( handle . IsInvalid )
390
+ if ( handle . IsInvalid || handle . IsClosed )
391
391
{
392
392
throw new ObjectDisposedException ( typeof ( Module ) . FullName ) ;
393
393
}
Original file line number Diff line number Diff line change @@ -279,7 +279,7 @@ internal Handle NativeHandle
279
279
{
280
280
get
281
281
{
282
- if ( handle . IsInvalid )
282
+ if ( handle . IsInvalid || handle . IsClosed )
283
283
{
284
284
throw new ObjectDisposedException ( typeof ( Store ) . FullName ) ;
285
285
}
Original file line number Diff line number Diff line change @@ -166,5 +166,17 @@ public void ItSetsMultiValue()
166
166
167
167
act . Should ( ) . Throw < WasmtimeException > ( ) ;
168
168
}
169
+
170
+ [ Fact ]
171
+ public void ItCannotBeAccessedOnceDisposed ( )
172
+ {
173
+ var config = new Config ( ) ;
174
+ config . Dispose ( ) ;
175
+
176
+ Assert . Throws < ObjectDisposedException > ( ( ) => config . NativeHandle ) ;
177
+ Assert . Throws < ObjectDisposedException > ( ( ) => config . WithBulkMemory ( true ) ) ;
178
+ Assert . Throws < ObjectDisposedException > ( ( ) => config . WithCacheConfig ( null ) ) ;
179
+ Assert . Throws < ObjectDisposedException > ( ( ) => config . WithEpochInterruption ( true ) ) ;
180
+ }
169
181
}
170
182
}
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using Xunit ;
3
+
4
+ namespace Wasmtime . Tests ;
5
+
6
+ public class EngineTests
7
+ {
8
+ [ Fact ]
9
+ public void ItCannotBeAccessedOnceDisposed ( )
10
+ {
11
+ var engine = new Engine ( ) ;
12
+
13
+ engine . Dispose ( ) ;
14
+
15
+ Assert . Throws < ObjectDisposedException > ( ( ) => engine . NativeHandle ) ;
16
+ Assert . Throws < ObjectDisposedException > ( ( ) => engine . IncrementEpoch ( ) ) ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change @@ -51,5 +51,20 @@ public void ItLoadsModuleTextFromEmbeddedResource()
51
51
// `ObjectDisposedException`
52
52
stream . Read ( new byte [ 0 ] , 0 , 0 ) ;
53
53
}
54
+
55
+ [ Fact ]
56
+ public void ItCannotBeAccessedOnceDisposed ( )
57
+ {
58
+ using var stream = Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( "hello.wasm" ) ;
59
+ stream . Should ( ) . NotBeNull ( ) ;
60
+
61
+ using var engine = new Engine ( ) ;
62
+ var module = Module . FromStream ( engine , "hello.wasm" , stream ) ;
63
+
64
+ module . Dispose ( ) ;
65
+
66
+ Assert . Throws < ObjectDisposedException > ( ( ) => module . NativeHandle ) ;
67
+ Assert . Throws < ObjectDisposedException > ( ( ) => module . Serialize ( ) ) ;
68
+ }
54
69
}
55
70
}
Original file line number Diff line number Diff line change 1
- using FluentAssertions ;
1
+ using System ;
2
+ using FluentAssertions ;
2
3
using System . IO ;
3
4
using Xunit ;
4
5
@@ -91,5 +92,19 @@ public void ItLimitsMemories()
91
92
var act = ( ) => { new Instance ( Store , module ) ; } ;
92
93
act . Should ( ) . Throw < WasmtimeException > ( ) ;
93
94
}
95
+
96
+ [ Fact ]
97
+ public void ItCannotBeAccessedOnceDisposed ( )
98
+ {
99
+ var ctx = Store . Context ;
100
+ Assert . Equal ( Store , ctx . Store ) ;
101
+
102
+ Store . Dispose ( ) ;
103
+
104
+ Assert . Throws < ObjectDisposedException > ( ( ) => { var x = Store . Context ; } ) ;
105
+ Assert . Throws < ObjectDisposedException > ( ( ) => Store . NativeHandle ) ;
106
+ Assert . Throws < ObjectDisposedException > ( ( ) => Store . Fuel ) ;
107
+ Assert . Throws < ObjectDisposedException > ( ( ) => Store . GC ( ) ) ;
108
+ }
94
109
}
95
110
}
You can’t perform that action at this time.
0 commit comments