| 1 | package JavaScript::Duktape::XS; | ||||||||||||
| 2 | |||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 10 | ▶ | use parent 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 10 | ▶ | use Text::Trim qw(trim rtrim); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 10 | ▶ | use XSLoader; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 10 | our $VERSION = '0.000052'; | |||||||||||
| 11 | 10 | XSLoader::load( __PACKAGE__, $VERSION ); | |||||||||||
| 12 | |||||||||||||
| 13 | 10 | our @EXPORT_OK = qw[]; | |||||||||||
| 14 | |||||||||||||
| 15 | sub _get_js_source_fragment { | ||||||||||||
| 16 | 2 | ▶ | my ($context, $range) = @_; | ||||||||||
|
Subroutine
_get_js_source_fragment: called CC=8 SCAR=21.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 2 | ▶ | $range //= 5; | ||||||||||
|
Condition50%1/2
$range //= 5
MC/DC0%0/1
$range //= 5
$range
Truth table50%1/2
A
A= $range
| |||||||||||||
| 19 | 2 | foreach my $frame (@{ $context->{frames} }) { | |||||||||||
| 20 | 4 | open my $fh, '<', $frame->{file}; | |||||||||||
| 21 | 4 | ▶ | if (!$fh) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | # TODO: error message? | ||||||||||||
| 23 | 0 | return; | |||||||||||
| 24 | } | ||||||||||||
| 25 | 4 | my $lineno = 0; | |||||||||||
| 26 | 4 | my @lines; | |||||||||||
| 27 | 4 | ▶ | while (my $line = <$fh>) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 88 | ++$lineno; | |||||||||||
| 29 | 88 | ▶ | next unless $lineno >= ($frame->{line} - $range); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 48 | ▶ | $frame->{line_offset} = $lineno unless exists $frame->{line_offset}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | |||||||||||||
| 32 | 48 | ▶ | last unless $lineno <= ($frame->{line} + $range); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 44 | push @lines, rtrim($line); | |||||||||||
| 34 | } | ||||||||||||
| 35 | 4 | $frame->{lines} = \@lines; | |||||||||||
| 36 | } | ||||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | sub parse_js_stacktrace { | ||||||||||||
| 40 | 2 | ▶ | my ($self, $stacktrace_lines, $desired_frames) = @_; | ||||||||||
|
Subroutine
parse_js_stacktrace: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||
| 41 | |||||||||||||
| 42 | 2 | ▶ | $desired_frames //= 1; | ||||||||||
|
Condition50%1/2
$desired_frames //= 1
MC/DC0%0/1
$desired_frames //= 1
$desired_frames
Truth table50%1/2
A
A= $desired_frames
| |||||||||||||
| 43 | |||||||||||||
| 44 | # @contexts => [ { | ||||||||||||
| 45 | # message => "undefined variable foo", | ||||||||||||
| 46 | # frames => [ { | ||||||||||||
| 47 | # file => 'foo.js', | ||||||||||||
| 48 | # line => 232, # line 232 is the one with the error | ||||||||||||
| 49 | # line_offset => 230, # first line in @lines is 230 | ||||||||||||
| 50 | # lines => [ | ||||||||||||
| 51 | # "function a()", | ||||||||||||
| 52 | # "{", | ||||||||||||
| 53 | # " return foo.length", | ||||||||||||
| 54 | # "}", | ||||||||||||
| 55 | # ], | ||||||||||||
| 56 | # }, {...} ] | ||||||||||||
| 57 | # } ] | ||||||||||||
| 58 | 2 | my @contexts; | |||||||||||
| 59 | 2 | foreach my $line (@$stacktrace_lines) { | |||||||||||
| 60 | 2 | my @texts = split /\n/, trim($line); | |||||||||||
| 61 | 2 | my %context; | |||||||||||
| 62 | 2 | $context{frames} = []; | |||||||||||
| 63 | 2 | foreach my $text (@texts) { | |||||||||||
| 64 | 8 | $text = trim($text); | |||||||||||
| 65 | 8 | ▶ | next unless $text; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | 8 | ▶ | $context{message} = $text unless exists $context{message}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | 8 | ▶ | next unless $text =~ m/^\s*at\s*(\S*)\s*\((.*):([0-9]+)\)\s*$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 4 | ▶ | push @{ $context{frames} //= [] }, { | ||||||||||
|
Condition50%1/2
$context{"frames"} //= []
MC/DC0%0/1
$context{"frames"} //= []
$context{"frames"}
Truth table50%1/2
A
A= $context{"frames"}
| |||||||||||||
| 71 | file => $2, | ||||||||||||
| 72 | line => $3, | ||||||||||||
| 73 | }; | ||||||||||||
| 74 | 4 | ▶ | last if scalar @{ $context{frames} } >= $desired_frames; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | } | ||||||||||||
| 76 | 2 | ▶ | next unless exists $context{message}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 2 | _get_js_source_fragment(\%context); | |||||||||||
| 78 | 2 | push @contexts, \%context; | |||||||||||
| 79 | } | ||||||||||||
| 80 | 2 | return \@contexts; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 10 | 1; | |||||||||||
| 84 | |||||||||||||
| 85 | __END__ | ||||||||||||