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

Method debug_assert_valid_wasm

crates/wizer/src/lib.rs:245–264  ·  view source on GitHub ↗
(&self, wasm: &[u8], context: &str)

Source from the content-addressed store, hash-verified

243 }
244
245 fn debug_assert_valid_wasm(&self, wasm: &[u8], context: &str) {
246 if !cfg!(debug_assertions) {
247 return;
248 }
249 if let Err(error) = self.wasm_validate(&wasm) {
250 #[cfg(feature = "wasmprinter")]
251 let wat = wasmprinter::print_bytes(&wasm)
252 .unwrap_or_else(|e| format!("Disassembling to WAT failed: {e}"));
253 #[cfg(not(feature = "wasmprinter"))]
254 let wat = "`wasmprinter` cargo feature is not enabled".to_string();
255
256 let wat = if wat.len() > 16 * 1024 {
257 std::fs::write("invalid.wat", wat).expect("writing to invalid.wat");
258 "written to invalid.wat"
259 } else {
260 &wat
261 };
262 panic!("{context} is not valid wasm: {error:?}\n\nWAT:\n{wat}");
263 }
264 }
265
266 fn wasm_validate(&self, wasm: &[u8]) -> Result<()> {
267 log::debug!("Validating input Wasm");

Callers 4

instrumentMethod · 0.80
snapshotMethod · 0.80
instrument_componentMethod · 0.80
snapshot_componentMethod · 0.80

Calls 6

print_bytesFunction · 0.85
wasm_validateMethod · 0.80
writeFunction · 0.50
to_stringMethod · 0.45
lenMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected