Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Document some more aborts/panics in the API (#15096)

Alex Crichtonb0821bb26e2f
diff --git a/crates/c-api/include/doc-wasm.h b/crates/c-api/include/doc-wasm.h
index 787f6ea574..a364d6d51d 100644
--- a/crates/c-api/include/doc-wasm.h
+++ b/crates/c-api/include/doc-wasm.h
@@ -369,6 +369,10 @@
*
* The caller is responsible for deleting the returned value.
*
+ * The returned function type is associated with an engine the first time it's
+ * used with one, for example by #wasmtime_func_new. At that point the process
+ * aborts if any parameter or result type comes from a different engine.
+ *
* \fn const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t *);
* \brief Returns the list of parameters of this function type.
*
diff --git a/crates/c-api/include/wasmtime/types/arrayref.h b/crates/c-api/include/wasmtime/types/arrayref.h
index 20b5be0089..3f3d73fe2a 100644
--- a/crates/c-api/include/wasmtime/types/arrayref.h
+++ b/crates/c-api/include/wasmtime/types/arrayref.h
@@ -31,6 +31,9 @@ typedef struct wasmtime_array_type wasmtime_array_type_t;
* \param field The element type descriptor.
*
* \return Returns a new array type.
+ *
+ * This function aborts the process if the field's type comes from an engine
+ * other than `engine`.
*/
WASM_API_EXTERN wasmtime_array_type_t *
wasmtime_array_type_new(const wasm_engine_t *engine,
diff --git a/crates/c-api/include/wasmtime/types/exnref.h b/crates/c-api/include/wasmtime/types/exnref.h
index cb5ab48324..2d473c7fb3 100644
--- a/crates/c-api/include/wasmtime/types/exnref.h
+++ b/crates/c-api/include/wasmtime/types/exnref.h
@@ -19,6 +19,9 @@ typedef struct wasmtime_exn_type wasmtime_exn_type_t;
///
/// Fills in `out` on success and returns `NULL`. Otherwise returns an
/// error and does not modify `out`.
+///
+/// This function aborts the process if any parameter's type comes from an
+/// engine other than `engine`.
WASM_API_EXTERN wasmtime_error_t *
wasmtime_exn_type_new(const wasm_engine_t *engine,
const wasm_valtype_vec_t *params,
diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rs
index 8c3472024a..b33dabd0e2 100644
--- a/crates/wasmtime/src/runtime/types.rs
+++ b/crates/wasmtime/src/runtime/types.rs
@@ -2850,6 +2850,10 @@ impl ExnType {
/// given signature, i.e., list of payload value types. This
/// signature implies a tag type, and when instantiated at
/// runtime, it must be associated with a tag of that type.
+ ///
+ /// # Panics
+ ///
+ /// Panics if any field type is not associated with the given engine.
pub fn new(engine: &Engine, fields: impl IntoIterator<Item = ValType>) -> Result<ExnType> {
let fields: TryVec<_> = fields.into_iter().try_collect()?;