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

Function exception_across_no_wasm

tests/all/exceptions.rs:187–216  ·  view source on GitHub ↗
(config: &mut Config)

Source from the content-addressed store, hash-verified

185
186#[wasmtime_test(wasm_features(exceptions))]
187fn exception_across_no_wasm(config: &mut Config) -> Result<()> {
188 let engine = Engine::new(config)?;
189 let mut store = Store::new(&engine, ());
190
191 let functy = FuncType::new(&engine, [ValType::I32], []);
192 let tagty = TagType::new(functy.clone());
193 let exnty = ExnType::from_tag_type(&tagty).unwrap();
194 let exnpre = ExnRefPre::new(&mut store, exnty);
195 let tag = Tag::new(&mut store, &tagty)?;
196 let extfunc = Func::new(&mut store, functy, move |mut caller, args, _rets| {
197 let exn = ExnRef::new(
198 &mut caller,
199 &exnpre,
200 &tag,
201 &[Val::I32(args[0].unwrap_i32())],
202 )
203 .unwrap();
204 caller.as_context_mut().throw(exn)?;
205 Ok(())
206 });
207 let mut results = [];
208 let result = extfunc.call(&mut store, &[Val::I32(42)], &mut results[..]);
209 assert!(result.is_err() && result.unwrap_err().downcast::<ThrownException>().is_ok());
210 let exn = store.take_pending_exception().unwrap();
211 let exntag = exn.tag(&mut store)?;
212 assert!(Tag::eq(&exntag, &tag, &store));
213 assert_eq!(exn.field(&mut store, 0)?.unwrap_i32(), 42);
214
215 Ok(())
216}
217
218#[wasmtime_test(wasm_features(gc, exceptions))]
219#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 10

OkFunction · 0.85
throwMethod · 0.80
newFunction · 0.50
cloneMethod · 0.45
unwrapMethod · 0.45
unwrap_i32Method · 0.45
as_context_mutMethod · 0.45
callMethod · 0.45
tagMethod · 0.45

Tested by

no test coverage detected