collapse some common code
This commit is contained in:
@@ -126,6 +126,11 @@ impl Instance {
|
||||
typecheck_externs(store.0, module, imports)?;
|
||||
Instantiator::new(store.0, module, ImportSource::Externs(imports))?
|
||||
};
|
||||
assert!(
|
||||
!store.0.async_support(),
|
||||
"cannot use `new` when async support is enabled on the config"
|
||||
);
|
||||
|
||||
i.run(&mut store)
|
||||
}
|
||||
|
||||
@@ -162,7 +167,14 @@ impl Instance {
|
||||
typecheck_externs(store.0, module, imports)?;
|
||||
Instantiator::new(store.0, module, ImportSource::Externs(imports))?
|
||||
};
|
||||
i.run_async(&mut store).await
|
||||
let mut store = store.as_context_mut();
|
||||
assert!(
|
||||
store.0.async_support(),
|
||||
"cannot use `new_async` without enabling async support on the config"
|
||||
);
|
||||
store
|
||||
.on_fiber(|store| i.run(&mut store.as_context_mut()))
|
||||
.await?
|
||||
}
|
||||
|
||||
pub(crate) fn from_wasmtime(handle: InstanceData, store: &mut StoreOpaque) -> Instance {
|
||||
@@ -472,13 +484,6 @@ impl<'a> Instantiator<'a> {
|
||||
}
|
||||
|
||||
fn run<T>(&mut self, store: &mut StoreContextMut<'_, T>) -> Result<Instance, Error> {
|
||||
assert!(
|
||||
!store.0.async_support(),
|
||||
"cannot use `new` when async support is enabled on the config"
|
||||
);
|
||||
|
||||
// NB: this is the same code as `run_async`. It's intentionally
|
||||
// small but should be kept in sync (modulo the async bits).
|
||||
loop {
|
||||
if let Some((instance, start, toplevel)) = self.step(store.0)? {
|
||||
if let Some(start) = start {
|
||||
@@ -491,33 +496,6 @@ impl<'a> Instantiator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
async fn run_async<T>(&mut self, store: &mut StoreContextMut<'_, T>) -> Result<Instance, Error>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
assert!(
|
||||
store.0.async_support(),
|
||||
"cannot use `new_async` without enabling async support on the config"
|
||||
);
|
||||
|
||||
// NB: this is the same code as `run`. It's intentionally
|
||||
// small but should be kept in sync (modulo the async bits).
|
||||
store
|
||||
.on_fiber(|store| loop {
|
||||
let step = self.step(store.0)?;
|
||||
if let Some((instance, start, toplevel)) = step {
|
||||
if let Some(start) = start {
|
||||
Instantiator::start_raw(store, instance, start)?
|
||||
}
|
||||
if toplevel {
|
||||
break Ok(instance);
|
||||
}
|
||||
}
|
||||
})
|
||||
.await?
|
||||
}
|
||||
|
||||
/// Processes the next initializer for the next instance being created
|
||||
/// without running any wasm code.
|
||||
///
|
||||
@@ -1002,7 +980,15 @@ impl<T> InstancePre<T> {
|
||||
ImportSource::Definitions(&self.items),
|
||||
)?
|
||||
};
|
||||
i.run_async(&mut store.as_context_mut()).await
|
||||
|
||||
let mut store = store.as_context_mut();
|
||||
assert!(
|
||||
store.0.async_support(),
|
||||
"cannot use `new_async` without enabling async support on the config"
|
||||
);
|
||||
store
|
||||
.on_fiber(|store| i.run(&mut store.as_context_mut()))
|
||||
.await?
|
||||
}
|
||||
|
||||
fn ensure_comes_from_same_store(&self, store: &StoreOpaque) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user