test4.wast 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (module
  2. (type $ft (func))
  3. (type $st (struct))
  4. (type $at (array i8))
  5. (table 10 anyref)
  6. (elem declare func $f)
  7. (func $f)
  8. (func (export "init") (param $x externref)
  9. (table.set (i32.const 0) (ref.null any))
  10. (table.set (i32.const 1) (ref.i31 (i32.const 7)))
  11. (table.set (i32.const 2) (struct.new_default $st))
  12. (table.set (i32.const 3) (array.new_default $at (i32.const 0)))
  13. (table.set (i32.const 4) (any.convert_extern (local.get $x)))
  14. (table.set (i32.const 5) (ref.null i31))
  15. (table.set (i32.const 6) (ref.null struct))
  16. (table.set (i32.const 7) (ref.null none))
  17. )
  18. (func (export "ref_cast_non_null") (param $i i32)
  19. (drop (ref.as_non_null (table.get (local.get $i))))
  20. (drop (ref.cast (ref null any) (table.get (local.get $i))))
  21. )
  22. (func (export "ref_cast_null") (param $i i32)
  23. (drop (ref.cast anyref (table.get (local.get $i))))
  24. (drop (ref.cast structref (table.get (local.get $i))))
  25. (drop (ref.cast arrayref (table.get (local.get $i))))
  26. (drop (ref.cast i31ref (table.get (local.get $i))))
  27. (drop (ref.cast nullref (table.get (local.get $i))))
  28. )
  29. (func (export "ref_cast_i31") (param $i i32)
  30. (drop (ref.cast (ref i31) (table.get (local.get $i))))
  31. (drop (ref.cast i31ref (table.get (local.get $i))))
  32. )
  33. (func (export "ref_cast_struct") (param $i i32)
  34. (drop (ref.cast (ref struct) (table.get (local.get $i))))
  35. (drop (ref.cast structref (table.get (local.get $i))))
  36. )
  37. (func (export "ref_cast_array") (param $i i32)
  38. (drop (ref.cast (ref array) (table.get (local.get $i))))
  39. (drop (ref.cast arrayref (table.get (local.get $i))))
  40. )
  41. )