()
| 1353 | |
| 1354 | #[tokio::test] |
| 1355 | async fn drop_on_owned_resource() -> Result<()> { |
| 1356 | let mut config = wasmtime::Config::new(); |
| 1357 | config.wasm_component_model_async(true); |
| 1358 | let engine = &wasmtime::Engine::new(&config)?; |
| 1359 | let c = Component::new( |
| 1360 | &engine, |
| 1361 | r#" |
| 1362 | (component |
| 1363 | (import "t" (type $t (sub resource))) |
| 1364 | (import "[constructor]t" (func $ctor (result (own $t)))) |
| 1365 | (import "[method]t.foo" (func $foo async (param "self" (borrow $t)))) |
| 1366 | |
| 1367 | (core func $ctor (canon lower (func $ctor))) |
| 1368 | (core func $drop (canon resource.drop $t)) |
| 1369 | (core func $foo (canon lower (func $foo) async)) |
| 1370 | |
| 1371 | (core module $m |
| 1372 | (import "" "ctor" (func $ctor (result i32))) |
| 1373 | (import "" "foo" (func $foo (param i32) (result i32))) |
| 1374 | (import "" "drop" (func $drop (param i32))) |
| 1375 | |
| 1376 | (func (export "f") |
| 1377 | (local $r i32) |
| 1378 | (local $status i32) |
| 1379 | (local.set $r (call $ctor)) |
| 1380 | (local.set $status (call $foo (local.get $r))) |
| 1381 | (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $status) (i32.const 0xf))) |
| 1382 | (then unreachable)) |
| 1383 | (call $drop (local.get $r)) |
| 1384 | (unreachable) |
| 1385 | ) |
| 1386 | ) |
| 1387 | (core instance $i (instantiate $m |
| 1388 | (with "" (instance |
| 1389 | (export "ctor" (func $ctor)) |
| 1390 | (export "foo" (func $foo)) |
| 1391 | (export "drop" (func $drop)) |
| 1392 | )) |
| 1393 | )) |
| 1394 | (func (export "f") async (canon lift (core func $i "f"))) |
| 1395 | ) |
| 1396 | "#, |
| 1397 | )?; |
| 1398 | |
| 1399 | struct MyType; |
| 1400 | |
| 1401 | let mut store = Store::new(&engine, ()); |
| 1402 | let mut linker = Linker::new(&engine); |
| 1403 | linker |
| 1404 | .root() |
| 1405 | .resource("t", ResourceType::host::<MyType>(), |_, _| Ok(()))?; |
| 1406 | linker.root().func_wrap("[constructor]t", |_, ()| { |
| 1407 | Ok((Resource::<MyType>::new_own(300),)) |
| 1408 | })?; |
| 1409 | linker |
| 1410 | .root() |
| 1411 | .func_wrap_concurrent("[method]t.foo", |_cx, (r,): (Resource<MyType>,)| { |
| 1412 | assert!(!r.owned()); |
nothing calls this directly
no test coverage detected