JE/Code.pm

filter: Statementstmt 90.1% 666 / 739 Branchbran 84.7% 373 / 440 Conditioncond 75.6% 165 / 218 MC/DCmcdc 59.6% 77 / 129 Subroutinesub 83.7% 77 / 92 Podpod 57.1% 4 / 7 totaltotal 83.8% 1362 / 1625 CC 309 SCAR 42.7
CC
309
Cov
86%
set_global
380.0
eval
167.0
eval
59.3
CRAP 71.6
« JE/Object/RegExp.pm ↑ Summary JE/Object/Math.pm »
1 package JE::Code;
2  
3 101 our $VERSION = '0.066';
4  
5 101 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 101 ▶use warnings; no warnings 'utf8', 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #use Data::Dumper;
9 101 ▶use Carp 1.01 'shortmess';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 101 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 101 ▶use Scalar::Util 'tainted';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 101 our @CARP_NOT = 'JE';
14 101 our @EXPORT_OK = 'add_line_number';
15  
16 101 ▶use constant T => ${^TAINT}; # perl doesn’t optimise if(${AINT}) away
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 101 require JE::Object::Error;
19 101 require JE::Object::Error::ReferenceError;
20 101 require JE::Object::Error::SyntaxError;
21 101 require JE::Object::Error::TypeError;
22 101 require JE::Object::Function;
23 101 require JE::Object::Array;
24 101 require JE::Boolean;
25 101 require JE::Object;
26 101 require JE::Parser;
27 101 require JE::Number;
28 101 require JE::LValue;
29 101 require JE::String;
30 101 require JE::Scope;
31  
32 sub add_line_number; # so I can call it without parentheses in sub execute
33  
34  
35 # This is documented in a POD comment at the bottom of the file.
36 338 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.5
Pod documented
37 338 my($global, $src, $file, $line) = @_;
38  
39 338 ($src, my ($tree, $vars)) = JE::Parser::_parse(
40 program => $src, $global, $file, $line
41 );
42  
43 338 ▶ $@ and return;
Branch: 1 branch
BranchTrueFalseTotal
$@ and return 23 315 338
44  
45 #print Dumper $tree;
46  
47 315 ▶ my $r= bless { global => $global,
Branch: 1 branch
BranchTrueFalseTotal
$JE::Parser::_parser ? : 5 310 315
48 ( $JE::Parser::_parser
49 ? (parser => $JE::Parser::_parser)
50 : () ),
51 source => \$src,
52 file => $file,
53 line => $line,
54 vars => $vars,
55 tree => $tree };
56 # $self->{source} is a reference, so that we can share the same
57 # source between code objects without the extra memory overhead
58 # that copying it would have. (Some JS script files are
59 # rather large.)
60  
61 $r->optimise
62 if $ENV{'YES_I_WANT_JE_TO_OPTIMISE'}
63 315 ▶ and $ENV{'YES_I_WANT_JE_TO_OPTIMISE'} ne 2;
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"YES_I_WANT_JE_TO_OPTIMISE"} and $ENV{"YES_I_WANT_JE_TO_OPTIMISE"} ne 2 0 315 315
Condition33%1/3
$ENV{"YES_I_WANT_JE_TO_OPTIMISE"} and $ENV{"YES_I_WANT_JE_TO_OPTIMISE"} ne 2
!ll&&!rl&&r
31500
MC/DC0%0/2
$ENV{"YES_I_WANT_JE_TO_OPTIMISE"} and $ENV{"YES_I_WANT_JE_TO_OPTIMISE"} ne 2
$ENV{"YES_I_WANT_JE_TO_OPTIMISE"} $ENV{"YES_I_WANT_JE_TO_OPTIMISE"} ne 2
Truth table33%1/3
A and B
A= $ENV{"YES_I_WANT_JE_TO_OPTIMISE"}B= $ENV{"YES_I_WANT_JE_TO_OPTIMISE"} ne 2
ABresult
0X0
100
111
64  
65 315 $r;
66 }
67  
68  
69  
70  
71 2 ▶sub execute_till { # ~~~ Should this be made public?
Subroutine execute_till: called CC=1 SCAR=0.0
Pod undocumented
72 2 (my $code, local our $counting) = (shift,shift);
73 2 local our $ops = 0;
74 JE_Code_OP: {
75 2 return $code->execute(@_);
76 }
77 # If we get here, then we reached the max number of ops.
78 1 $@ = shortmess "max_ops ($counting) exceeded";
79 1 return undef;
80 }
81  
82 0 ▶sub set_global {
Subroutine set_global: not called CC=19 SCAR=59.4
Pod documented
83 0 my $code = shift;
84 0 my $old = $code->{global};
85 0 $code->{global} = $_[0];
86 0 ▶ {for(@{$code->{cache}||last}) {
Condition0%0/2
$code->{'cache'} || (last)
l!l
00
MC/DC0%0/1
$code->{'cache'} || (last)
$code->{'cache'}
Truth table0%0/2
A
A= $code->{'cache'}
Aresult
11
00
87 0 ▶ ref eq 'JE::Code' and $_->set_global($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "JE::Code" and $_->set_global($_[0]) 0 0 0
88 }}
89 0 ▶ {for(@{$code->{vars}||last}){
Condition0%0/2
$code->{'vars'} || (last)
l!l
00
MC/DC0%0/1
$code->{'vars'} || (last)
$code->{'vars'}
Truth table0%0/2
A
A= $code->{'vars'}
Aresult
11
00
90 0 ▶ ref && ref $$_[4] eq 'JE::Code'
Branch: 1 branch
BranchTrueFalseTotal
ref $_ and ref $_->[4] eq "JE::Code" and $_->[4]->set_global($_[0]) 0 0 0
Condition0%0/3
ref $_ and ref $_->[4] eq "JE::Code"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and ref $_->[4] eq "JE::Code"
ref $_ ref $_->[4] eq "JE::Code"
Truth table0%0/3
A and B
A= ref $_B= ref $_->[4] eq "JE::Code"
ABresult
0X0
100
111
91 && $$_[4]->set_global($_[0])
92 }}
93 0 ▶ defined $old or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $old or return 0 0 0
94 0 my @stack = $code->{tree};
95 0 local *@;
96 0 ▶ while(@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 0 0 0
97 0 for(shift @stack) {
98 0 for(@$_[1..$#$_]) {
99 0 ▶ my $r = ref || next;
Condition0%0/2
ref $_ || (next)
l!l
00
MC/DC0%0/1
ref $_ || (next)
ref $_
Truth table0%0/2
A
A= ref $_
Aresult
11
00
100 0 ▶ $r =~ /^(?:ARRAY\z|JE::Code::)/
Branch: 1 branch
BranchTrueFalseTotal
$r =~ /^(?:ARRAY\z|JE::Code::)/ and push(@stack, $_) =~ (next) 0 0 0
101 and push @stack, $_, =~ next;
102 0 ▶ $r eq 'JE::Boolean'
Branch: 1 branch
BranchTrueFalseTotal
$r eq "JE::Boolean" and $_ = ("f", "t")[$_->value], next 0 0 0
103 and $_ = qw(f t)[$_->value], next;
104 0 ▶ $r eq 'JE::Number'
Branch: 1 branch
BranchTrueFalseTotal
$r eq "JE::Number" and $_ = $_->value, next 0 0 0
105 and $_ = $_->value, next;
106 0 ▶ $r eq 'JE::String'
Branch: 1 branch
BranchTrueFalseTotal
$r eq "JE::String" and $_ = 's' . $_->value16, next 0 0 0
107 and $_ = "s".$_->value16, next;
108 0 ▶ $r eq 'JE::Null' and $_ = 'n', next;
Branch: 1 branch
BranchTrueFalseTotal
$r eq "JE::Null" and $_ = "n", next 0 0 0
109 $r eq 'JE::Object::RegExp'
110 0 ▶ and $_ = [$_->{source}->value, $$$_{regexp_flags}],
Branch: 1 branch
BranchTrueFalseTotal
$r eq "JE::Object::RegExp" and $_ = [$_->{"source"}->value, $$_->{"regexp_flags"}], next 0 0 0
111 next;
112 }
113 }
114 }
115 0 return;
116 }
117  
118 0 ▶sub optimise {
Subroutine optimise: not called CC=1 SCAR=6.9
Pod undocumented
119 0 require 'JE/toperl.pl';
120 0 goto &{'optimise'};
121 }
122  
123 # Variables pertaining to the current execution context
124 101 our $code; # JE::Code object, not source code
125 101 our $this;
126 101 our $scope;
127 101 our $parser;
128 101 our $pos; # position within the source code; used to calculate a line no.
129 101 our $taint;
130 101 our $ops;
131 101 our $counting;
132 101 our $global;
133 101 our $return;
134 101 our $cache;
135  
136 2163 ▶sub execute {
Subroutine execute: called CC=21 SCAR=32.5
Pod documented
137 2163 local $code = shift;
138 2163 local $global = $$code{global};
139  
140 # We check $ops’ definedness to avoid resetting the op count when
141 # called recursively.
142 2163 ▶ if(!defined our $ops and my $max_ops = $global->max_ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined our $ops and my $max_ops = $JE::Code::global->max_ops) 2 2161 2163
Condition100%3/3
not defined our $ops and my $max_ops = $JE::Code::global->max_ops
!ll&&!rl&&r
221592
MC/DC100%2/2
not defined our $ops and my $max_ops = $JE::Code::global->max_ops
not defined our $ops my $max_ops = $JE::Code::global->max_ops
Truth table100%3/3
not(A) and B
A= not defined our $opsB= my $max_ops = $JE::Code::global->max_ops
ABresult
0X0
100
111
143 2 unshift @_, $code, $max_ops;
144 2 goto &execute_till;
145 }
146  
147 2161 ▶ local $this = defined $_[0] ? $_[0] : $global;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 1946 215 2161
148 2161 shift;
149  
150 2161 ▶ local $scope = shift || bless [$global], 'JE::Scope';
Condition100%2/2
shift() || bless([$JE::Code::global], 'JE::Scope')
l!l
1946215
MC/DC100%1/1
shift() || bless([$JE::Code::global], 'JE::Scope')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
151  
152 2161 ▶ my $code_type = shift || 0;
Condition100%2/2
shift() || 0
l!l
1947214
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
153  
154 2161 local our $taint = substr(${$$code{source}},0,0) if T;
155  
156 2161 my $rv;
157 2161 eval {
158 # passing these values around is too
159 # cumbersome
160 2161 local $JE::Code::parser = $code->{parser}; # might be
161 2161 local our $pos; # undef
162 2161 local our $code = $code;
163 2161 local $JE::Code::Expression::_eval = $code_type == 1;
164  
165 package JE::Code::Statement;
166 2161 local our $_label;
167 package JE::Code;
168 # This $return variable has two uses. It holds the return
169 # value when the JS 'return' statement calls 'last RETURN'.
170 # It also is used by statements that return values. It is
171 # necessary to use this var, rather than simply returning
172 # the value (as in v0.016 and earlier), in order to make
173 # 'while(true) { 3; break }' return 3, rather than
174 # undefined.
175 2161 local $return;
176 2161 ▶ local $cache = $$code{cache}||=[];
Condition100%2/2
$JE::Code::code->{"cache"} ||= []
l!l
1666495
MC/DC100%1/1
$JE::Code::code->{"cache"} ||= []
$JE::Code::code->{"cache"}
Truth table100%2/2
A
A= $JE::Code::code->{"cache"}
Aresult
11
00
177  
178 RETURN: {
179 2161 BREAK: {
180 2161 CONT: {
181 2161 JE'Code'Statement'_create_vars();
182 0 ▶ $$code{sub} ? &{$$code{sub}} :
Branch: 1 branch
BranchTrueFalseTotal
$JE::Code::code->{'psrc'} ? : 0 2161 2161
183 $$code{psrc}? (
184 # ~~~ temporary hack:
185 ($$code{psrc}) = $$code{psrc} =~/(.*)/s,
186 &{$$code{sub} =
187 16 ▶ eval{ eval("sub{$$code{psrc}}")||die }
Condition0%0/2
eval "sub{$JE::Code::code->{'psrc'}}" || die()
l!l
00
MC/DC0%0/1
eval "sub{$JE::Code::code->{'psrc'}}" || die()
eval "sub{$JE::Code::code->{'psrc'}}"
Truth table0%0/2
A
A= eval "sub{$JE::Code::code->{'psrc'}}"
Aresult
11
00
188 || die "Internal error that should never"
189 . " happen (please report this): $@: "
190 . $$code{psrc}
191 0 ▶ }):
Condition0%0/2
eval { do { eval "sub{$JE::Code::code->{'psrc'}}" or die } } || die('Internal error that should never' . " happen (please report this): $@: " . $JE::Code::code->{'psrc'})
l!l
00
MC/DC0%0/1
eval { do { eval "sub{$JE::Code::code->{'psrc'}}" or die } } || die('Internal error that should never' . " happen (please report this): $@: " . $JE::Code::code->{'psrc'})
eval { do { eval "sub{$JE::Code::code->{'psrc'}}" or die } }
Truth table0%0/2
A
A= eval { do { eval "sub{$JE::Code::code->{'psrc'}}" or die } }
Aresult
11
00
192 2145 ▶ $$code{tree}->eval;
Branch: 1 branch
BranchTrueFalseTotal
$JE::Code::code->{'sub'} ? : 0 2161 2161
193 487 ▶ $code_type == 2 # function
Branch: 1 branch
BranchTrueFalseTotal
$code_type == 2 or defined $JE::Code::return and $rv = $JE::Code::return 213 274 487
Condition66%4/6
$code_type == 2 || defined $JE::Code::return && ($rv = $JE::Code::return)
l!l
2132740
defined $JE::Code::return and $rv = $JE::Code::return
!ll
941800
MC/DC0%0/3
$code_type == 2 || defined $JE::Code::return && ($rv = $JE::Code::return)
$code_type == 2 defined $JE::Code::return $rv = $JE::Code::return
Truth table0%0/4
A || B and C
A= $code_type == 2B= defined $JE::Code::returnC= $rv = $JE::Code::return
ABCresult
1XX1
0111
00X0
0100
194 or defined $return && ($rv = $return);
195 471 goto FINISH;
196 }
197  
198 0 ▶ if($JE::Code::Statement::_label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Code::Statement::_label) { } 0 0 0
199 0 die new JE::Object::Error::SyntaxError $global,
200 add_line_number
201 "continue $JE::Code::Statement::_label: label " .
202 "'$JE::Code::Statement::_label' not found";
203 0 } else { goto FINISH; }
204  
205 } # end of BREAK
206  
207 0 ▶ if($JE::Code::Statement::_label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Code::Statement::_label) { } 0 0 0
208 0 die new JE::Object::Error::SyntaxError $global,
209 add_line_number
210 "break $JE::Code::Statement::_label: label " .
211 "'$JE::Code::Statement::_label' not found";
212 0 } else { goto FINISH; }
213  
214 } # end of RETURN
215  
216 1666 $rv = $return;
217  
218  
219 FINISH: # I have to put this here inside the eval,
220 # because 'eval { goto label }; label:' causes a
221 # a bus error in p5.8.8 if a tie handler is in
222 # the call stack (fixed in 5.9.5).
223 2137 };
224  
225 2160 ▶ T and defined $rv and tainted $taint and $rv->can('taint')
Branch: 1 branch
BranchTrueFalseTotal
defined $rv and &tainted($JE::Code::taint) and $rv->can("taint") and $rv = $rv->taint($JE::Code::taint) 33 2127 2160
Condition100%6/6
defined $rv and &tainted($JE::Code::taint) and $rv->can("taint")
!ll&&!rl&&r
2126133
defined $rv and &tainted($JE::Code::taint)
!ll&&!rl&&r
318180818
MC/DC100%3/3
defined $rv and &tainted($JE::Code::taint) and $rv->can("taint")
defined $rv &tainted($JE::Code::taint) $rv->can("taint")
Truth table100%4/4
A and B and C
A= defined $rvB= &tainted($JE::Code::taint)C= $rv->can("taint")
ABCresult
0XX0
10X0
1100
1111
226 and $rv = taint $rv $taint;
227  
228 2160 ▶ if(ref $@ eq '' and $@ eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $@ eq '' and $@ eq '') { } 2123 37 2160
Condition100%3/3
ref $@ eq "" and $@ eq ""
!ll&&!rl&&r
1762121
MC/DC100%2/2
ref $@ eq "" and $@ eq ""
ref $@ eq "" $@ eq ""
Truth table100%3/3
A and B
A= ref $@ eq ""B= $@ eq ""
ABresult
0X0
100
111
229 2121 ▶ !defined $rv and $rv = $scope->undefined;
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or $rv = $JE::Code::scope->undefined 1826 295 2121
230 }
231 else {
232 # Catch-all for any errors not dealt with elsewhere
233 39 $@ = _objectify_error($@);
234 }
235  
236 2144 $rv;
237 }
238  
239 310 ▶sub add_line_number {
Subroutine add_line_number: called CC=9 SCAR=22.0
Pod documented
240 310 my $msg = shift;
241 310 ▶ my $code = @_ ? shift : $code;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 31 279 310
242 310 ▶ my $pos = @_ ? shift : $pos ;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 26 284 310
243 310 ▶ $msg =~ /\n\z/ and return $msg;
Branch: 1 branch
BranchTrueFalseTotal
$msg =~ /\n\z/ and return $msg 19 291 310
244 defined(my $file = ($code || return $msg)->{file})
245 291 ▶ or defined $pos or return $msg;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $file = +($code || (return $msg))->{"file"}) or defined $pos or return $msg 278 1 279
Condition100%5/5
defined(my $file = +($code || (return $msg))->{"file"}) or defined $pos
l!l&&r!l&&!r
1421361
$code || (return $msg)
l!l
27912
MC/DC0%0/2
defined(my $file = +($code || (return $msg))->{"file"}) or defined $pos
$code defined $pos
Truth table33%1/3
A or B
A= $codeB= defined $pos
ABresult
1X1
011
000
246 278 my $first_line = $code->{line};
247 278 ▶ defined $first_line or $first_line = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $first_line or $first_line = 1 144 134 278
248 278 ▶ if(defined $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) { } 276 2 278
249 101 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
250 "$msg at $file" . ', ' x defined($file) . 'line ' .
251 276 ($first_line + (() = substr(${$code->{source}},0,$pos) =~
252 /\cm\cj?|[\cj\x{2028}\x{2029}]/g))
253 . ".\n";
254 } else {
255 2 "$msg in $file.\n"
256 }
257 }
258  
259 302 ▶sub _objectify_error {
Subroutine _objectify_error: called CC=3 SCAR=11.0
260 302 my $msg = shift;
261  
262 302 ▶ ref $msg and return $global->upgrade($msg);
Branch: 1 branch
BranchTrueFalseTotal
ref $msg and return $JE::Code::global->upgrade($msg) 265 37 302
263  
264 37 my $class = 'JE::Object::Error';
265  
266 37 ▶ if($msg =~ /^Can't\ locate\ object\ method\
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ /^Can't\ locate\ object\ method\ "(?:c(?:all|onstruct)|apply|invoke_with)"/x) 18 19 37
267 "(?:c(?:all|onstruct)|apply|invoke_with)"/x) {
268 # ~~~ the ‘apply’ in there is legacy and can be removed b4 v1
269 18 $class = 'JE::Object::Error::TypeError';
270 18 $msg = "Argument to new is not a constructor";
271 }
272  
273 37 new $class $global, add_line_number $msg;
274 }
275  
276 0 ▶sub DDS_freeze {
Subroutine DDS_freeze: not called CC=1 SCAR=6.9
Pod undocumented
277 0 my $self = shift;
278 0 my $copy = bless {%$self}, ref $self;
279 0 delete $copy->{sub};
280 0 $copy;
281 }
282  
283  
284  
285 package JE::Code::Statement; # This does not cover expression statements.
286  
287 101 our $VERSION = '0.066';
288  
289 101 ▶use subs qw'_eval_term';
Subroutine BEGIN: called CC=1 SCAR=0.0
290 101 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
291  
292 101 our( $_label);
293  
294 101 *_eval_term = *JE::Code::Expression::_eval_term;
295 101 import JE::Code 'add_line_number';
296 sub add_line_number;
297  
298  
299 # Note: each statement object is an array ref. The elems are:
300 # [0] - an array ref containing
301 # [0] - the starting position in the source code and
302 # [1] - the ending position
303 # [1] - the type of statement
304 # [2..$#] - the various expressions/statements that make up the statement
305  
306 12924 ▶sub eval { # evaluate statement
Subroutine eval: called CC=96 SCAR=51.2
307 12924 my $stm = shift;
308  
309 12924 my $type = $$stm[1];
310 12924 ▶ $type eq 'empty' || $type eq 'function' and return;
Branch: 1 branch
BranchTrueFalseTotal
$type eq "empty" || $type eq "function" and return 351 12573 12924
Condition100%3/3
$type eq "empty" or $type eq "function"
l!l&&r!l&&!r
11423712573
MC/DC100%2/2
$type eq "empty" or $type eq "function"
$type eq "empty" $type eq "function"
Truth table100%3/3
A or B
A= $type eq "empty"B= $type eq "function"
ABresult
1X1
011
000
311  
312 12573 my @labels;
313 12573 $pos = $$stm[0][0];
314  
315 12573 ▶ if ($type eq 'labelled') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "labelled") 10 12563 12573
316 10 @labels = @$stm[2..$#$stm-1];
317 10 ▶ if ($$stm[-1][1] =~ /^(?:do|while|for|switch)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stm->[-1][1] =~ /^(?:do|while|for|switch)\z/) 2 8 10
318 2 $stm = $$stm[-1];
319 2 $type = $$stm[1];
320 101 ▶ no warnings 'deprecated';
Subroutine BEGIN: called CC=1 SCAR=0.0
321 2 goto LOOPS; # skip unnecessary if statements
322 }
323  
324 BREAK: {
325 8 my $returned = $$stm[-1]->eval;
326 4 ▶ defined $returned and $return = $returned
Branch: 1 branch
BranchTrueFalseTotal
defined $returned and $JE::Code::return = $returned 0 4 4
327 }
328  
329 # Note that this has 'defined' in it, whereas the similar
330 # 'if' statement further down where the loop constructs are
331 # doesn't. This is because 'break' without a label sets
332 # $_label to '' and exits loops and switches.
333 7 ▶ if(! defined $_label || first {$_ eq $_label} @labels) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $JE::Code::Statement::_label or &first(sub { $_ eq $_label; } , @labels)) { } 6 1 7
Condition100%3/3
not defined $JE::Code::Statement::_label or &first(sub { $_ eq $_label; } , @labels)
l!l&&r!l&&!r
421
MC/DC100%2/2
not defined $JE::Code::Statement::_label or &first(sub { $_ eq $_label; } , @labels)
not defined $JE::Code::Statement::_label &first(sub { $_ eq $_label; } , @labels)
Truth table100%3/3
not(A) or B
A= not defined $JE::Code::Statement::_labelB= &first(sub { $_ eq $_label; } , @labels)
ABresult
1X1
011
000
334 6 undef $_label;
335 6 return;
336 } else {
337 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
338 1 last BREAK;
339 }
340 }
341  
342 12563 ▶ if ($type eq 'statements') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "statements") 9397 3166 12563
343  
344 # Execute the statements, one by one, and return the return
345 # value of the last statement that actually returned one.
346 9397 my $returned;
347 9397 for (@$stm[2..$#$stm]) {
348 21497 ▶ next if $_ eq 'empty';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "empty" 0 21497 21497
349 21497 ▶ defined($returned = $_->eval) and
Branch: 1 branch
BranchTrueFalseTotal
defined($returned = $_->eval) and $JE::Code::return = $returned, ref $JE::Code::return eq "JE::LValue" && $JE::Code::return->get 18021 1509 19530
Condition66%2/3
ref $JE::Code::return eq "JE::LValue" and $JE::Code::return->get
!ll
17966550
MC/DC0%0/2
ref $JE::Code::return eq "JE::LValue" and $JE::Code::return->get
ref $JE::Code::return eq "JE::LValue" $JE::Code::return->get
Truth table66%2/3
A and B
A= ref $JE::Code::return eq "JE::LValue"B= $JE::Code::return->get
ABresult
0X0
100
111
350 $return = $returned,
351 ref $return eq 'JE::LValue'
352 && get $return;
353 }
354 7427 return;
355 }
356 3166 ▶ if ($type eq 'var') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "var") 576 2590 3166
357 576 ▶ for (@$stm[2..$#$stm]) { if (@$_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$_ == 2) 428 192 620
358 428 my $ret = _eval_term $$_[1];
359 428 ▶ ref $ret eq'JE::LValue' and $ret = get $ret;
Branch: 1 branch
BranchTrueFalseTotal
ref $ret eq "JE::LValue" and $ret = $ret->get 25 403 428
360 426 $scope->find_var($$_[0])->set($ret);
361 }}
362 574 return;
363 }
364 2590 ▶ if ($type eq 'if') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "if") 194 2396 2590
365 # 2 3 4
366 # we have: expr statement statement?
367 194 my $returned;
368 194 ▶ if ($$stm[2]->eval->to_boolean->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stm->[2]->eval->to_boolean->value) { } 53 139 192
369 53 ▶ $$stm[3] eq 'empty' or $returned = $$stm[3]->eval;
Branch: 1 branch
BranchTrueFalseTotal
$stm->[3] eq "empty" or $returned = $stm->[3]->eval 0 53 53
370 }
371 else {
372 139 ▶ exists $$stm[4]
Branch: 1 branch
BranchTrueFalseTotal
exists $stm->[4] and $stm->[4] ne "empty" and $returned = $stm->[4]->eval 10 129 139
Condition66%2/3
exists $stm->[4] and $stm->[4] ne "empty"
!ll&&!rl&&r
129010
MC/DC50%1/2
exists $stm->[4] and $stm->[4] ne "empty"
exists $stm->[4] $stm->[4] ne "empty"
Truth table66%2/3
A and B
A= exists $stm->[4]B= $stm->[4] ne "empty"
ABresult
0X0
100
111
373 && $$stm[4] ne 'empty'
374 and $returned = $$stm[4]->eval;
375 }
376 153 ▶ defined $returned and $return = $returned;
Branch: 1 branch
BranchTrueFalseTotal
defined $returned and $JE::Code::return = $returned 16 137 153
377 return
378 153 }
379 2398 ▶ if ($type =~ /^(?:do|while|for|switch)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^(?:do|while|for|switch)\z/) 359 2037 2396
380 # We have one of the following:
381 #
382 # 1 2 3 4 5
383 # 'do' statement expression
384 # 'while' expression statement
385 # 'for' expression 'in' expression statement
386 # 'for' var_decl 'in' expression statement
387 # 'for' expression expression expression statement
388 # 'for' var_decl expression expression statement
389 #
390 # In those last two cases, expression may be 'empty'.
391 # (See further down for 'switch').
392  
393 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
394  
395 359 LOOPS:
396 my $returned;
397
398 BREAK: {
399 359 ▶ if ($type eq 'do') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'do') { } 18 341 359
elsif ($type eq 'while') { } 5 336 341
elsif ($type eq 'for' and $stm->[3] eq 'in') { } 40 296 336
elsif ($type eq 'for') { } 280 16 296
400 18 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$stm->[3]->eval->to_boolean->value and do { do { CONT: { defined($returned = ref $stm->[2] ? $stm->[2]->eval : undef) and $JE::Code::return = $returned; } ; if ($JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)) { goto NEXT; } ; undef $JE::Code::Statement::_label } } 5 15 20
401 CONT: {
402 23 ▶ defined ($returned = ref $$stm[2]
Branch: 2 branches
BranchTrueFalseTotal
defined($returned = ref $stm->[2] ? $stm->[2]->eval : undef) and $JE::Code::return = $returned 3 12 15
ref $stm->[2] ? : 23 0 23
403 ? $$stm[2]->eval : undef)
404 and $return = $returned;
405 }
406  
407 20 ▶ if($_label and
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)) 0 20 20
Condition33%1/3
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
!ll&&!rl&&r
2000
MC/DC0%0/2
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
$JE::Code::Statement::_label not &first(sub { $_ eq $_label; } , @labels)
Truth table33%1/3
A and not(B)
A= $JE::Code::Statement::_labelB= not &first(sub { $_ eq $_label; } , @labels)
ABresult
0X0
100
111
408 0 ▶ !first {$_ eq $_label} @labels) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
409 0 goto NEXT;
410 }
411 20 undef $_label;
412 } while $$stm[3]->eval->to_boolean->value;
413 }
414 elsif ($type eq 'while') {
415 5 ▶ CONT: while ($$stm[2]->eval->to_boolean->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stm->[2]->eval->to_boolean->value) 34 3 37
416 34 ▶ defined ($returned = ref $$stm[3]
Branch: 2 branches
BranchTrueFalseTotal
defined($returned = ref $stm->[3] ? $stm->[3]->eval : undef) and $JE::Code::return = $returned 32 0 32
ref $stm->[3] ? : 34 0 34
417 ? $$stm[3]->eval : undef)
418 and $return = $returned;
419 }
420 continue {
421 32 ▶ if($_label and
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)) 0 32 32
Condition33%1/3
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
!ll&&!rl&&r
3200
MC/DC0%0/2
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
$JE::Code::Statement::_label not &first(sub { $_ eq $_label; } , @labels)
Truth table33%1/3
A and not(B)
A= $JE::Code::Statement::_labelB= not &first(sub { $_ eq $_label; } , @labels)
ABresult
0X0
100
111
422 0 ▶ !first {$_ eq $_label} @labels) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
423 0 goto NEXT;
424 }
425 }
426 3 undef $_label;
427 }
428 ▶ elsif ($type eq 'for' and $$stm[3] eq 'in') {
Condition100%3/3
$type eq "for" and $stm->[3] eq "in"
!ll&&!rl&&r
1628040
MC/DC100%2/2
$type eq "for" and $stm->[3] eq "in"
$type eq "for" $stm->[3] eq "in"
Truth table100%3/3
A and B
A= $type eq "for"B= $stm->[3] eq "in"
ABresult
0X0
100
111
429 40 my $left_side = $$stm[2];
430 40 ▶ if ($left_side->[1] eq 'var') {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_side->[1] eq "var") 17 23 40
431 17 $left_side->eval;
432 17 $left_side = $left_side->[2][0];
433 # now contains the identifier
434 }
435 40 my $obj = $$stm[4]->eval;
436 40 ▶ $obj = $obj->get if ref $obj eq 'JE::LValue';
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj eq "JE::LValue" 30 10 40
437 40 ▶ ref($obj) =~ /^JE::(?:Undefined|Null)\z/
Branch: 1 branch
BranchTrueFalseTotal
ref($obj) =~ /^JE::(?:Undefined|Null)\z/ and undef $JE::Code::Statement::_label, return 0 40 40
438 # ~~~ Do we need undef $_label here?
439 and undef $_label, return;
440 40 my @keys = $obj->keys;
441 40 CONT: for(@keys) {
442 5229 ▶ if($_label and
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)) 0 5229 5229
Condition33%1/3
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
!ll&&!rl&&r
522900
MC/DC0%0/2
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
$JE::Code::Statement::_label not &first(sub { $_ eq $_label; } , @labels)
Truth table33%1/3
A and not(B)
A= $JE::Code::Statement::_labelB= not &first(sub { $_ eq $_label; } , @labels)
ABresult
0X0
100
111
443 0 ▶ !first {$_ eq $_label} @labels) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
444 0 goto NEXT;
445 }
446 5229 undef $_label;
447  
448 5229 ▶ next if not defined $obj->prop($_);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj->prop($_) 2 5227 5229
449 # in which case it's been deleted
450
451 5227 ▶ (ref $left_side ? $left_side->eval :
Branch: 1 branch
BranchTrueFalseTotal
ref $left_side ? : 28 5199 5227
452 $scope->find_var($left_side))
453 ->set(_new JE::String $global, $_);
454  
455 5227 ▶ defined ($returned = ref $$stm[5]
Branch: 2 branches
BranchTrueFalseTotal
defined($returned = ref $stm->[5] ? $stm->[5]->eval : undef) and $JE::Code::return = $returned 25 5202 5227
ref $stm->[5] ? : 5227 0 5227
456 ? $$stm[5]->eval : undef)
457 and $return = $returned;
458 }
459  
460 # In case 'continue LABEL' is called during the
461 # last iteration of the loop
462 40 ▶ if($_label and
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)) 0 40 40
Condition33%1/3
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
!ll&&!rl&&r
4000
MC/DC0%0/2
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
$JE::Code::Statement::_label not &first(sub { $_ eq $_label; } , @labels)
Truth table33%1/3
A and not(B)
A= $JE::Code::Statement::_labelB= not &first(sub { $_ eq $_label; } , @labels)
ABresult
0X0
100
111
463 0 ▶ !first {$_ eq $_label} @labels) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
464 0 next CONT;
465 }
466 40 undef $_label;
467  
468 }
469 elsif ($type eq 'for') { # for(;;)
470 280 my $tmp;
471 280 ▶ CONT: for (
Branch: 3 branches
BranchTrueFalseTotal
ref $tmp eq "JE::LValue" and $tmp->get 0 280 280
if (ref $stm->[3] ? $stm->[3]->eval->to_boolean->value : 1) 2867 237 3104
ref $stm->[3] ? : 3006 98 3104
Condition66%2/3
ref $stm->[2] && $stm->[2]->eval
!ll&&!rl&&r
083197
MC/DC50%1/2
ref $stm->[2] && $stm->[2]->eval
ref $stm->[2] $stm->[2]->eval
Truth table66%2/3
A && B
A= ref $stm->[2]B= $stm->[2]->eval
ABresult
0X0
100
111
472 $tmp = ref $$stm[2] && $$stm[2]->eval,
473 ref $tmp eq 'JE::LValue' && get $tmp;
474  
475 ref $$stm[3]
476 ? $$stm[3]->eval->to_boolean->value
477 : 1;
478  
479 2825 ▶ do{if($_label and
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)) 0 2825 2825
Condition33%1/3
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
!ll&&!rl&&r
282500
MC/DC0%0/2
$JE::Code::Statement::_label and not &first(sub { $_ eq $_label; } , @labels)
$JE::Code::Statement::_label not &first(sub { $_ eq $_label; } , @labels)
Truth table33%1/3
A and not(B)
A= $JE::Code::Statement::_labelB= not &first(sub { $_ eq $_label; } , @labels)
ABresult
0X0
100
111
480 0 ▶ !first {$_ eq $_label} @labels) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
481 0 goto NEXT;
482 }
483 2825 ▶ undef $_label;
Branch: 1 branch
BranchTrueFalseTotal
ref $tmp eq "JE::LValue" and $tmp->get 0 2824 2824
Condition66%2/3
ref $stm->[4] && $stm->[4]->eval
!ll&&!rl&&r
012824
MC/DC0%0/2
ref $stm->[4] && $stm->[4]->eval
ref $stm->[4] $stm->[4]->eval
Truth table33%1/3
A && B
A= ref $stm->[4]B= $stm->[4]->eval
ABresult
0X0
100
111
484 },
485 $tmp = ref $$stm[4] && $$stm[4]->eval,
486 ref $tmp eq 'JE::LValue' && get $tmp
487 ) {
488 2867 ▶ defined ($returned = ref $$stm[5]
Branch: 2 branches
BranchTrueFalseTotal
defined($returned = ref $stm->[5] ? $stm->[5]->eval : undef) and $JE::Code::return = $returned 1307 1518 2825
ref $stm->[5] ? : 2867 0 2867
489 ? $$stm[5]->eval : undef)
490 and $return = $returned;
491 }
492 }
493 else { # switch
494 # $stm->[2] is the parenthesized
495 # expression.
496 # Each pair of elements thereafter
497 # represents one case clause, an expr
498 # followed by statements, except for
499 # the default clause, which has the
500 # string 'default' for its first elem
501  
502
503 # Evaluate the expression in the header
504 16 my $given = $$stm[2]->eval;
505 16 ▶ $given = get $given if ref $given eq 'JE::LValue';
Branch: 1 branch
BranchTrueFalseTotal
if ref $given eq "JE::LValue" 0 16 16
506
507 # Look through the case clauses to see
508 # which it matches. At the same time,
509 # look for the default clause.
510  
511 101 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
512  
513 16 my($n, $default) = 1;
514 16 ▶ while (($n+=2) < @$stm) {
Branch: 1 branch
BranchTrueFalseTotal
if (($n += 2) < @$stm) 34 12 46
515 34 ▶ if($$stm[$n] eq 'default') {
Branch: 1 branch
BranchTrueFalseTotal
if ($stm->[$n] eq "default") 10 24 34
516 10 $default = $n; next;
517 }
518  
519 # Execute the statements if we have a match
520 24 ▶ if("JE::Code::Expression::in==="->(
Branch: 1 branch
BranchTrueFalseTotal
if ('JE::Code::Expression::in==='->($given, $stm->[$n]->eval)) 4 20 24
521 $given, $$stm[$n]->eval
522 )) {
523 4 $n++;
524 4 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
($n += 2) < @$stm and do { do { $stm->[$n]->eval } } 2 4 6
525 6 $$stm[$n]->eval;
526 } while ($n+=2) < @$stm;
527 4 undef $default;
528 4 last;
529 }
530 } ;
531  
532 # If we can't find a case that matches, but we
533 # did find a default (and $default was not erased
534 # when a case matched)
535 16 ▶ if(defined $default) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) 10 6 16
536 10 $n = $default +1;
537 10 ▶ do { $$stm[$n]->eval }
Branch: 1 branch
BranchTrueFalseTotal
($n += 2) < @$stm and do { do { $stm->[$n]->eval } } 10 10 20
538 while ($n+=2) < @$stm;
539 }
540 } # switch
541  
542 } # end of BREAK
543  
544  
545 0 ▶ if(!$_label || first {$_ eq $_label} @labels) {
Subroutine __ANON__: not called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
if (not $JE::Code::Statement::_label or &first(sub { $_ eq $_label; } , @labels)) { } 358 0 358
Condition33%1/3
not $JE::Code::Statement::_label or &first(sub { $_ eq $_label; } , @labels)
l!l&&r!l&&!r
35800
MC/DC0%0/2
not $JE::Code::Statement::_label or &first(sub { $_ eq $_label; } , @labels)
not $JE::Code::Statement::_label &first(sub { $_ eq $_label; } , @labels)
Truth table33%1/3
not(A) or B
A= not $JE::Code::Statement::_labelB= &first(sub { $_ eq $_label; } , @labels)
ABresult
1X1
011
000
546 358 undef $_label;
547 358 return;
548 } else {
549 0 last BREAK;
550 }
551
552 0 NEXT: next CONT;
553 }
554 2037 ▶ if ($type eq 'continue') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "continue") 5 2032 2037
555 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
556 5 ▶ $_label = exists $$stm[2] ? $$stm[2] : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $stm->[2] ? : 0 5 5
557 5 next CONT;
558 }
559 2032 ▶ if ($type eq 'break') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "break") 49 1983 2032
560 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
561 49 ▶ $_label = exists $$stm[2] ? $$stm[2] : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $stm->[2] ? : 2 47 49
562 49 last BREAK;
563 }
564 1983 ▶ if ($type eq 'return') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "return") 1651 332 1983
565 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
566 1651 ▶ if (exists $$stm[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $stm->[2]) { } 1649 2 1651
567 1649 ▶ ref ($return = $$stm[2]->eval) eq 'JE::LValue'
Branch: 1 branch
BranchTrueFalseTotal
ref($JE::Code::return = $stm->[2]->eval) eq "JE::LValue" and $JE::Code::return = $JE::Code::return->get 90 1558 1648
568 and $return = get $return;
569 2 } else { $return = undef }
570 1650 last RETURN;
571 }
572 332 ▶ if ($type eq 'with') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "with") 14 318 332
573 14 local $scope = bless [
574 @$scope, $$stm[2]->eval->to_object
575 ], 'JE::Scope';
576 14 my $returned = $$stm[3]->eval;
577 14 ▶ defined $returned and $return = $returned;
Branch: 1 branch
BranchTrueFalseTotal
defined $returned and $JE::Code::return = $returned 3 11 14
578 14 return;
579 }
580 318 ▶ if ($type eq 'throw') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "throw") 13 305 318
581 13 my $excep;
582 13 ▶ if (exists $$stm[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $stm->[2]) 13 0 13
583 13 ▶ ref ($excep = $$stm[2]->eval) eq 'JE::LValue'
Branch: 1 branch
BranchTrueFalseTotal
ref($excep = $stm->[2]->eval) eq "JE::LValue" and $excep = $excep->get 2 11 13
584 and $excep = get $excep;
585 }
586 13 ▶ die defined $excep? $excep : $global->undefined;
Branch: 1 branch
BranchTrueFalseTotal
defined $excep ? : 13 0 13
587 }
588 305 ▶ if ($type eq 'try') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "try") 305 0 305
589 # We have one of the following:
590 # 1 2 3 4 5
591 # 'try' block ident block (catch)
592 # 'try' block block (finally)
593 # 'try' block ident block block (catch & finally)
594  
595 305 my $result;
596 my $propagate;
597  
598 305 eval { # try
599 305 local $return;
600 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
601 RETURN: {
602 305 BREAK: {
603 305 CONT: {
604 305 $result = $$stm[2]->eval;
605 26 goto SAVERESULT;
606 0 ▶ } $propagate = sub{ next CONT }; goto SAVERESULT;
Subroutine __ANON__: not called CC=1 SCAR=6.9
607 0 ▶ } $propagate = sub{ last BREAK }; goto SAVERESULT;
Subroutine __ANON__: not called CC=1 SCAR=6.9
608 0 ▶ } $propagate = sub{ last RETURN }; goto SAVERESULT;
Subroutine __ANON__: not called CC=1 SCAR=6.9
609  
610 26 ▶ SAVERESULT:
Branch: 1 branch
BranchTrueFalseTotal
defined $result or $result = $JE::Code::return 0 26 26
611 defined $result or $result = $return;
612 26 goto FINALLY;
613 };
614 # check ref first to avoid the overhead of overloading
615 279 ▶ if (ref $@ || $@ ne '' and !ref $$stm[3]) { # catch
Branch: 1 branch
BranchTrueFalseTotal
if (ref $@ || $@ ne "" and not ref $stm->[3]) 279 0 279
Condition50%3/6
ref $@ || $@ ne "" and not ref $stm->[3]
!ll&&!rl&&r
00279
ref $@ or $@ ne ""
l!l&&r!l&&!r
248310
MC/DC0%0/3
ref $@ || $@ ne "" and not ref $stm->[3]
ref $@ $@ ne "" not ref $stm->[3]
Truth table40%2/5
A or B and not(C)
A= ref $@B= $@ ne ""C= not ref $stm->[3]
ABCresult
00X0
1X00
0100
1X11
0111
616 279 undef $result; # prevent { 3; throw ... } from
617 # returning 3
618  
619 # Turn miscellaneous errors into Error objects
620 279 $@ = JE'Code'_objectify_error($@);
621  
622 279 (my $new_obj = new JE::Object $global)
623 ->prop({
624 name => $$stm[3],
625 value => $@,
626 dontdel => 1,
627 });
628 279 local $scope = bless [
629 @$scope, $new_obj
630 ], 'JE::Scope';
631
632 279 eval { # in case the catch block ends abruptly
633 279 local $return;
634 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
635 RETURN: {
636 279 BREAK: {
637 279 CONT: {
638 279 $result = $$stm[4]->eval;
639 279 goto SAVE;
640 0 ▶ } $propagate = sub{ next CONT }; goto SAVE;
Subroutine __ANON__: not called CC=1 SCAR=6.9
641 0 ▶ } $propagate = sub{ last BREAK }; goto SAVE;
Subroutine __ANON__: not called CC=1 SCAR=6.9
642 0 ▶ } $propagate = sub{ last RETURN }; goto SAVE;
Subroutine __ANON__: not called CC=1 SCAR=6.9
643  
644 279 ▶ SAVE:
Branch: 1 branch
BranchTrueFalseTotal
defined $result or $result = $JE::Code::return 0 279 279
645 defined $result or $result = $return;
646 279 $@ = '';
647 }
648 }
649 # In case the 'finally' block resets $@:
650 279 my $exception = $@;
651 FINALLY:
652 305 ▶ if ($#$stm == 3 or $#$stm == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stm->$#* == 3 or $stm->$#* == 5) 6 299 305
Condition100%3/3
$stm->$#* == 3 or $stm->$#* == 5
l!l&&r!l&&!r
24299
MC/DC100%2/2
$stm->$#* == 3 or $stm->$#* == 5
$stm->$#* == 3 $stm->$#* == 5
Truth table100%3/3
A or B
A= $stm->$#* == 3B= $stm->$#* == 5
ABresult
1X1
011
000
653 6 $$stm[-1]->eval;
654 }
655 305 ▶ defined $exception and ref $exception || $exception ne ''
Branch: 1 branch
BranchTrueFalseTotal
defined $exception and ref $exception || $exception ne "" and die $exception 0 305 305
Condition50%3/6
defined $exception and ref $exception || $exception ne ""
!ll&&!rl&&r
262790
ref $exception or $exception ne ""
l!l&&r!l&&!r
00279
MC/DC0%0/3
defined $exception and ref $exception || $exception ne ""
defined $exception ref $exception $exception ne ""
Truth table50%2/4
A and B or C
A= defined $exceptionB= ref $exceptionC= $exception ne ""
ABCresult
0XX0
1000
11X1
1011
656 and die $exception;
657 305 ▶ $return = $result if defined $result;
Branch: 1 branch
BranchTrueFalseTotal
if defined $result 295 10 305
658 305 ▶ $propagate and &$propagate();
Branch: 1 branch
BranchTrueFalseTotal
$propagate and &$propagate() 0 305 305
659 }
660 }
661  
662 2161 ▶sub _create_vars { # Process var and function declarations
Subroutine _create_vars: called CC=4 SCAR=14.0
663 2161 my $vars = $code->{vars};
664 2161 for(@$vars) {
665 758 ▶ if(ref) { # function
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 168 590 758
666 # format: [[...], function=> 'name',
667 # [ (params) ], $statements_obj, \@vars ]
668 # With optimisation on, the $statements_obj will
669 # actually be a code object.
670 168 $scope->[-1]->delete($$_[2], 1);
671 168 my $new_code_obj;
672 168 ▶ if(ref $$_[4] eq 'JE::Code') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_->[4] eq 'JE::Code') { } 0 168 168
673 0 $new_code_obj = $$_[4]
674 }
675 else {
676 ($new_code_obj = bless {
677 map+($_=>$code->{$_}),
678 qw/global source file line/
679 }, 'JE::Code')
680 168 ->{tree} = $$_[4];
681 168 $new_code_obj->{vars} = $$_[5];
682 }
683 168 $scope->new_var($$_[2], new JE::Object::Function {
684 scope => $scope,
685 name => $$_[2],
686 argnames => $$_[3],
687 function => $new_code_obj
688 });
689 }
690 else {
691 590 $scope->new_var($_);
692 }
693 }
694 }
695  
696  
697  
698  
699 package JE::Code::Expression;
700  
701 101 our $VERSION = '0.066';
702  
703 # B::Deparse showed me how to get these values.
704 101 ▶use constant nan => sin 9**9**9;
Subroutine BEGIN: called CC=1 SCAR=0.0
705 101 ▶use constant inf => 9**9**9;
Subroutine BEGIN: called CC=1 SCAR=0.0
706  
707 101 ▶use subs qw'_eval_term';
Subroutine BEGIN: called CC=1 SCAR=0.0
708 101 ▶use POSIX 'fmod';
Subroutine BEGIN: called CC=1 SCAR=0.0
709 101 ▶use Scalar::Util 'tainted';
Subroutine BEGIN: called CC=1 SCAR=0.0
710  
711 101 import JE::Code 'add_line_number';
712 sub add_line_number;
713  
714 101 ▶BEGIN{*T = *JE::Code::T;}
Subroutine BEGIN: called CC=1 SCAR=0.0
715  
716  
717 #----------for reference------------#
718 #sub _to_int {
719 # call to_number first
720 # then...
721 # NaN becomes 0
722 # 0 and Infinity remain as they are
723 # other nums are rounded towards zero ($_ <=> 0) * floor(abs)
724 #}
725  
726 # Note that abs in ECMA-262
727 #sub _to_uint32 {
728 # call to_number, then ...
729  
730 # return 0 for Nan, -?inf and 0
731 # (round toward zero) % 2 ** 32
732 #}
733  
734 #sub _to_int32 {
735 # calculate _to_uint32 but subtract 2**32 if the result >= 2**31
736 #}
737  
738 #sub _to_uint16 {
739 # just like _to_uint32, except that 2**16 is used instead.
740 #}
741  
742  
743 #---------------------------------#
744  
745 { # JavaScript operators
746 # Note: some operators are not dealt with here, but inside
747 # sub eval.
748 101 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
749 101 ▶ *{'predelete'} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
750 209 ▶ ref(my $term = shift) eq 'JE::LValue' or return
Branch: 1 branch
BranchTrueFalseTotal
ref(my $term = shift()) eq "JE::LValue" or return "JE::Boolean"->new($JE::Code::global, 1) 203 6 209
751 new JE::Boolean $global, 1;
752 203 my $base = $term->base;
753 203 ▶ new JE::Boolean $global,
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 197 6 203
754 defined $base ? $base->delete($term->property) : 1;
755 101 };
756 101 ▶ *{'prevoid'} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
757 318 my $term = shift;
758 318 ▶ $term = get $term while ref $term eq 'JE::LValue';
Branch: 1 branch
BranchTrueFalseTotal
ref $term eq "JE::LValue" and do { $term = $term->get } 1 317 318
759 317 return $global->undefined;
760 101 };
761 101 ▶ *{'pretypeof'} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
762 166 my $term = shift;
763 166 ▶ ref $term eq 'JE::LValue' and
Branch: 1 branch
BranchTrueFalseTotal
ref $term eq "JE::LValue" and ref $term->base eq "" and return "JE::String"->_new($JE::Code::global, "undefined") 1 165 166
Condition100%3/3
ref $term eq "JE::LValue" and ref $term->base eq ""
!ll&&!rl&&r
181471
MC/DC100%2/2
ref $term eq "JE::LValue" and ref $term->base eq ""
ref $term eq "JE::LValue" ref $term->base eq ""
Truth table100%3/3
A and B
A= ref $term eq "JE::LValue"B= ref $term->base eq ""
ABresult
0X0
100
111
764 ref base $term eq '' and
765 return _new JE::String $global, 'undefined';
766 165 _new JE::String $global, typeof $term;
767 101 };
768 101 ▶ *{'pre++'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
769 # ~~~ These is supposed to use the same rules
770 # as the + infix op for the actual
771 # addition part. Verify that it does this.
772 2832 my $term = shift;
773 2832 $term->set(new JE::Number $global,
774 get $term->to_number + 1);
775 101 };
776 101 ▶ *{'pre--'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
777 # ~~~ These is supposed to use the same rules
778 # as the - infix op for the actual
779 # subtraction part. Verify that it does this.
780 12 my $term = shift;
781 12 $term->set(new JE::Number $global,
782 get $term->to_number->value - 1);
783 101 };
784 101 ▶ *{'pre+'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
785 594 shift->to_number;
786 101 };
787 101 ▶ *{'pre-'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
788 7297 new JE::Number $global, -shift->to_number->value;
789 101 };
790 101 ▶ *{'pre~'} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
791 38 my $num = shift->to_number->value;
792 38 ▶ $num =
Branch: 1 branch
BranchTrueFalseTotal
$num != $num || abs $num == 9**9**9 ? : 6 32 38
Condition100%3/3
$num != $num or abs $num == "Inf"
l!l&&r!l&&!r
4232
MC/DC100%2/2
$num != $num or abs $num == "Inf"
$num != $num abs $num == "Inf"
Truth table100%3/3
A or B
A= $num != $numB= abs $num == "Inf"
ABresult
1X1
011
000
793 $num != $num || abs($num) == inf # nan/+-inf
794 ? 0
795 : int($num) % 2**32;
796  
797 38 ▶ $num -= 2**32 if $num >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num >= "2147483648" 13 25 38
798  
799 101 ▶ { use integer; # for signed bitwise negation
Subroutine BEGIN: called CC=1 SCAR=0.0
800 38 $num = ~$num; }
801
802 38 new JE::Number $global, $num;
803 101 };
804 101 ▶ *{'pre!'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
805 691 new JE::Boolean $global, !shift->to_boolean->value
806 101 };
807 101 ▶ *{'in*'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
808 70 new JE::Number $global,
809 shift->to_number->value *
810 shift->to_number->value;
811 101 };
812 101 ▶ *{'in/'} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
813 50 my($num,$denom) = map to_number $_->value, @_[0,1];
814 50 ▶ new JE::Number $global,
Branch: 2 branches
BranchTrueFalseTotal
$denom ? : 43 7 50
$num && $num == $num ? : 6 1 7
Condition66%2/3
$num and $num == $num
!ll&&!rl&&r
106
MC/DC50%1/2
$num and $num == $num
$num $num == $num
Truth table66%2/3
A and B
A= $numB= $num == $num
ABresult
0X0
100
111
815 $denom ?
816 $num/$denom :
817 # Divide by zero:
818 $num && $num == $num # not zero or nan
819 ? $num * inf
820 : nan;
821 101 };
822 101 ▶ *{'in%'} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
823 46 my($num,$denom) = map to_number $_->value,
824 @_[0,1];
825 46 ▶ new JE::Number $global,
Branch: 2 branches
BranchTrueFalseTotal
$num + 1 == $num ? : 4 42 46
$num == $num && abs $denom == 9**9**9 ? : 4 38 42
Condition100%3/3
$num == $num and abs $denom == "Inf"
!ll&&!rl&&r
4344
MC/DC100%2/2
$num == $num and abs $denom == "Inf"
$num == $num abs $denom == "Inf"
Truth table100%3/3
A and B
A= $num == $numB= abs $denom == "Inf"
ABresult
0X0
100
111
826 $num+1 == $num ? nan :
827 $num == $num && abs($denom) == inf ?
828 $num :
829 fmod $num, $denom;
830 101 };
831 101 ▶ *{'in+'} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
832 19783 my($x, $y) = @_;
833 19783 $x = $x->to_primitive;
834 19783 $y = $y->to_primitive;
835 19781 ▶ if($x->typeof eq 'string' or
Branch: 1 branch
BranchTrueFalseTotal
if ($x->typeof eq "string" or $y->typeof eq "string") 19489 292 19781
Condition100%3/3
$x->typeof eq "string" or $y->typeof eq "string"
l!l&&r!l&&!r
144305059292
MC/DC100%2/2
$x->typeof eq "string" or $y->typeof eq "string"
$x->typeof eq "string" $y->typeof eq "string"
Truth table100%3/3
A or B
A= $x->typeof eq "string"B= $y->typeof eq "string"
ABresult
1X1
011
000
836 $y->typeof eq 'string') {
837 19489 return _new JE::String $global,
838 $x->to_string->value16 .
839 $y->to_string->value16;
840 }
841 292 return new JE::Number $global,
842 $x->to_number->value +
843 $y->to_number->value;
844 101 };
845 101 ▶ *{'in-'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
846 57 new JE::Number $global,
847 shift->to_number->value -
848 shift->to_number->value;
849 101 };
850 101 ▶ *{'in<<'} = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
851 897 my $num = shift->to_number->value;
852 897 ▶ $num =
Branch: 1 branch
BranchTrueFalseTotal
$num != $num || abs $num == 9**9**9 ? : 108 789 897
Condition100%3/3
$num != $num or abs $num == "Inf"
l!l&&r!l&&!r
5058789
MC/DC100%2/2
$num != $num or abs $num == "Inf"
$num != $num abs $num == "Inf"
Truth table100%3/3
A or B
A= $num != $numB= abs $num == "Inf"
ABresult
1X1
011
000
853 $num != $num || abs($num) == inf # nan/+-inf
854 ? $num = 0
855 : int($num) % 2**32;
856 897 ▶ $num -= 2**32 if $num >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num >= "2147483648" 377 520 897
857  
858 897 my $shift_by = shift->to_number->value;
859 897 ▶ $shift_by =
Branch: 1 branch
BranchTrueFalseTotal
$shift_by != $shift_by || abs $shift_by == 9**9**9 ? : 108 789 897
Condition100%3/3
$shift_by != $shift_by or abs $shift_by == "Inf"
l!l&&r!l&&!r
5058789
MC/DC100%2/2
$shift_by != $shift_by or abs $shift_by == "Inf"
$shift_by != $shift_by abs $shift_by == "Inf"
Truth table100%3/3
A or B
A= $shift_by != $shift_byB= abs $shift_by == "Inf"
ABresult
1X1
011
000
860 $shift_by != $shift_by || abs($shift_by) == inf
861 ? 0
862 : int($shift_by) % 32;
863  
864 897 my $ret = ($num << $shift_by) % 2**32;
865 897 ▶ $ret -= 2**32 if $ret >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $ret >= "2147483648" 326 571 897
866  
867 897 new JE::Number $global, $ret;
868  
869 # Fails on 64-bit:
870 #use integer;
871 #new JE::Number $global,
872 # $num << $shift_by;
873 101 };
874 101 ▶ *{'in>>'} = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
875 897 my $num = shift->to_number->value;
876 897 ▶ $num =
Branch: 1 branch
BranchTrueFalseTotal
$num != $num || abs $num == 9**9**9 ? : 101 796 897
Condition100%3/3
$num != $num or abs $num == "Inf"
l!l&&r!l&&!r
4358796
MC/DC100%2/2
$num != $num or abs $num == "Inf"
$num != $num abs $num == "Inf"
Truth table100%3/3
A or B
A= $num != $numB= abs $num == "Inf"
ABresult
1X1
011
000
877 $num != $num || abs($num) == inf # nan/+-inf
878 ? $num = 0
879 : int($num) % 2**32;
880 897 ▶ $num -= 2**32 if $num >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num >= "2147483648" 377 520 897
881  
882 897 my $shift_by = shift->to_number->value;
883 897 ▶ $shift_by =
Branch: 1 branch
BranchTrueFalseTotal
$shift_by != $shift_by || abs $shift_by == 9**9**9 ? : 101 796 897
Condition100%3/3
$shift_by != $shift_by or abs $shift_by == "Inf"
l!l&&r!l&&!r
4358796
MC/DC100%2/2
$shift_by != $shift_by or abs $shift_by == "Inf"
$shift_by != $shift_by abs $shift_by == "Inf"
Truth table100%3/3
A or B
A= $shift_by != $shift_byB= abs $shift_by == "Inf"
ABresult
1X1
011
000
884 $shift_by != $shift_by || abs($shift_by) == inf
885 ? 0
886 : int($shift_by) % 32;
887  
888 101 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
889 897 new JE::Number $global,
890 $num >> $shift_by;
891 101 };
892 101 ▶ *{'in>>>'} = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
893 897 my $num = shift->to_number->value;
894 897 ▶ $num =
Branch: 1 branch
BranchTrueFalseTotal
$num != $num || abs $num == 9**9**9 ? : 101 796 897
Condition100%3/3
$num != $num or abs $num == "Inf"
l!l&&r!l&&!r
4358796
MC/DC100%2/2
$num != $num or abs $num == "Inf"
$num != $num abs $num == "Inf"
Truth table100%3/3
A or B
A= $num != $numB= abs $num == "Inf"
ABresult
1X1
011
000
895 $num != $num || abs($num) == inf # nan/+-inf
896 ? $num = 0
897 : int($num) % 2**32;
898  
899 897 my $shift_by = shift->to_number->value;
900 897 ▶ $shift_by =
Branch: 1 branch
BranchTrueFalseTotal
$shift_by != $shift_by || abs $shift_by == 9**9**9 ? : 101 796 897
Condition100%3/3
$shift_by != $shift_by or abs $shift_by == "Inf"
l!l&&r!l&&!r
4358796
MC/DC100%2/2
$shift_by != $shift_by or abs $shift_by == "Inf"
$shift_by != $shift_by abs $shift_by == "Inf"
Truth table100%3/3
A or B
A= $shift_by != $shift_byB= abs $shift_by == "Inf"
ABresult
1X1
011
000
901 $shift_by != $shift_by || abs($shift_by) == inf
902 ? 0
903 : int($shift_by) % 32;
904  
905 897 new JE::Number $global,
906 $num >> $shift_by;
907 101 };
908 101 ▶ *{'in<'} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
909 1488 my($x,$y) = map to_primitive $_, @_[0,1];
910 1488 ▶ new JE::Boolean $global,
Branch: 1 branch
BranchTrueFalseTotal
$x->typeof eq 'string' && $y->typeof eq 'string' ? : 10 1478 1488
Condition100%3/3
$x->typeof eq "string" and $y->typeof eq "string"
!ll&&!rl&&r
14681010
MC/DC100%2/2
$x->typeof eq "string" and $y->typeof eq "string"
$x->typeof eq "string" $y->typeof eq "string"
Truth table100%3/3
A and B
A= $x->typeof eq "string"B= $y->typeof eq "string"
ABresult
0X0
100
111
911 $x->typeof eq 'string' &&
912 $y->typeof eq 'string'
913 ? $x->to_string->value16 lt $y->to_string->value16
914 : $x->to_number->[0] < $y->to_number->[0];
915 101 };
916 101 ▶ *{'in>'} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
917 80 my($x,$y) = map to_primitive $_, @_[0,1];
918 80 ▶ new JE::Boolean $global,
Branch: 1 branch
BranchTrueFalseTotal
$x->typeof eq 'string' && $y->typeof eq 'string' ? : 10 70 80
Condition100%3/3
$x->typeof eq "string" and $y->typeof eq "string"
!ll&&!rl&&r
601010
MC/DC100%2/2
$x->typeof eq "string" and $y->typeof eq "string"
$x->typeof eq "string" $y->typeof eq "string"
Truth table100%3/3
A and B
A= $x->typeof eq "string"B= $y->typeof eq "string"
ABresult
0X0
100
111
919 $x->typeof eq 'string' &&
920 $y->typeof eq 'string'
921 ? $x->to_string->value16 gt $y->to_string->value16
922 : $x->to_number->[0] > $y->to_number->[0];
923 101 };
924 101 ▶ *{'in<='} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
925 1568 my($x,$y) = map to_primitive $_, @_[0,1];
926 1568 ▶ new JE::Boolean $global,
Branch: 1 branch
BranchTrueFalseTotal
$x->typeof eq 'string' && $y->typeof eq 'string' ? : 10 1558 1568
Condition100%3/3
$x->typeof eq "string" and $y->typeof eq "string"
!ll&&!rl&&r
15481010
MC/DC100%2/2
$x->typeof eq "string" and $y->typeof eq "string"
$x->typeof eq "string" $y->typeof eq "string"
Truth table100%3/3
A and B
A= $x->typeof eq "string"B= $y->typeof eq "string"
ABresult
0X0
100
111
927 $x->typeof eq 'string' &&
928 $y->typeof eq 'string'
929 ? $x->to_string->value16 le $y->to_string->value16
930 : $x->to_number->[0] <= $y->to_number->[0];
931 101 };
932 101 ▶ *{'in>='} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
933 72 my($x,$y) = map to_primitive $_, @_[0,1];
934 72 ▶ new JE::Boolean $global,
Branch: 1 branch
BranchTrueFalseTotal
$x->typeof eq 'string' && $y->typeof eq 'string' ? : 10 62 72
Condition100%3/3
$x->typeof eq "string" and $y->typeof eq "string"
!ll&&!rl&&r
521010
MC/DC100%2/2
$x->typeof eq "string" and $y->typeof eq "string"
$x->typeof eq "string" $y->typeof eq "string"
Truth table100%3/3
A and B
A= $x->typeof eq "string"B= $y->typeof eq "string"
ABresult
0X0
100
111
935 $x->typeof eq 'string' &&
936 $y->typeof eq 'string'
937 ? $x->to_string->value16 ge $y->to_string->value16
938 : $x->to_number->[0] >= $y->to_number->[0];
939 101 };
940 101 ▶ *{'ininstanceof'} = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
941 216 my($obj,$func) = @_;
942 216 ▶ die new JE::Object::Error::TypeError $global,
Branch: 1 branch
BranchTrueFalseTotal
if $func->primitive 2 214 216
943 add_line_number "$func is not an object"
944 if $func->primitive;
945  
946 214 ▶ die new JE::Object::Error::TypeError $global,
Branch: 1 branch
BranchTrueFalseTotal
if $func->typeof ne "function" 1 213 214
947 add_line_number "$func is not a function"
948 if $func->typeof ne 'function';
949
950 213 ▶ return new JE::Boolean $global, 0 if $obj->primitive;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->primitive 5 208 213
951  
952 208 my $proto_id = $func->prop('prototype');
953 208 ▶ !defined $proto_id || $proto_id->primitive and die new
Branch: 1 branch
BranchTrueFalseTotal
!defined($proto_id) || $proto_id->primitive and die "JE::Object::Error::TypeError"->new($JE::Code::global, add_line_number(qq[Function $$func->{"func_name"} has no prototype property])) 2 206 208
Condition100%3/3
not defined $proto_id or $proto_id->primitive
l!l&&r!l&&!r
11206
MC/DC100%2/2
not defined $proto_id or $proto_id->primitive
not defined $proto_id $proto_id->primitive
Truth table100%3/3
not(A) or B
A= not defined $proto_idB= $proto_id->primitive
ABresult
1X1
011
000
954 JE::Object::Error::TypeError $global,
955 add_line_number "Function $$$func{func_name} has no prototype property";
956 206 $proto_id = $proto_id->id;
957  
958 206 ▶ 0 while (defined($obj = $obj->prototype)
Branch: 2 branches
BranchTrueFalseTotal
defined($obj = $obj->prototype) || (return "JE::Boolean"->new($JE::Code::global, 0)), $obj->id ne $proto_id and do { '???' } 11 204 215
defined($obj = $obj->prototype) or return "JE::Boolean"->new($JE::Code::global, 0) 215 2 217
959 or return new JE::Boolean $global, 0),
960 $obj->id ne $proto_id;
961
962 204 new JE::Boolean $global, 1;
963 101 };
964 101 ▶ *{'inin'} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
965 309 my($prop,$obj) = @_;
966 309 ▶ die new JE::Object::Error::TypeError $global,
Branch: 1 branch
BranchTrueFalseTotal
if $obj->primitive 1 308 309
967 add_line_number "$obj is not an object"
968 if $obj->primitive;
969 308 new JE::Boolean $global, defined $obj->prop($prop);
970 101 };
971 101 ▶ *{'in=='} = sub {
Subroutine __ANON__: called CC=23 SCAR=32.0
972 2720 my($x,$y) = @_;
973 2720 my($xt,$yt) = (typeof $x, typeof $y);
974 2720 my($xi,$yi) = ( id $x, id $y);
975 2720 ▶ $xt eq $yt and return new JE::Boolean $global,
Branch: 1 branch
BranchTrueFalseTotal
$xt eq $yt and return "JE::Boolean"->new($JE::Code::global, $xi eq $yi && $xi ne "num:nan") 2574 146 2720
Condition100%3/3
$xi eq $yi && $xi ne 'num:nan'
!ll&&!rl&&r
5191405650
MC/DC100%2/2
$xi eq $yi && $xi ne 'num:nan'
$xi eq $yi $xi ne 'num:nan'
Truth table100%3/3
A && B
A= $xi eq $yiB= $xi ne 'num:nan'
ABresult
0X0
100
111
976 $xi eq $yi && $xi ne 'num:nan';
977  
978 146 ▶ $xi eq 'null' and
Branch: 1 branch
BranchTrueFalseTotal
$xi eq "null" and return "JE::Boolean"->new($JE::Code::global, $yi eq "undef") 8 138 146
979 return new JE::Boolean $global,
980 $yi eq 'undef';
981 138 ▶ $xi eq 'undef' and
Branch: 1 branch
BranchTrueFalseTotal
$xi eq "undef" and return "JE::Boolean"->new($JE::Code::global, $yi eq "null") 40 98 138
982 return new JE::Boolean $global,
983 $yi eq 'null';
984 98 ▶ $yi eq 'null' and
Branch: 1 branch
BranchTrueFalseTotal
$yi eq "null" and return "JE::Boolean"->new($JE::Code::global, $xi eq "undef") 6 92 98
985 return new JE::Boolean $global,
986 $xi eq 'undef';
987 92 ▶ $yi eq 'undef' and
Branch: 1 branch
BranchTrueFalseTotal
$yi eq "undef" and return "JE::Boolean"->new($JE::Code::global, $xi eq "null") 10 82 92
988 return new JE::Boolean $global,
989 $xi eq 'null';
990  
991 82 ▶ if($xt eq 'boolean') {
Branch: 2 branches
BranchTrueFalseTotal
if ($xt eq 'boolean') { } 12 70 82
elsif ($yt eq 'boolean') { } 8 62 70
992 12 $x = to_number $x;
993 12 $xt = 'number';
994 }
995 elsif($yt eq 'boolean') {
996 8 $y = to_number $y;
997 8 $yt = 'number';
998 }
999  
1000 82 ▶ if($xt eq 'string' || $xt eq 'number' and !primitive $y)
Branch: 2 branches
BranchTrueFalseTotal
if ($xt eq 'string' || $xt eq 'number' and not $y->primitive) { } 12 70 82
elsif ($yt eq 'string' || $yt eq 'number' and not $x->primitive) { } 42 28 70
Condition100%6/6
$xt eq "string" || $xt eq "number" and not $y->primitive
!ll&&!rl&&r
422812
$xt eq "string" or $xt eq "number"
l!l&&r!l&&!r
162442
MC/DC100%3/3
$xt eq "string" || $xt eq "number" and not $y->primitive
$xt eq "string" $xt eq "number" not $y->primitive
Truth table100%5/5
A or B and not(C)
A= $xt eq "string"B= $xt eq "number"C= not $y->primitive
ABCresult
00X0
1X00
0100
1X11
0111
1001 12 { $y = to_primitive $y; $yt = typeof $y }
1002 ▶ elsif
Condition66%4/6
$yt eq "string" || $yt eq "number" and not $x->primitive
!ll&&!rl&&r
02842
$yt eq "string" or $yt eq "number"
l!l&&r!l&&!r
28420
MC/DC33%1/3
$yt eq "string" || $yt eq "number" and not $x->primitive
$yt eq "string" $yt eq "number" not $x->primitive
Truth table80%4/5
A or B and not(C)
A= $yt eq "string"B= $yt eq "number"C= not $x->primitive
ABCresult
00X0
1X00
0100
1X11
0111
1003 ($yt eq 'string' || $yt eq 'number' and !primitive $x)
1004 42 { $x = to_primitive $x; $xt = typeof $x }
1005  
1006 82 ▶ ($xt eq 'number' and $yt eq 'string' || $yt eq 'number')
Branch: 1 branch
BranchTrueFalseTotal
$xt eq "number" && ($yt eq "string" || $yt eq "number") || $yt eq "number" && ($xt eq "string" || $xt eq "number") and return "JE::Boolean"->new($JE::Code::global, $x->to_number->[0] == $y->to_number->[0]) 62 20 82
Condition66%10/15
$xt eq "number" and $yt eq "string" || $yt eq "number" or $yt eq "number" and $xt eq "string" || $xt eq "number"
l!l&&r!l&&!r
441820
$xt eq "number" and $yt eq "string" || $yt eq "number"
!ll&&!rl&&r
38044
$yt eq "string" or $yt eq "number"
l!l&&r!l&&!r
14300
$yt eq "number" and $xt eq "string" || $xt eq "number"
!ll&&!rl&&r
20018
$xt eq "string" or $xt eq "number"
l!l&&r!l&&!r
1800
MC/DC33%2/6
$xt eq "number" and $yt eq "string" || $yt eq "number" or $yt eq "number" and $xt eq "string" || $xt eq "number"
$xt eq "number" $yt eq "string" $yt eq "number" $yt eq "number" $xt eq "string" $xt eq "number"
Truth table40%4/10
A and B or C or D and E or F
A= $xt eq "number"B= $yt eq "string"C= $yt eq "number"D= $yt eq "number"E= $xt eq "string"F= $xt eq "number"
ABCDEFresult
11XXXX1
101XXX1
0XX11X1
0XX1011
10011X1
1001011
0XX0XX0
0XX1000
1000XX0
1001000
1007 ||
1008 ($yt eq 'number' and $xt eq 'string' || $xt eq 'number')
1009 and
1010 return new JE::Boolean $global,
1011 to_number $x->[0] == to_number $y->[0];
1012  
1013 20 ▶ $xt eq 'string' && $yt eq 'string' and
Branch: 1 branch
BranchTrueFalseTotal
$xt eq "string" and $yt eq "string" and return "JE::Boolean"->new($JE::Code::global, $x->value16 eq $y->value16) 20 0 20
Condition33%1/3
$xt eq "string" and $yt eq "string"
!ll&&!rl&&r
0020
MC/DC0%0/2
$xt eq "string" and $yt eq "string"
$xt eq "string" $yt eq "string"
Truth table33%1/3
A and B
A= $xt eq "string"B= $yt eq "string"
ABresult
0X0
100
111
1014 return new JE::Boolean $global,
1015 $x->value16 eq $y->value16;
1016
1017 0 new JE::Boolean $global, 0;
1018 101 };
1019 101 ▶ *{'in!='} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1020 1460 new JE::Boolean $global, !&{'in=='}->[0];
1021 101 };
1022 101 ▶ *{'in==='} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1023 8959 my($x,$y) = @_;
1024 8959 my($xi,$yi) = ( id $x, id $y);
1025 8959 ▶ return new JE::Boolean $global,
Condition100%3/3
$xi eq $yi && $xi ne 'num:nan'
!ll&&!rl&&r
13328824
MC/DC100%2/2
$xi eq $yi && $xi ne 'num:nan'
$xi eq $yi $xi ne 'num:nan'
Truth table100%3/3
A && B
A= $xi eq $yiB= $xi ne 'num:nan'
ABresult
0X0
100
111
1026 $xi eq $yi && $xi ne 'num:nan';
1027 101 };
1028 101 ▶ *{'in!=='} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1029 68 new JE::Boolean $global, !&{'in==='}->[0];
1030 101 };
1031  
1032 # ~~~ These three bitwise operators are slower than molasses. There
1033 # must be some way to speed them up, but I'm not sure the research
1034 # is worth it. Does anyone actually use these in JS?
1035 101 ▶ *{'in&'} = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
1036 899 my $num = shift->to_number->[0];
1037 899 ▶ $num =
Branch: 1 branch
BranchTrueFalseTotal
$num != $num || abs $num == 9**9**9 ? : 108 791 899
Condition100%3/3
$num != $num or abs $num == "Inf"
l!l&&r!l&&!r
5058791
MC/DC100%2/2
$num != $num or abs $num == "Inf"
$num != $num abs $num == "Inf"
Truth table100%3/3
A or B
A= $num != $numB= abs $num == "Inf"
ABresult
1X1
011
000
1038 $num != $num || abs($num) == inf
1039 ? 0
1040 : int($num) % 2**32;
1041 899 ▶ $num -= 2**32 if $num >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num >= "2147483648" 377 522 899
1042  
1043 899 my $num2 = shift->to_number->[0];
1044 899 ▶ $num2 =
Branch: 1 branch
BranchTrueFalseTotal
$num2 != $num2 || abs $num2 == 9**9**9 ? : 108 791 899
Condition100%3/3
$num2 != $num2 or abs $num2 == "Inf"
l!l&&r!l&&!r
5058791
MC/DC100%2/2
$num2 != $num2 or abs $num2 == "Inf"
$num2 != $num2 abs $num2 == "Inf"
Truth table100%3/3
A or B
A= $num2 != $num2B= abs $num2 == "Inf"
ABresult
1X1
011
000
1045 $num2 != $num2 || abs($num2) == inf
1046 ? 0
1047 : int($num2) % 2**32;
1048 899 ▶ $num2 -= 2**32 if $num2 >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num2 >= "2147483648" 377 522 899
1049  
1050 101 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
1051 899 new JE::Number $global,
1052 $num & $num2;
1053 101 };
1054 101 ▶ *{'in^'} = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
1055 899 my $num = shift->to_number->[0];
1056 899 ▶ $num =
Branch: 1 branch
BranchTrueFalseTotal
$num != $num || abs $num == 9**9**9 ? : 108 791 899
Condition100%3/3
$num != $num or abs $num == "Inf"
l!l&&r!l&&!r
5058791
MC/DC100%2/2
$num != $num or abs $num == "Inf"
$num != $num abs $num == "Inf"
Truth table100%3/3
A or B
A= $num != $numB= abs $num == "Inf"
ABresult
1X1
011
000
1057 $num != $num || abs($num) == inf
1058 ? 0
1059 : int($num) % 2**32;
1060 899 ▶ $num -= 2**32 if $num >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num >= "2147483648" 377 522 899
1061  
1062 899 my $num2 = shift->to_number->[0];
1063 899 ▶ $num2 =
Branch: 1 branch
BranchTrueFalseTotal
$num2 != $num2 || abs $num2 == 9**9**9 ? : 108 791 899
Condition100%3/3
$num2 != $num2 or abs $num2 == "Inf"
l!l&&r!l&&!r
5058791
MC/DC100%2/2
$num2 != $num2 or abs $num2 == "Inf"
$num2 != $num2 abs $num2 == "Inf"
Truth table100%3/3
A or B
A= $num2 != $num2B= abs $num2 == "Inf"
ABresult
1X1
011
000
1064 $num2 != $num2 || abs($num2) == inf
1065 ? 0
1066 : int($num2) % 2**32;
1067 899 ▶ $num2 -= 2**32 if $num2 >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num2 >= "2147483648" 377 522 899
1068  
1069 101 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
1070 899 new JE::Number $global,
1071 $num ^ $num2;
1072 101 };
1073 101 ▶ *{'in|'} = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
1074 900 my $num = shift->to_number->[0];
1075 900 ▶ $num =
Branch: 1 branch
BranchTrueFalseTotal
$num != $num || abs $num == 9**9**9 ? : 108 792 900
Condition100%3/3
$num != $num or abs $num == "Inf"
l!l&&r!l&&!r
5058792
MC/DC100%2/2
$num != $num or abs $num == "Inf"
$num != $num abs $num == "Inf"
Truth table100%3/3
A or B
A= $num != $numB= abs $num == "Inf"
ABresult
1X1
011
000
1076 $num != $num || abs($num) == inf
1077 ? 0
1078 : int($num) % 2**32;
1079 900 ▶ $num -= 2**32 if $num >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num >= "2147483648" 377 523 900
1080  
1081 900 my $num2 = shift->to_number->[0];
1082 900 ▶ $num2 =
Branch: 1 branch
BranchTrueFalseTotal
$num2 != $num2 || abs $num2 == 9**9**9 ? : 108 792 900
Condition100%3/3
$num2 != $num2 or abs $num2 == "Inf"
l!l&&r!l&&!r
5058792
MC/DC100%2/2
$num2 != $num2 or abs $num2 == "Inf"
$num2 != $num2 abs $num2 == "Inf"
Truth table100%3/3
A or B
A= $num2 != $num2B= abs $num2 == "Inf"
ABresult
1X1
011
000
1083 $num2 != $num2 || abs($num2) == inf
1084 ? 0
1085 : int($num2) % 2**32;
1086 900 ▶ $num2 -= 2**32 if $num2 >= 2**31;
Branch: 1 branch
BranchTrueFalseTotal
if $num2 >= "2147483648" 377 523 900
1087  
1088 101 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
1089 900 new JE::Number $global,
1090 $num | $num2;
1091 101 };
1092 }
1093  
1094 =begin for-me
1095  
1096 Types of expressions:
1097  
1098 'new' term args?
1099  
1100 'member/call' term ( subscript | args) *
1101  
1102 'postfix' term op
1103  
1104 'hash' term*
1105  
1106 'array' term? (comma term?)*
1107  
1108 'prefix' op+ term
1109  
1110 'lassoc' term (op term)*
1111  
1112 'assign' term (op term)* (term term)?
1113 (the last two terms are the 2nd and 3rd terms of ? :
1114  
1115 'expr' term*
1116 (commas are omitted from the array)
1117  
1118 'function' ident? params statements
1119  
1120 =end for-me
1121  
1122 =cut
1123  
1124  
1125 # Note: each expression object is an array ref. The elems are:
1126 # [0] - an array ref containing
1127 # [0] - the starting position in the source code and
1128 # [1] - the ending position
1129 # [1] - the type of expression
1130 # [2..$#] - the various terms/tokens that make up the expr
1131  
1132 193988 ▶sub eval { # evalate (sub)expression
Subroutine eval: called CC=59 SCAR=40.8
1133 101 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
1134 193988 ▶ ++ $ops>$counting and last JE_Code_OP if $counting;
Branch: 1 branch
BranchTrueFalseTotal
if $JE::Code::counting 113 193875 193988
Condition80%4/5
$JE::Code::counting && (++$JE::Code::ops > $JE::Code::counting && (last JE_Code_OP))
!ll
1938751130
++$JE::Code::ops > $JE::Code::counting and last JE_Code_OP
!ll
1121
MC/DC0%0/2
$JE::Code::counting && (++$JE::Code::ops > $JE::Code::counting && (last JE_Code_OP))
$JE::Code::counting ++$JE::Code::ops > $JE::Code::counting
Truth table66%2/3
A && B
A= $JE::Code::countingB= ++$JE::Code::ops > $JE::Code::counting
ABresult
0X0
100
111
1135
1136 193987 my $expr = shift;
1137  
1138 193987 my $type = $$expr[1];
1139 193987 my @labels;
1140  
1141 193987 $pos = $$expr[0][0];
1142  
1143 193987 ▶ if ($type eq 'expr') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "expr") 72551 121436 193987
1144 72551 my $result;
1145 72551 ▶ if(@$expr == 3) { # no comma
Branch: 1 branch
BranchTrueFalseTotal
if (@$expr == 3) { } 72161 390 72551
1146 72161 return _eval_term $$expr[-1];
1147 }
1148 else { # comma op
1149 390 for (@$expr[2..$#$expr-1]) {
1150 1352 $result = _eval_term $_ ;
1151 1352 ▶ get $result if ref $result eq 'JE::LValue';
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "JE::LValue" 37 1315 1352
1152 }
1153 390 $result = _eval_term $$expr[-1] ;
1154 390 ▶ return ref $result eq 'JE::LValue' ? get $result
Branch: 1 branch
BranchTrueFalseTotal
ref $result eq 'JE::LValue' ? : 114 276 390
1155 : $result;
1156 }
1157 }
1158 121436 ▶ if ($type eq 'assign') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "assign") 7399 114037 121436
1159 7399 my @copy = \(@$expr[2..$#$expr]);
1160 # Evaluation is done left-first in JS, unlike in
1161 # Perl, so a = b = c is evaluated in this order:
1162 # - evaluate a
1163 # - evaluate b
1164 # - evaluate c
1165 # - assign c to b
1166 # - assign b to a
1167  
1168 # Check first to see whether we have the terms
1169 # of a ? : at the end:
1170 my @qc_terms = @copy >= 3 && (
1171 7399 ref ${$copy[-2]} # avoid stringification
1172 7399 ▶ || ${$copy[-2]} =~ /^(?:[tfu]|[si0-9])/
Branch: 1 branch
BranchTrueFalseTotal
@copy >= 3 && (ref ${$copy[-2];} || ${$copy[-2];} =~ /^(?:[tfu]|[si0-9])/) ? : 561 6838 7399
Condition83%5/6
@copy >= 3 and ref ${$copy[-2];} || ${$copy[-2];} =~ /^(?:[tfu]|[si0-9])/
!ll&&!rl&&r
06838561
ref ${$copy[-2];} or ${$copy[-2];} =~ /^(?:[tfu]|[si0-9])/
l!l&&r!l&&!r
2772846838
MC/DC66%2/3
@copy >= 3 and ref ${$copy[-2];} || ${$copy[-2];} =~ /^(?:[tfu]|[si0-9])/
@copy >= 3 ref ${$copy[-2];} ${$copy[-2];} =~ /^(?:[tfu]|[si0-9])/
Truth table75%3/4
A and B or C
A= @copy >= 3B= ref ${$copy[-2];}C= ${$copy[-2];} =~ /^(?:[tfu]|[si0-9])/
ABCresult
0XX0
1000
11X1
1011
1173 )
1174 ? (pop @copy, pop @copy) : ();
1175 # @qc_terms is now in reverse order
1176  
1177 # Make a list of operands, evalling each
1178 7399 my @terms = _eval_term ${shift @copy};
1179 7399 my @ops;
1180 7399 ▶ while(@copy) {
Branch: 1 branch
BranchTrueFalseTotal
if (@copy) 6861 7398 14259
1181 6861 push @ops, ${shift @copy};
1182 6861 push @terms, _eval_term ${shift @copy};
1183 }
1184  
1185 7398 my $val = pop @terms;
1186  
1187 # Now apply ? : if it's there
1188 @qc_terms and $val = _eval_term
1189 7398 ▶ ${$qc_terms[$val->to_boolean->[0]]};
Branch: 1 branch
BranchTrueFalseTotal
@qc_terms and $val = _eval_term(${$qc_terms[$val->to_boolean->[0]];}) 561 6837 7398
1190  
1191 7398 for (reverse @ops) {
1192 101 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1193 length > 1 and $val =
1194 6860 ▶ &{'in'.substr $_,0,-1}(
Branch: 1 branch
BranchTrueFalseTotal
length $_ > 1 and $val = &{'in' . substr($_, 0, -1);}($terms[-1], $val) 153 6707 6860
1195 $terms[-1], $val
1196 );
1197 6860 ▶ $val = $val->get if ref $val eq 'JE::LValue';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "JE::LValue" 5268 1592 6860
1198 6860 ▶ T and tainted $taint and $val->can('taint')
Branch: 1 branch
BranchTrueFalseTotal
&tainted($JE::Code::taint) and $val->can("taint") and $val = $val->taint($JE::Code::taint) 0 6860 6860
Condition33%1/3
&tainted($JE::Code::taint) and $val->can("taint")
!ll&&!rl&&r
686000
MC/DC0%0/2
&tainted($JE::Code::taint) and $val->can("taint")
&tainted($JE::Code::taint) $val->can("taint")
Truth table33%1/3
A and B
A= &tainted($JE::Code::taint)B= $val->can("taint")
ABresult
0X0
100
111
1199 and $val = taint $val $taint;
1200 6860 eval { (pop @terms)->set($val) };
1201 6860 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 1 6859 6860
1202 1 ▶ die $err if UNIVERSAL::isa($err, 'JE::Object::Error');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($err, "JE::Object::Error") 0 1 1
1203 1 die new JE::Object::Error::ReferenceError
1204 $global, add_line_number "Cannot assign to a non-lvalue";
1205 }
1206 # ~~~ This needs to check whether it was an error
1207 # other than 'Can't locate object method "set"
1208 # since store handlers can thrown other errors.
1209
1210 }
1211 7397 ▶ if(!@ops) { # If we only have ? : and no assignment
Branch: 1 branch
BranchTrueFalseTotal
unless (@ops) 553 6844 7397
1212 553 ▶ $val = $val->get if ref $val eq 'JE::LValue';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "JE::LValue" 35 520 555
1213 }
1214 7397 return $val;
1215 }
1216 114037 ▶ if($type eq 'lassoc') { # left-associative
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "lassoc") 32056 81979 114035
1217 32056 my @copy = \(@$expr[2..$#$expr]);
1218 32056 my $result = _eval_term ${shift @copy};
1219 32056 ▶ while(@copy) {
Branch: 1 branch
BranchTrueFalseTotal
if (@copy) 41211 32047 73258
1220 101 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1221 # We have to deal with || && here for the sake of
1222 # short-circuiting
1223 41211 my $op = ${$copy[0]};
1224 41211 ▶ if ($op eq '&&') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '&&') { } 485 40726 41211
elsif ($op eq '||') { } 95 40631 40726
1225 485 ▶ $result = _eval_term(${$copy[1]}) if
Branch: 1 branch
BranchTrueFalseTotal
if $result->to_boolean->[0] 458 27 485
1226 $result->to_boolean->[0];
1227 485 ▶ $result = $result->get
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "JE::LValue" 13 472 485
1228 if ref $result eq 'JE::LValue';
1229 }
1230 elsif($op eq '||') {
1231 95 ▶ $result = _eval_term(${$copy[1]}) unless
Branch: 1 branch
BranchTrueFalseTotal
unless $result->to_boolean->[0] 25 70 95
1232 $result->to_boolean->[0];
1233 95 ▶ $result = $result->get
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "JE::LValue" 44 51 95
1234 if ref $result eq 'JE::LValue';
1235 }
1236 else {
1237 40631 ▶ $result = $result->get
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "JE::LValue" 16777 23856 40633
1238 if ref $result eq 'JE::LValue';
1239 40630 $result = &{"in$op"}(
1240 40630 $result, _eval_term ${$copy[1]}
1241 );
1242 }
1243 41202 splice @copy, 0, 2; # double shift
1244 }
1245 32047 return $result;
1246 }
1247 81981 ▶ if ($type eq 'prefix') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "prefix") 12009 69972 81981
1248 # $$expr[1] -- 'prefix'
1249 # @$expr[2..-2] -- prefix ops
1250 # $$expr[-1] -- operand
1251 12009 my $term = _eval_term $$expr[-1];
1252  
1253 101 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1254 12009 $term = &{"pre$_"}($term) for reverse @$expr[2..@$expr-2];
1255 11999 return $term;
1256 }
1257 69972 ▶ if ($type eq 'postfix') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "postfix") 129 69843 69972
1258 # ~~~ These are supposed to use the same rules
1259 # as the + and - infix ops for the actual
1260 # addition part. Verify that they do this.
1261  
1262 129 my $ret = (my $term = _eval_term $$expr[2])
1263 ->to_number;
1264 129 $term->set(new JE::Number $global,
1265 $ret->value + (-1,1)[$$expr[3] eq '++']);
1266 129 return $ret;
1267 }
1268 69843 ▶ if ($type eq 'new') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "new") 1120 68721 69841
1269 1120 ▶ return _eval_term($$expr[2])->construct(
Branch: 3 branches
BranchTrueFalseTotal
@$expr == 4 ? : 950 172 1122
&tainted($JE::Code::taint) ? : 2 950 952
$_->can('taint') ? : 0 2 2
1270 @$expr == 4
1271 ? T && tainted $taint
1272 ? map $_->can('taint') ?taint $_ $taint:$_,
1273 $$expr[-1]->list
1274 : $$expr[-1]->list
1275 : ()
1276 );
1277 }
1278 68723 ▶ if($type eq 'member/call') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "member/call") 62830 5891 68721
1279 62832 my $obj = _eval_term $$expr[2];
1280 62832 for (@$expr[3..$#$expr]) {
1281 69147 ▶ if(ref eq 'JE::Code::Subscript') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'JE::Code::Subscript') { } 46975 22168 69143
1282 46977 ▶ $obj = get $obj
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj eq "JE::LValue" 45630 1345 46975
1283 if ref $obj eq 'JE::LValue';
1284 46977 $obj = new JE::LValue $obj, $_->str_val;
1285 }
1286 else {
1287 22170 ▶ $obj = $obj->call(
Branch: 2 branches
BranchTrueFalseTotal
&tainted($JE::Code::taint) ? : 0 22168 22168
$_->can('taint') ? : 0 0 0
1288 T && tainted $taint
1289 ? map $_->can('taint')
1290 ? taint $_ $taint
1291 : $_,
1292 $_->list
1293 : $_->list
1294 );
1295 # If $obj is an lvalue,
1296 # JE::LValue::call will make
1297 # the lvalue's base object the 'this'
1298 # value. Otherwise,
1299 # JE::Object::Function::call
1300 # will make the
1301 # global object the 'this' value.
1302 }
1303 # ~~~ need some error-checking
1304 }
1305 62666 return $obj; # which may be an lvalue
1306 }
1307 5891 ▶ if($type eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "array") 5260 631 5891
1308 5260 my @ary;
1309 5260 for (2..$#$expr) {
1310 36225 ▶ if(ref $$expr[$_] eq 'comma') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expr->[$_] eq 'comma') { } 15614 20611 36225
1311 15614 ▶ ref $$expr[$_-1] eq 'comma' || $_ == 2
Branch: 1 branch
BranchTrueFalseTotal
ref $$expr[$_ - 1] eq "comma" || $_ == 2 and ++$#ary 134 15480 15614
Condition100%3/3
ref $$expr[$_ - 1] eq "comma" or $_ == 2
l!l&&r!l&&!r
973715480
MC/DC100%2/2
ref $$expr[$_ - 1] eq "comma" or $_ == 2
ref $$expr[$_ - 1] eq "comma" $_ == 2
Truth table100%3/3
A or B
A= ref $$expr[$_ - 1] eq "comma"B= $_ == 2
ABresult
1X1
011
000
1312 and ++$#ary
1313 }
1314 else {
1315 20611 push @ary, _eval_term $$expr[$_];
1316 20611 ▶ $ary[-1] = $ary[-1]->get
Branch: 1 branch
BranchTrueFalseTotal
if ref $ary[-1] eq "JE::LValue" 714 19897 20611
1317 if ref $ary[-1] eq 'JE::LValue';
1318 }
1319 }
1320  
1321 5259 my $ary = new JE::Object::Array $global;
1322 5259 $$$ary{array} = \@ary; # sticking it in like this
1323 # makes 'undef' elements non-
1324 # existent, rather
1325 # than undefined
1326 5259 return $ary;
1327 }
1328 631 ▶ if($type eq 'hash') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "hash") 462 169 631
1329 462 my $obj = new JE::Object $global;
1330 462 local @_ = \(@$expr[2..$#$expr]);
1331 462 my (@keys, $key, $value);
1332 462 ▶ while(@_) { # I have to loop through them to keep
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 92 462 554
1333 # the order.
1334 92 $key = ${+shift};
1335 92 $value = _eval_term ${shift;};
1336 92 ▶ $value = get $value if ref $value eq 'JE::LValue';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "JE::LValue" 24 68 92
1337 92 $obj->prop($key, $value);
1338 }
1339 462 return $obj;
1340 }
1341 169 ▶ if ($type eq 'func') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "func") 169 0 169
1342 # format: [[...], function=> 'name',
1343 # [ params ], $statements_obj, \@vars]
1344 # or: [[...], function =>
1345 # [ params ], $statements_obj, \@vars]
1346 169 ▶ my($name,$params,$statements) = ref $$expr[2] ?
Branch: 1 branch
BranchTrueFalseTotal
ref $expr->[2] ? : 162 7 169
1347 (undef, @$expr[2,3]) : @$expr[2..4];
1348 169 ▶ my $func_scope = $name
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 7 162 169
1349 ? bless([@$scope, my $obj=new JE::Object $global],
1350 'JE::Scope')
1351 : $scope;
1352 (my $new_code_obj = bless {
1353 map+($_=>$code->{$_}),qw/global source file line/
1354 }, 'JE::Code')
1355 169 ->{tree} = $statements;
1356 169 $new_code_obj->{vars} = $$expr[-1];
1357 169 ▶ my $f = new JE::Object::Function {
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 7 162 169
1358 scope => $func_scope,
1359 defined $name ? (name => $name) : (),
1360 argnames => $params,
1361 function => $new_code_obj,
1362 };
1363 169 ▶ if($name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 7 162 169
1364 7 $obj->prop({
1365 name => $name,
1366 value => $f,
1367 readonly => 1,
1368 dontdel => 1,
1369 });
1370 }
1371 169 return $f;
1372 }
1373 }
1374 299771 ▶sub _eval_term {
Subroutine _eval_term: called CC=10 SCAR=23.7
1375 299771 my $term = $_[0];
1376  
1377 299771 ▶ return $term->eval if ref $term eq 'JE::Code::Expression';
Branch: 1 branch
BranchTrueFalseTotal
if ref $term eq "JE::Code::Expression" 125320 174451 299771
1378  
1379 174451 ▶ ref $term ? ref $term eq 'ARRAY'
Branch: 8 branches
BranchTrueFalseTotal
ref $term ? : 46726 127725 174451
ref $term eq 'ARRAY' ? : 0 46726 46726
$term eq 'this' ? : 423 127302 127725
$term =~ /^s/ ? : 7715 119587 127302
$term =~ /^i/ ? : 99406 20181 119587
$term eq 't' ? : 0 20181 20181
$term eq 'f' ? : 0 20181 20181
$term eq 'n' ? : 0 20181 20181
1380 ? ( require JE::Object::RegExp,
1381 return JE::Object::RegExp->new(
1382 $global, @$term
1383 ) )
1384 : $term :
1385 $term eq'this'? $this :
1386 $term =~ /^s/ ? $_[0] = JE::String->_new($global,substr $term,1) :
1387 $term =~ /^i/ ? $scope->find_var(substr $term,1) :
1388 $term eq 't' ? $global->true :
1389 $term eq 'f' ? $global->false :
1390 $term eq 'n' ? $global->null :
1391 ($_[0] = JE::Number->new($global,$term));
1392 }
1393  
1394  
1395  
1396  
1397 package JE::Code::Subscript;
1398  
1399 101 our $VERSION = '0.066';
1400  
1401 46977 ▶sub str_val {
Subroutine str_val: called CC=2 SCAR=6.9
1402 46977 my $val = (my $self = shift)->[1];
1403 46977 ▶ ref $val ? ''.$val->eval : $val;
Branch: 1 branch
BranchTrueFalseTotal
ref $val ? : 40919 6058 46977
1404 }
1405  
1406  
1407  
1408  
1409 package JE::Code::Arguments;
1410  
1411 101 our $VERSION = '0.066';
1412  
1413 23118 ▶sub list {
Subroutine list: called CC=3 SCAR=11.0
1414 23118 my $self = shift;
1415  
1416 # I can't use map here, because this method is called from within
1417 # a foreach loop, and an exception might be thrown from within
1418 # _eval_term, which has strange effects in perl 5.8.x (see perl
1419 # bug #24254).
1420  
1421 23118 if(1) {
1422 23118 my @result;
1423 23118 for(@$self[1..$#$self]) {
1424 40657 my $val = JE::Code::Expression::_eval_term($_);
1425 40654 ▶ push @result, ref $val eq 'JE::LValue' ? $val->get : $val
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'JE::LValue' ? : 5486 35168 40654
1426 }
1427 23115 @result;
1428  
1429 }else{ # original code
1430 map { my $val = JE::Code::Expression::_eval_term($_);
1431 ref $val eq 'JE::LValue' ? $val->get : $val }
1432 @$self[1..$#$self];
1433 }
1434 }
1435  
1436  
1437  
1438  
1439 101 1;
1440 __END__
« JE/Object/RegExp.pm ↑ Summary JE/Object/Math.pm »