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

Function private_entity_access

tests/all/debug.rs:389–485  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

387#[test]
388#[cfg_attr(miri, ignore)]
389fn private_entity_access() -> wasmtime::Result<()> {
390 let mut config = Config::default();
391 config.guest_debug(true);
392 config.wasm_gc(true);
393 config.gc_support(true);
394 config.wasm_exceptions(true);
395 let engine = Engine::new(&config)?;
396 let mut store = Store::new(&engine, ());
397 let module = Module::new(
398 &engine,
399 r#"
400 (module
401 (import "" "i" (global (mut i32)))
402 (import "" "f" (func (result i32)))
403 (global $g (mut i32) (i32.const 0))
404 (memory $m 1 1)
405 (table $t 10 10 i31ref)
406 (tag $tag (param f64))
407 (func (export "main")
408 ;; $g := 42
409 i32.const 42
410 global.set $g
411 ;; $m[1024] := 1
412 i32.const 1024
413 i32.const 1
414 i32.store8 $m
415 ;; $t[1] := (ref.i31 (i32.const 100))
416 i32.const 1
417 i32.const 100
418 ref.i31
419 table.set $t)
420
421 (func (param i32)
422 local.get 0
423 global.set $g))
424 "#,
425 )?;
426
427 let host_global = Global::new(
428 &mut store,
429 GlobalType::new(ValType::I32, Mutability::Var),
430 Val::I32(1000),
431 )?;
432 let host_func = Func::wrap(&mut store, |_caller: Caller<'_, ()>| -> i32 { 7 });
433
434 let instance = Instance::new(
435 &mut store,
436 &module,
437 &[Extern::Global(host_global), Extern::Func(host_func)],
438 )?;
439 let func = instance.get_func(&mut store, "main").unwrap();
440 func.call(&mut store, &[], &mut [])?;
441
442 // Nothing is exported except for `main`, yet we can still access
443 // (below).
444 let exports = instance.exports(&mut store).collect::<Vec<_>>();
445 assert_eq!(exports.len(), 1);
446 assert!(exports.into_iter().next().unwrap().into_func().is_some());

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
guest_debugMethod · 0.80
gc_supportMethod · 0.80
debug_functionMethod · 0.80
debug_globalMethod · 0.80
debug_memoryMethod · 0.80
debug_tableMethod · 0.80
debug_tagMethod · 0.80
newFunction · 0.50
GlobalClass · 0.50
FuncEnum · 0.50
wasm_gcMethod · 0.45

Tested by

no test coverage detected