File tree Expand file tree Collapse file tree
wasmtime/src/runtime/component Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #![ cfg( arc_try_new) ]
2+
3+ use wasmtime:: component:: { Component , Linker } ;
4+ use wasmtime:: { Config , Engine , Result , Store } ;
5+ use wasmtime_fuzzing:: oom:: OomTest ;
6+
7+ #[ tokio:: test]
8+ async fn component_linker_instantiate_async ( ) -> Result < ( ) > {
9+ let component_bytes = {
10+ let mut config = Config :: new ( ) ;
11+ config. concurrency_support ( false ) ;
12+ let engine = Engine :: new ( & config) ?;
13+ Component :: new (
14+ & engine,
15+ r#"
16+ (component
17+ (core module $m
18+ (func (export "id") (param i32) (result i32) (local.get 0))
19+ )
20+ (core instance $i (instantiate $m))
21+ (func (export "id") (param "x" s32) (result s32)
22+ (canon lift (core func $i "id"))
23+ )
24+ )
25+ "# ,
26+ ) ?
27+ . serialize ( ) ?
28+ } ;
29+ let mut config = Config :: new ( ) ;
30+ config. enable_compiler ( false ) ;
31+ config. concurrency_support ( false ) ;
32+ let engine = Engine :: new ( & config) ?;
33+ let component = unsafe { Component :: deserialize ( & engine, & component_bytes) ? } ;
34+ let linker = Linker :: < ( ) > :: new ( & engine) ;
35+
36+ OomTest :: new ( )
37+ . test_async ( || async {
38+ let mut store = Store :: try_new ( & engine, ( ) ) ?;
39+ let _instance = linker. instantiate_async ( & mut store, & component) . await ?;
40+ Ok ( ( ) )
41+ } )
42+ . await
43+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ mod boxed;
66mod btree_map;
77mod caller;
88mod component_func;
9+ mod component_linker;
910mod config;
1011mod engine;
1112mod entity_set;
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ impl<T: 'static> Linker<T> {
177177 engine : & self . engine ,
178178 types : component. types ( ) ,
179179 strings : & self . strings ,
180- imported_resources : Default :: default ( ) ,
180+ imported_resources : try_new :: < Arc < _ > > ( Default :: default ( ) ) ? ,
181181 } ;
182182
183183 // Walk over the component's list of import names and use that to lookup
@@ -267,7 +267,11 @@ impl<T: 'static> Linker<T> {
267267 assert_eq ! ( i, idx) ;
268268 }
269269 Ok ( unsafe {
270- InstancePre :: new_unchecked ( component. clone ( ) , Arc :: new ( imports) , imported_resources)
270+ InstancePre :: new_unchecked (
271+ component. clone ( ) ,
272+ try_new :: < Arc < _ > > ( imports) ?,
273+ imported_resources,
274+ )
271275 } )
272276 }
273277
You can’t perform that action at this time.
0 commit comments