wasmtime: Option to return default values for unknown imports (#6010)
Similar to the `--trap-unknown-imports` option, which defines unknown function imports with functions that trap when called, this new `--default-values-unknown-imports` option defines unknown function imports with a function that returns the default values for the result types (either zero or null depending on the value type).
This commit is contained in:
@@ -90,6 +90,11 @@ pub struct RunCommand {
|
||||
#[clap(long = "trap-unknown-imports")]
|
||||
trap_unknown_imports: bool,
|
||||
|
||||
/// Allow the main module to import unknown functions, using an
|
||||
/// implementation that returns default values, when running commands.
|
||||
#[clap(long = "default-values-unknown-imports")]
|
||||
default_values_unknown_imports: bool,
|
||||
|
||||
/// Allow executing precompiled WebAssembly modules as `*.cwasm` files.
|
||||
///
|
||||
/// Note that this option is not safe to pass if the module being passed in
|
||||
@@ -322,6 +327,12 @@ impl RunCommand {
|
||||
if self.trap_unknown_imports {
|
||||
linker.define_unknown_imports_as_traps(&module)?;
|
||||
}
|
||||
|
||||
// ...or as default values.
|
||||
if self.default_values_unknown_imports {
|
||||
linker.define_unknown_imports_as_default_values(&module)?;
|
||||
}
|
||||
|
||||
// Use "" as a default module name.
|
||||
linker
|
||||
.module(&mut *store, "", &module)
|
||||
|
||||
Reference in New Issue
Block a user