| 1 | package Wasm::Wasmtime::Trap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 16 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use FFI::Platypus::Buffer (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use Wasm::Wasmtime::FFI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | '""' => sub { shift->message . "\n" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | bool => sub { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 16 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # ABSTRACT: Wasmtime trap class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 16 | our $VERSION = '0.24'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | $ffi_prefix = 'wasm_trap_'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | $ffi->load_custom_type('::PtrObject' => 'wasm_trap_t' => __PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | ▶ | $ffi->attach( [ wasmtime_trap_new => 'new' ] => [ 'opaque', 'size_t' ] => 'wasm_trap_t' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | my $xsub = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | if(@_ == 1 && defined $_[0] && !ref $_[0] && $_[0] =~ /^[0-9]+$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
@_ == 1 and defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]+$/
@_ == 1 and defined $_[0] and not ref $_[0]
@_ == 1 and defined $_[0]
MC/DC0%0/4
@_ == 1 and defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]+$/
@_ == 1
defined $_[0]
not ref $_[0]
$_[0] =~ /^[0-9]+$/
Truth table40%2/5
A and B and not(C) and D
A= @_ == 1B= defined $_[0]C= not ref $_[0]D= $_[0] =~ /^[0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # wrap an existing wasm_trap_t pointer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $ptr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return bless { ptr => $ptr }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # ignore a leading store argument (legacy calling convention) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | ▶ | shift if @_ == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 8 | my $message = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 8 | ▶ | $message = '' unless defined $message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 8 | $message =~ s/\0+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | my($ptr, $len) = FFI::Platypus::Buffer::scalar_to_buffer($message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | $xsub->($ptr, $len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | sub from_error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | my($class, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | my $self = $class->new($error->message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | $self->{exit_status} = $error->exit_status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | ▶ | $ffi->attach( [ wasm_trap_message => 'message' ] => ['wasm_trap_t', 'wasm_byte_vec_t*'] => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | my $message = Wasm::Wasmtime::ByteVec->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | $xsub->($self, $message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | my $ret = $message->get; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | $ret =~ s/\0$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | $message->delete; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | sub exit_status { shift->{exit_status} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exit_status: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $ffi->attach( [ wasmtime_trap_code => 'code' ] => ['wasm_trap_t','uint8*'] => 'bool' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $xsub->($self, \$code) ? $code : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 16 | _generate_destroy('wasm_trap_delete'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||