(&self, wasm: &[u8], context: &str)
| 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"); |
no test coverage detected