Internal function to create an instance and run the start function. This function's unsafety is the same as `Instance::new_raw`.
(
store: &mut StoreContextMut<'_, T>,
module: &Module,
imports: Imports<'_>,
asyncness: Asyncness,
)
| 249 | /// |
| 250 | /// This function's unsafety is the same as `Instance::new_raw`. |
| 251 | pub(crate) async unsafe fn new_started<T>( |
| 252 | store: &mut StoreContextMut<'_, T>, |
| 253 | module: &Module, |
| 254 | imports: Imports<'_>, |
| 255 | asyncness: Asyncness, |
| 256 | ) -> Result<Instance> { |
| 257 | let instance = { |
| 258 | let (mut limiter, store) = store.0.resource_limiter_and_store_opaque(); |
| 259 | // SAFETY: the safety contract of `new_raw` is the same as this |
| 260 | // function. |
| 261 | unsafe { Instance::new_raw(store, limiter.as_mut(), module, imports).await? } |
| 262 | }; |
| 263 | |
| 264 | // If this instance requires startup, which is a dynamic decision made |
| 265 | // at this point in conjunction with analysis at compile time, the |
| 266 | // instance gets started. Note that this isn't just the wasm start |
| 267 | // function itself, but it's finalization of initialization of this |
| 268 | // instance, for example for complicated global initialization |
| 269 | // expressions. |
| 270 | if instance.id.get_mut(store.0).needs_startup() { |
| 271 | if asyncness == Asyncness::No { |
| 272 | instance.start_raw(store)?; |
| 273 | } else { |
| 274 | #[cfg(feature = "async")] |
| 275 | { |
| 276 | store.on_fiber(|store| instance.start_raw(store)).await??; |
| 277 | } |
| 278 | #[cfg(not(feature = "async"))] |
| 279 | unreachable!(); |
| 280 | } |
| 281 | } |
| 282 | Ok(instance) |
| 283 | } |
| 284 | |
| 285 | /// Internal function to create an instance which doesn't have its `start` |
| 286 | /// function run yet. |
nothing calls this directly
no test coverage detected