MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / instantiate

Method instantiate

crates/wasmtime/src/runtime/instance.rs:891–914  ·  view source on GitHub ↗

Instantiates this instance, creating a new instance within the provided `store`. This function will run the actual process of instantiation to completion. This will use all of the previously-closed-over items as imports to instantiate the module that this was originally created with. For more information about instantiation see [`Instance::new`]. # Panics Panics if any import closed over by th

(&self, mut store: impl AsContextMut<Data = T>)

Source from the content-addressed store, hash-verified

889 /// memory allocation fails. See the `OutOfMemory` type's documentation for
890 /// details on Wasmtime's out-of-memory handling.
891 pub fn instantiate(&self, mut store: impl AsContextMut<Data = T>) -> Result<Instance> {
892 let mut store = store.as_context_mut();
893 let imports = pre_instantiate_raw(
894 &mut store.0,
895 &self.module,
896 &self.items,
897 self.host_funcs,
898 &self.func_refs,
899 self.asyncness,
900 )?;
901
902 // Note that this is specifically done after `pre_instantiate_raw` to
903 // handle the case that if any imports in this `InstancePre` require
904 // async that it's flagged in the store by that point which will reject
905 // this instantiation to say "use `instantiate_async` instead".
906 store.0.validate_sync_call()?;
907
908 // This unsafety should be handled by the type-checking performed by the
909 // constructor of `InstancePre` to assert that all the imports we're passing
910 // in match the module we're instantiating.
911 vm::assert_ready(unsafe {
912 Instance::new_started(&mut store, &self.module, imports.as_ref(), Asyncness::No)
913 })
914 }
915
916 /// Creates a new instance, running the start function asynchronously
917 /// instead of inline.

Callers

nothing calls this directly

Calls 5

pre_instantiate_rawFunction · 0.85
validate_sync_callMethod · 0.80
assert_readyFunction · 0.70
as_context_mutMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected