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

Function drop_host_twice

tests/all/component_model/resources.rs:382–416  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

380
381#[test]
382fn drop_host_twice() -> Result<()> {
383 let engine = super::engine();
384 let c = Component::new(
385 &engine,
386 r#"
387 (component
388 (import "t" (type $t (sub resource)))
389
390 (core func $dtor (canon resource.drop $t))
391 (func (export "dtor") (param "x" (own $t))
392 (canon lift (core func $dtor)))
393 )
394 "#,
395 )?;
396
397 struct MyType;
398
399 let mut store = Store::new(&engine, ());
400 let mut linker = Linker::new(&engine);
401 linker
402 .root()
403 .resource("t", ResourceType::host::<MyType>(), |_, _| Ok(()))?;
404 let i = linker.instantiate(&mut store, &c)?;
405 let dtor = i.get_typed_func::<(&Resource<MyType>,), ()>(&mut store, "dtor")?;
406
407 let t = Resource::new_own(100);
408 dtor.call(&mut store, (&t,))?;
409
410 assert_eq!(
411 dtor.call(&mut store, (&t,)).unwrap_err().to_string(),
412 "host resource already consumed"
413 );
414
415 Ok(())
416}
417
418#[test]
419fn manually_destroy() -> Result<()> {

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
engineFunction · 0.50
newFunction · 0.50
resourceMethod · 0.45
rootMethod · 0.45
instantiateMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected