File Coverage

blib/lib/Wasm/Wasmtime/WasiInstance.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::WasiInstance;
2              
3 10     10   513 use strict;
  10         21  
  10         309  
4 10     10   62 use warnings;
  10         22  
  10         234  
5 10     10   158 use 5.008004;
  10         38  
6 10     10   59 use Wasm::Wasmtime::FFI;
  10         37  
  10         994  
7 10     10   168 use Wasm::Wasmtime::Store;
  10         23  
  10         280  
8 10     10   452 use Wasm::Wasmtime::Trap;
  10         19  
  10         245  
9 10     10   4031 use Wasm::Wasmtime::WasiConfig;
  10         30  
  10         2415  
10              
11             # ABSTRACT: WASI instance class
12             our $VERSION = '0.23'; # VERSION
13              
14              
15             $ffi_prefix = 'wasi_instance_';
16             $ffi->load_custom_type('::PtrObject' => 'wasi_instance_t' => __PACKAGE__);
17              
18              
19             $ffi->attach( new => ['wasm_store_t', 'string', 'wasi_config_t', 'opaque*'] => 'wasi_instance_t' => sub {
20             my $xsub = shift;
21             my $class = shift;
22             my $store = shift;
23             my $name = shift;
24             my $config = defined $_[0] && ref($_[0]) eq 'Wasm::Wasmtime::WasiConfig' ? shift : Wasm::Wasmtime::WasiConfig->new;
25             my $trap;
26             my $instance = $xsub->($store, $name, $config, \$trap);
27             delete $config->{ptr};
28             unless($instance)
29             {
30             if($trap)
31             {
32             die Wasm::Wasmtime::Trap->new($trap);
33             }
34             Carp::croak("failed to create wasi instance");
35             }
36             $instance;
37             });
38              
39             # TODO: bind_import
40              
41             _generate_destroy();
42              
43             1;
44              
45             __END__