lib/BarefootJS/Evaluator.pm

filter: Statementstmt 85.2% 427 / 501 Branchbran 72.0% 307 / 426 Conditioncond 56.3% 116 / 206 MC/DCmcdc 32.4% 37 / 114 Subroutinesub 92.5% 62 / 67 Podpod 0.0% 0 / 20 totaltotal 71.1% 949 / 1334 CC 334 SCAR 35.8
CC
334
Cov
75%
_radix_to_number
182.0
evaluate
132.7
_call_builtin
58.5
CRAP 36.0
« lib/BarefootJS.pm ↑ Summary blib/lib/BarefootJS/DevReload.pm »
1 package BarefootJS::Evaluator;
2 18 our $VERSION = "0.41.3";
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use Scalar::Util qw(looks_like_number refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use BarefootJS::Undefined ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # JS `undefined` (BarefootJS/Undefined.pm). Perl's `undef` is JS `null`.
16 18 my $UNDEF = $BarefootJS::Undefined::UNDEF;
17 688 ▶sub _is_undef { BarefootJS::Undefined::is_undefined($_[0]) }
Subroutine _is_undef: called CC=1 SCAR=0.0
18 208 ▶sub _is_nullish { BarefootJS::Undefined::is_nullish($_[0]) }
Subroutine _is_nullish: called CC=1 SCAR=0.0
19  
20 # Lightweight evaluator for the pure `ParsedExpr` subset, scoped to
21 # higher-order callback bodies (reduce / sort / map / filter / find
22 # `(…) => expr`) — issue #2018. Templates cannot carry a lambda in
23 # expression position, which is why the adapters historically special-cased
24 # these callbacks into fixed shapes (bf_sort's comparator catalogue,
25 # bf_reduce's +/* fold). Instead, the callback BODY rides as a pure
26 # `ParsedExpr` subtree (the structured IR the compiler already produces) and
27 # is evaluated here against an environment (`{acc, item, …captured free
28 # vars}`).
29 #
30 # ONE shared implementation for both Perl backends (Mojo + Xslate), living
31 # alongside SearchParams.pm in the engine-agnostic core (no CPAN deps beyond
32 # core B / POSIX / Scalar::Util). The accepted subset and its semantics are
33 # documented in spec/compiler.md ("ParsedExpr Evaluator Semantics") and pinned
34 # isomorphically by the cross-language golden vectors
35 # (packages/adapter-tests/helper-vectors/eval-vectors.json), shared with the Go
36 # evaluator (bf.go) — same input → same output.
37 #
38 # The coercion below is JS-faithful (ToNumber / ToString / ToBoolean, strict
39 # equality) and deliberately distinct from the divergent bf->string / number
40 # helpers in BarefootJS.pm, so the contract is unambiguous and the two
41 # template adapters stay byte-equal with each other and with Go.
42 #
43 # JS `undefined` is `$BarefootJS::UNDEF` and Perl's `undef` is JS `null`. A
44 # missing field, an out-of-range or non-canonical index, the unbound
45 # `undefined` identifier, an omitted builtin argument and a `find` with no
46 # result read as `UNDEF` (spec/js-undefined-value.md, section 2).
47  
48 # evaluate($node, $env)
49 #
50 # Evaluate a decoded ParsedExpr node (a hashref keyed by `kind`) against the
51 # environment hashref ($env), returning a Perl value (number, string,
52 # JSON::PP::Boolean, undef for null, `UNDEF` for undefined, arrayref,
53 # hashref). The matching JSON entry point is eval_json() below.
54 541 ▶sub evaluate ($node, $env) {
Subroutine evaluate: called CC=56 SCAR=48.9
Pod undocumented
55 541 ▶ return undef unless ref $node eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" 0 541 541
56 541 ▶ my $kind = $node->{kind} // '';
Condition50%1/2
$node->{"kind"} // ""
l!l
5410
MC/DC0%0/1
$node->{"kind"} // ""
$node->{"kind"}
Truth table50%1/2
A
A= $node->{"kind"}
Aresult
11
00
57  
58 541 ▶ if ($kind eq 'literal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "literal") 68 473 541
59 68 return $node->{value};
60 }
61 473 ▶ if ($kind eq 'identifier') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "identifier") 211 262 473
62 211 my $name = $node->{name};
63 # The unshadowed `undefined` identifier is the constant.
64 211 ▶ return $UNDEF if $name eq 'undefined' && !exists $env->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "undefined" and not exists $env->{$name} 1 210 211
Condition100%3/3
$name eq "undefined" and not exists $env->{$name}
!ll&&!rl&&r
20911
MC/DC100%2/2
$name eq "undefined" and not exists $env->{$name}
$name eq "undefined" not exists $env->{$name}
Truth table100%3/3
A and not(B)
A= $name eq "undefined"B= not exists $env->{$name}
ABresult
0X0
100
111
65 210 return $env->{$name};
66 }
67 262 ▶ if ($kind eq 'binary') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "binary") 104 158 262
68 return _binary($node->{op},
69 104 evaluate($node->{left}, $env), evaluate($node->{right}, $env));
70 }
71 158 ▶ if ($kind eq 'unary') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "unary") 1 157 158
72 1 return _unary($node->{op}, evaluate($node->{argument}, $env));
73 }
74 157 ▶ if ($kind eq 'logical') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "logical") 3 154 157
75 3 my $op = $node->{op};
76 3 my $left = evaluate($node->{left}, $env);
77 3 ▶ if ($op eq '&&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "&&") 0 3 3
78 0 ▶ return _truthy($left) ? evaluate($node->{right}, $env) : $left;
Branch: 1 branch
BranchTrueFalseTotal
_truthy($left) ? : 0 0 0
79 }
80 3 ▶ if ($op eq '||') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "||") 0 3 3
81 0 ▶ return _truthy($left) ? $left : evaluate($node->{right}, $env);
Branch: 1 branch
BranchTrueFalseTotal
_truthy($left) ? : 0 0 0
82 }
83 # `??` coalesces both nils.
84 3 ▶ return _is_nullish($left) ? evaluate($node->{right}, $env) : $left;
Branch: 1 branch
BranchTrueFalseTotal
_is_nullish($left) ? : 2 1 3
85 }
86 154 ▶ if ($kind eq 'conditional') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "conditional") 0 154 154
87 return _truthy(evaluate($node->{test}, $env))
88 ? evaluate($node->{consequent}, $env)
89 0 ▶ : evaluate($node->{alternate}, $env);
Branch: 1 branch
BranchTrueFalseTotal
_truthy(evaluate($node->{'test'}, $env)) ? : 0 0 0
90 }
91 154 ▶ if ($kind eq 'member') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "member") 110 44 154
92 110 return _read_property(evaluate($node->{object}, $env), $node->{property});
93 }
94 44 ▶ if ($kind eq 'index-access') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "index-access") 14 30 44
95 14 return _read_index(evaluate($node->{object}, $env), evaluate($node->{index}, $env));
96 }
97 30 ▶ if ($kind eq 'call') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "call") 14 16 30
98 # Nested `.map(cb)` / `.filter(cb)` (#2094) — e.g. a `.flatMap(p =>
99 # p.tags.map(t => '#'+t))` projection body that itself contains a
100 # `.map`/`.filter` call. Checked BEFORE builtin-name resolution
101 # (the callee is a `member` node, never a bare/dotted builtin
102 # identifier, so the two can't collide). Mirrors Go's
103 # evalArrayCallbackCall / evalArrayCallback.
104 14 my ($method, $object_node, $arrow_node) = _array_callback_call($node);
105 14 ▶ if (defined $method) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $method) 5 9 14
106 5 return _array_callback($method, $object_node, $arrow_node, $env);
107 }
108 9 my $name = _builtin_name($node->{callee});
109 9 ▶ return undef unless defined $name && $name ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name ne "" 0 9 9
Condition33%1/3
defined $name and $name ne ""
!ll&&!rl&&r
009
MC/DC0%0/2
defined $name and $name ne ""
defined $name $name ne ""
Truth table33%1/3
A and B
A= defined $nameB= $name ne ""
ABresult
0X0
100
111
110 9 ▶ my @args = map { evaluate($_, $env) } @{ $node->{args} // [] };
Condition50%1/2
$node->{"args"} // []
l!l
90
MC/DC0%0/1
$node->{"args"} // []
$node->{"args"}
Truth table50%1/2
A
A= $node->{"args"}
Aresult
11
00
111 9 return _call_builtin($name, \@args);
112 }
113 16 ▶ if ($kind eq 'template-literal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "template-literal") 2 14 16
114 2 my $out = '';
115 2 ▶ for my $p (@{ $node->{parts} // [] }) {
Condition50%1/2
$node->{"parts"} // []
l!l
20
MC/DC0%0/1
$node->{"parts"} // []
$node->{"parts"}
Truth table50%1/2
A
A= $node->{"parts"}
Aresult
11
00
116 4 ▶ if (($p->{type} // '') eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if (($p->{'type'} // '') eq 'string') { } 2 2 4
Condition50%1/2
$p->{"type"} // ""
l!l
40
MC/DC0%0/1
$p->{"type"} // ""
$p->{"type"}
Truth table50%1/2
A
A= $p->{"type"}
Aresult
11
00
117 2 ▶ $out .= $p->{value} // '';
Condition50%1/2
$p->{"value"} // ""
l!l
20
MC/DC0%0/1
$p->{"value"} // ""
$p->{"value"}
Truth table50%1/2
A
A= $p->{"value"}
Aresult
11
00
118 }
119 else {
120 2 $out .= _to_string(evaluate($p->{expr}, $env));
121 }
122 }
123 2 return $out;
124 }
125 14 ▶ if ($kind eq 'array-literal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "array-literal") 2 12 14
126 2 ▶ return [ map { evaluate($_, $env) } @{ $node->{elements} // [] } ];
Condition50%1/2
$node->{"elements"} // []
l!l
20
MC/DC0%0/1
$node->{"elements"} // []
$node->{"elements"}
Truth table50%1/2
A
A= $node->{"elements"}
Aresult
11
00
127 }
128 12 ▶ if ($kind eq 'object-literal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "object-literal") 0 12 12
129 # Each entry carries its own `kind` ('prop' | 'spread', #2696 Step 2)
130 # — the SAME encoding the Go evaluator (eval.go) and the raw
131 # ParsedExpr shape the eval-vectors.json golden corpus carry, so
132 # this one decoder serves both a compiled `*_eval` payload and the
133 # golden-vector JSON directly. A 'spread' evaluates its `expr` and
134 # shallow-merges the result's own keys (a non-hashref result —
135 # including a null/undefined JS spread source — is a no-op); a
136 # 'prop' sets one key. Later entries win on a shared key, in source
137 # order, matching JS object-spread exactly.
138 0 my %out;
139 0 ▶ for my $prop (@{ $node->{properties} // [] }) {
Condition0%0/2
$node->{"properties"} // []
l!l
00
MC/DC0%0/1
$node->{"properties"} // []
$node->{"properties"}
Truth table0%0/2
A
A= $node->{"properties"}
Aresult
11
00
140 0 ▶ if (($prop->{kind} // '') eq 'spread') {
Branch: 1 branch
BranchTrueFalseTotal
if (($prop->{"kind"} // "") eq "spread") 0 0 0
Condition0%0/2
$prop->{"kind"} // ""
l!l
00
MC/DC0%0/1
$prop->{"kind"} // ""
$prop->{"kind"}
Truth table0%0/2
A
A= $prop->{"kind"}
Aresult
11
00
141 0 my $spread = evaluate($prop->{expr}, $env);
142 0 ▶ if (ref $spread eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spread eq "HASH") 0 0 0
143 0 $out{$_} = $spread->{$_} for keys %$spread;
144 }
145 0 next;
146 }
147 0 $out{ $prop->{key} } = evaluate($prop->{value}, $env);
148 }
149 0 return \%out;
150 }
151 12 ▶ if ($kind eq 'array-method' && ($node->{method} // '') eq 'includes'
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "array-method" and ($node->{"method"} // "") eq "includes" and @{$node->{"args"} // [];} == 1) 8 4 12
Condition62%5/8
$kind eq "array-method" and ($node->{"method"} // "") eq "includes" and @{$node->{"args"} // [];} == 1
!ll&&!rl&&r
408
$kind eq "array-method" and ($node->{"method"} // "") eq "includes"
!ll&&!rl&&r
048
$node->{"method"} // ""
l!l
120
MC/DC0%0/3
$kind eq "array-method" and ($node->{"method"} // "") eq "includes" and @{$node->{"args"} // [];} == 1
$kind eq "array-method" $node->{"method"} @{$node->{"args"} // [];} == 1
Truth table25%1/4
A and B and C
A= $kind eq "array-method"B= $node->{"method"}C= @{$node->{"args"} // [];} == 1
ABCresult
0XX0
10X0
1100
1111
152 8 ▶ && @{ $node->{args} // [] } == 1)
Condition50%1/2
$node->{"args"} // []
l!l
80
MC/DC0%0/1
$node->{"args"} // []
$node->{"args"}
Truth table50%1/2
A
A= $node->{"args"}
Aresult
11
00
153 {
154 # `.includes(x)` (#2075) — the one `array-method` in the evaluator
155 # subset, shared between `Array.prototype.includes` (SameValueZero
156 # membership) and `String.prototype.includes` (substring search),
157 # matching the receiver-type dispatch the SSR template lowering does
158 # at runtime (`bf_includes` / `$bf->includes`). Mirrors the JS
159 # reference's `includes()` (eval-reference.ts).
160 8 my $obj = evaluate($node->{object}, $env);
161 8 my $needle = evaluate($node->{args}[0], $env);
162 8 ▶ if (ref $obj eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq "ARRAY") 5 3 8
163 5 for my $el (@$obj) {
164 10 ▶ return _bool(1) if _same_value_zero($el, $needle);
Branch: 1 branch
BranchTrueFalseTotal
if _same_value_zero($el, $needle) 3 7 10
165 }
166 2 return _bool(0);
167 }
168 3 ▶ if (_is_string($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_string($obj)) 1 2 3
169 1 return _bool(index($obj, _to_string($needle)) != -1);
170 }
171 # Any other receiver is not a JS `.includes` target — degrade to
172 # false rather than throwing, mirroring the reference.
173 2 return _bool(0);
174 }
175 4 ▶ if ($kind eq 'array-method' && ($node->{method} // '') eq 'join'
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "array-method" and ($node->{"method"} // "") eq "join" and @{$node->{"args"} // [];} <= 1) 4 0 4
Condition37%3/8
$kind eq "array-method" and ($node->{"method"} // "") eq "join" and @{$node->{"args"} // [];} <= 1
!ll&&!rl&&r
004
$kind eq "array-method" and ($node->{"method"} // "") eq "join"
!ll&&!rl&&r
004
$node->{"method"} // ""
l!l
40
MC/DC0%0/3
$kind eq "array-method" and ($node->{"method"} // "") eq "join" and @{$node->{"args"} // [];} <= 1
$kind eq "array-method" $node->{"method"} @{$node->{"args"} // [];} <= 1
Truth table25%1/4
A and B and C
A= $kind eq "array-method"B= $node->{"method"}C= @{$node->{"args"} // [];} <= 1
ABCresult
0XX0
10X0
1100
1111
176 4 ▶ && @{ $node->{args} // [] } <= 1)
Condition50%1/2
$node->{"args"} // []
l!l
40
MC/DC0%0/1
$node->{"args"} // []
$node->{"args"}
Truth table50%1/2
A
A= $node->{"args"}
Aresult
11
00
177 {
178 # `.join(sep?)` (#2094), a sibling of `.includes` above in the
179 # `array-method` node kind — needed for a composed case like
180 # `.flatMap(p => p.tags.map(...).join(' ')).join(', ')`. JS
181 # semantics: default separator is `,`; a `null`/`undefined`
182 # element joins as `''` (NOT the string "null"). Mirrors the Go
183 # evaluator's evalJoin.
184 # An omitted or `undefined` separator is ","; a `null` one is
185 # ToString'd ("null").
186 4 my $obj = evaluate($node->{object}, $env);
187 4 ▶ my $args = $node->{args} // [];
Condition50%1/2
$node->{"args"} // []
l!l
40
MC/DC0%0/1
$node->{"args"} // []
$node->{"args"}
Truth table50%1/2
A
A= $node->{"args"}
Aresult
11
00
188 4 ▶ my $sep_value = @$args == 1 ? evaluate($args->[0], $env) : $UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
@$args == 1 ? : 2 2 4
189 4 ▶ my $sep = _is_undef($sep_value) ? ',' : _to_string($sep_value);
Branch: 1 branch
BranchTrueFalseTotal
_is_undef($sep_value) ? : 2 2 4
190 4 return _join_array($obj, $sep);
191 }
192  
193 # arrow-fn / higher-order / unsupported array-method: a callback body
194 # containing these is refused upstream (BF101); never reached here.
195 0 return undef;
196 }
197  
198 # ---------------------------------------------------------------------------
199 # Nested `.map` / `.filter` callback recognition (#2094) — the evaluator
200 # widening that lets a callback body (already evaluated here for reduce /
201 # sort / filter / find / …) itself contain a `.map(cb)` or `.filter(cb)`
202 # call, e.g. the #1938 blog-showcase `.flatMap(p => p.tags.map(t => '#'+t))`
203 # projection. Everything else nested (`.some`/`.find`/`.every`/`.sort`/
204 # `.reduce`/`.flat`/`.flatMap`, standalone arrows) stays refused upstream —
205 # only `.map`/`.filter` are recognized here, mirroring Go's
206 # evalArrayCallbackCall / evalArrayCallback exactly.
207 # ---------------------------------------------------------------------------
208  
209 # _array_callback_call($node): if $node (a `call` node) is a `.map(arrow)` /
210 # `.filter(arrow)` call — i.e. its callee is an uncomputed `member` node
211 # whose property is "map"/"filter", and its first argument is an `arrow`
212 # node — returns `(method, object_node, arrow_node)`. Otherwise returns the
213 # empty list (so `if (my (...) = _array_callback_call($node))` is false).
214 14 ▶sub _array_callback_call ($node) {
Subroutine _array_callback_call: called CC=13 SCAR=27.9
215 14 my $callee = $node->{callee};
216 14 ▶ return () unless ref $callee eq 'HASH' && ($callee->{kind} // '') eq 'member';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callee eq "HASH" and ($callee->{"kind"} // "") eq "member" 1 13 14
Condition60%3/5
ref $callee eq "HASH" and ($callee->{"kind"} // "") eq "member"
!ll&&!rl&&r
0113
$callee->{"kind"} // ""
l!l
140
MC/DC0%0/2
ref $callee eq "HASH" and ($callee->{"kind"} // "") eq "member"
ref $callee eq "HASH" $callee->{"kind"}
Truth table33%1/3
A and B
A= ref $callee eq "HASH"B= $callee->{"kind"}
ABresult
0X0
100
111
217 13 ▶ return () if $callee->{computed};
Branch: 1 branch
BranchTrueFalseTotal
if $callee->{"computed"} 0 13 13
218 13 ▶ my $prop = $callee->{property} // '';
Condition50%1/2
$callee->{"property"} // ""
l!l
130
MC/DC0%0/1
$callee->{"property"} // ""
$callee->{"property"}
Truth table50%1/2
A
A= $callee->{"property"}
Aresult
11
00
219 13 ▶ return () unless $prop eq 'map' || $prop eq 'filter';
Branch: 1 branch
BranchTrueFalseTotal
unless $prop eq "map" or $prop eq "filter" 8 5 13
Condition100%3/3
$prop eq "map" or $prop eq "filter"
l!l&&r!l&&!r
238
MC/DC100%2/2
$prop eq "map" or $prop eq "filter"
$prop eq "map" $prop eq "filter"
Truth table100%3/3
A or B
A= $prop eq "map"B= $prop eq "filter"
ABresult
1X1
011
000
220 5 ▶ my $args = $node->{args} // [];
Condition50%1/2
$node->{"args"} // []
l!l
50
MC/DC0%0/1
$node->{"args"} // []
$node->{"args"}
Truth table50%1/2
A
A= $node->{"args"}
Aresult
11
00
221 5 ▶ return () unless @$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 5 5
222 5 my $arrow = $args->[0];
223 5 ▶ return () unless ref $arrow eq 'HASH' && ($arrow->{kind} // '') eq 'arrow';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arrow eq "HASH" and ($arrow->{"kind"} // "") eq "arrow" 0 5 5
Condition40%2/5
ref $arrow eq "HASH" and ($arrow->{"kind"} // "") eq "arrow"
!ll&&!rl&&r
005
$arrow->{"kind"} // ""
l!l
50
MC/DC0%0/2
ref $arrow eq "HASH" and ($arrow->{"kind"} // "") eq "arrow"
ref $arrow eq "HASH" $arrow->{"kind"}
Truth table33%1/3
A and B
A= ref $arrow eq "HASH"B= $arrow->{"kind"}
ABresult
0X0
100
111
224 5 return ($prop, $callee->{object}, $arrow);
225 }
226  
227 # _array_callback($method, $object_node, $arrow_node, $env): evaluate the
228 # receiver (`$object_node`) against $env, then map/filter it through the
229 # arrow's body. `params` in the decoded JSON is an array ref of plain
230 # strings (e.g. `["t"]` or `["t","i"]`) — 1 param binds the element, 2
231 # params bind (element, index). The child env is a COPY of the parent env
232 # (never mutated in place across sibling iterations), with the param
233 # name(s) bound per call — matches Go's per-call `inner` env copy.
234 5 ▶sub _array_callback ($method, $object_node, $arrow_node, $env) {
Subroutine _array_callback: called CC=7 SCAR=19.5
235 5 my $arr = evaluate($object_node, $env);
236 5 ▶ return undef unless ref $arr eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arr eq "ARRAY" 0 5 5
237 5 ▶ my @params = @{ $arrow_node->{params} // [] };
Condition50%1/2
$arrow_node->{"params"} // []
l!l
50
MC/DC0%0/1
$arrow_node->{"params"} // []
$arrow_node->{"params"}
Truth table50%1/2
A
A= $arrow_node->{"params"}
Aresult
11
00
238 5 my $body = $arrow_node->{body};
239 11 ▶ my $call_cb = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
240 11 my ($item, $index) = @_;
241 11 my %inner = %$env;
242 11 ▶ $inner{ $params[0] } = $item if @params >= 1;
Branch: 1 branch
BranchTrueFalseTotal
if @params >= 1 11 0 11
243 11 ▶ $inner{ $params[1] } = $index if @params >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @params >= 2 3 8 11
244 11 return evaluate($body, \%inner);
245 5 };
246 5 ▶ if ($method eq 'map') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "map") 2 3 5
247 2 my @out;
248 2 my $i = 0;
249 2 for my $item (@$arr) {
250 5 push @out, $call_cb->($item, $i);
251 5 $i++;
252 }
253 2 return \@out;
254 }
255 # filter
256 3 my @out;
257 3 my $i = 0;
258 3 for my $item (@$arr) {
259 6 ▶ push @out, $item if _truthy($call_cb->($item, $i));
Branch: 1 branch
BranchTrueFalseTotal
if _truthy(&$call_cb($item, $i)) 2 4 6
260 6 $i++;
261 }
262 3 return \@out;
263 }
264  
265 # _join_array($obj, $sep): `Array.prototype.join` semantics — non-ARRAY
266 # receiver -> '' (the evaluator's degrade-rather-than-die convention,
267 # matching `.includes` above); a `null` (Perl `undef`) or `undefined`
268 # (`UNDEF`) element joins as '' (not the string "null"); every other element
269 # goes through
270 # `_to_string` (JS `String(x)` — a JS boolean stringifies "true"/"false", a
271 # number "42"/"NaN"/"Infinity", etc.). Mirrors Go's evalJoin.
272 4 ▶sub _join_array ($obj, $sep) {
Subroutine _join_array: called CC=3 SCAR=11.1
273 4 ▶ return '' unless ref $obj eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj eq "ARRAY" 0 4 4
274 4 ▶ return join($sep, map { _is_nullish($_) ? '' : _to_string($_) } @$obj);
Branch: 1 branch
BranchTrueFalseTotal
_is_nullish($_) ? : 1 7 8
275 }
276  
277 # eval_json($json, $env): decode a ParsedExpr JSON string and evaluate it.
278 # Mirrors the Go EvalExpr entry point. Requires JSON::PP only when used.
279 0 ▶sub eval_json ($json, $env) {
Subroutine eval_json: not called CC=1 SCAR=6.9
Pod undocumented
280 0 require JSON::PP;
281 0 my $node = JSON::PP->new->decode($json);
282 0 return evaluate($node, $env);
283 }
284  
285 # ---------------------------------------------------------------------------
286 # JS value classification. JSON-decoded strings carry the string flag (POK)
287 # but no numeric flag; JSON-decoded numbers carry IOK/NOK. This lets the
288 # evaluator tell the JS *string* "10" from the JS *number* 10 — essential for
289 # the `+` overload and relational comparison — which looks_like_number alone
290 # cannot (it is true for both).
291 # ---------------------------------------------------------------------------
292  
293 851 ▶sub _is_string ($v) {
Subroutine _is_string: called CC=5 SCAR=16.1
294 851 ▶ return 0 if !defined $v || ref $v;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $v or ref $v 5 846 851
Condition100%3/3
not defined $v or ref $v
l!l&&r!l&&!r
23846
MC/DC100%2/2
not defined $v or ref $v
not defined $v ref $v
Truth table100%3/3
not(A) or B
A= not defined $vB= ref $v
ABresult
1X1
011
000
295 846 my $f = B::svref_2object(\$v)->FLAGS;
296 846 ▶ return (($f & B::SVf_POK) && !($f & (B::SVf_IOK | B::SVf_NOK))) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$f & 1024 && !($f & 768) ? : 293 553 846
Condition66%2/3
$f & 1024 and not $f & 768
!ll&&!rl&&r
5530293
MC/DC50%1/2
$f & 1024 and not $f & 768
$f & 1024 not $f & 768
Truth table66%2/3
A and not(B)
A= $f & 1024B= not $f & 768
ABresult
0X0
100
111
297 }
298  
299 363 ▶sub _is_number ($v) {
Subroutine _is_number: called CC=4 SCAR=13.9
300 363 ▶ return (defined $v && !ref $v && !_is_string($v)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $v && !ref($v) && !_is_string($v) ? : 109 254 363
Condition100%6/6
defined $v and not ref $v and not _is_string($v)
!ll&&!rl&&r
46208109
defined $v and not ref $v
!ll&&!rl&&r
1234317
MC/DC100%3/3
defined $v and not ref $v and not _is_string($v)
defined $v not ref $v not _is_string($v)
Truth table100%4/4
A and not(B) and not(C)
A= defined $vB= not ref $vC= not _is_string($v)
ABCresult
0XX0
10X0
1100
1111
301 }
302  
303 # Perl's builtin `length` counts UTF-8 BYTES unless the scalar already
304 # carries the internal UTF8 flag (set when the caller decoded it, e.g. via
305 # `JSON::PP->new->utf8->decode`) — a byte count diverges from JS `.length`
306 # (UTF-16 code units) on ANY non-ASCII input, not just astral characters
307 # (#2196 Level 1). Count Unicode codepoints instead: agrees with JS for
308 # every BMP character; astral characters (emoji, CJK-ext) still diverge
309 # from JS's 2-code-unit count (documented, separate known limitation) but
310 # now agree with the other four backends (Go/Ruby/Python/PHP), which all
311 # already count codepoints.
312 1 ▶sub _codepoint_length ($s) {
Subroutine _codepoint_length: called CC=2 SCAR=7.0
313 1 ▶ return length($s) if utf8::is_utf8($s);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($s) 0 1 1
314 1 my $copy = $s;
315 1 utf8::decode($copy); # no-op on already-decoded or invalid-UTF-8 input
316 1 return length($copy);
317 }
318  
319 22 ▶sub _nan {
Subroutine _nan: called CC=1 SCAR=0.0
320 22 my $inf = 9**9**9;
321 22 return $inf - $inf;
322 }
323  
324 # ---------------------------------------------------------------------------
325 # JS coercion primitives (ToNumber / ToString / ToBoolean).
326 # ---------------------------------------------------------------------------
327  
328 # _double: the IEEE double nearest $n. A JS number is a double, but a perl
329 # built with -Duselongdouble or -Dusequadmath keeps a wider NV, so `0.1 + 0.2`
330 # is 0.3 there and a round-trip check passes at a precision JS doesn't have
331 # (#3445). Rounding where a number enters and after each arithmetic step keeps
332 # those perls on JS's values; with an 8-byte NV it is the identity.
333 18 ▶use constant WIDE_NV => length(pack 'F', 0) > 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
334 705 ▶sub _double ($n) { WIDE_NV ? unpack('d', pack('d', $n)) : $n }
Subroutine _double: called CC=1 SCAR=0.0
335  
336 404 ▶sub _to_number ($v) {
Subroutine _to_number: called CC=7 SCAR=20.7
337 404 ▶ return 0 if !defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 12 392 404
338 392 ▶ return _nan() if _is_undef($v);
Branch: 1 branch
BranchTrueFalseTotal
if _is_undef($v) 10 382 392
339 0 ▶ if (ref $v eq 'JSON::PP::Boolean') { return $v ? 1 : 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq "JSON::PP::Boolean") 0 382 382
$v ? : 0 0 0
340 382 ▶ return _nan() if ref $v;
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 0 382 382
341 382 ▶ return _string_to_number($v) if _is_string($v);
Branch: 1 branch
BranchTrueFalseTotal
if _is_string($v) 9 373 382
342 # Already a number: no `+ 0`, which would turn a -0 into +0.
343 373 return _double($v);
344 }
345  
346 # _string_to_number: JS StringToNumber (ECMA-262 StringNumericLiteral),
347 # ASCII digits only. The string is trimmed and `''` is 0; a signed decimal
348 # literal with an optional exponent, the exact spelling `Infinity`, and an
349 # unsigned `0x` / `0o` / `0b` integer are their values; anything else
350 # (`infinity`, `nan`, `1_000`, `-0x10`) is NaN. Perl's own numification
351 # (`looks_like_number`) accepts `inf` / `nan`, reads `"0x10"` as 0 and
352 # `"-0"` as +0, so it is not used here.
353 18 my %RADIX = (x => 16, o => 8, b => 2);
354  
355 # _radix_to_number: the digits of a JS `0x` / `0o` / `0b` integer as the
356 # double nearest its value, ties to even; NaN for a digit outside the base.
357 # JS rounds the mathematical value once (#3824 step 3), so the digits are
358 # read as bits: the first 53 significant bits, the next one (the round bit)
359 # and whether any later bit is set (the sticky bit). Accumulating them in a
360 # Perl number rounds every prefix past 64 bits instead. A value past the
361 # largest double is Infinity.
362 18 my %RADIX_BITS = (16 => 4, 8 => 3, 2 => 1);
363  
364 0 ▶sub _radix_to_number ($digits, $base) {
Subroutine _radix_to_number: not called CC=13 SCAR=52.0
365 0 my $kept = 0; # the first 54 significant bits (53 + the round bit)
366 0 my $significant = 0;
367 0 my $sticky = 0;
368 0 for my $digit (split //, $digits) {
369 0 my $d = hex $digit;
370 0 ▶ return _nan() if $d >= $base;
Branch: 1 branch
BranchTrueFalseTotal
if $d >= $base 0 0 0
371 0 ▶ for (my $shift = $RADIX_BITS{$base} - 1; $shift >= 0; $shift--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shift >= 0) 0 0 0
372 0 my $bit = ($d >> $shift) & 1;
373 0 ▶ next if $significant == 0 && $bit == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $significant == 0 and $bit == 0 0 0 0
Condition0%0/3
$significant == 0 and $bit == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$significant == 0 and $bit == 0
$significant == 0 $bit == 0
Truth table0%0/3
A and B
A= $significant == 0B= $bit == 0
ABresult
0X0
100
111
374 0 ▶ if ($significant < 54) {
Branch: 2 branches
BranchTrueFalseTotal
if ($significant < 54) { } 0 0 0
elsif ($bit) { } 0 0 0
375 0 $kept = $kept * 2 + $bit;
376 }
377 elsif ($bit) {
378 0 $sticky = 1;
379 }
380 0 $significant++;
381 }
382 }
383 0 ▶ return _double($kept) if $significant <= 53;
Branch: 1 branch
BranchTrueFalseTotal
if $significant <= 53 0 0 0
384 0 my $round = $kept % 2;
385 0 my $mantissa = ($kept - $round) / 2;
386 0 ▶ $mantissa++ if $round && ($sticky || $mantissa % 2);
Branch: 1 branch
BranchTrueFalseTotal
if $round and $sticky || $mantissa % 2 0 0 0
Condition0%0/6
$round and $sticky || $mantissa % 2
!ll&&!rl&&r
000
$sticky or $mantissa % 2
l!l&&r!l&&!r
000
MC/DC0%0/3
$round and $sticky || $mantissa % 2
$round $sticky $mantissa % 2
Truth table0%0/4
A and B or C
A= $roundB= $stickyC= $mantissa % 2
ABCresult
0XX0
1000
11X1
1011
387 # mantissa <= 2^53 is exact, and a power of two scales it exactly or
388 # overflows to Infinity.
389 0 my $exponent = $significant - 53;
390 0 ▶ return 9**9**9 if $exponent > 1100;
Branch: 1 branch
BranchTrueFalseTotal
if $exponent > 1100 0 0 0
391 0 return _double($mantissa * (2**$exponent));
392 }
393  
394 9 ▶sub _string_to_number ($s) {
Subroutine _string_to_number: called CC=8 SCAR=30.1
395 9 my $t = $s;
396 9 $t =~ s/\A\s+//;
397 9 $t =~ s/\s+\z//;
398 9 ▶ return 0 if $t eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "" 0 9 9
399 9 ▶ if ($t =~ /\A0([xXoObB])([0-9a-fA-F]+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /\A0([xXoObB])([0-9a-fA-F]+)\z/) 0 9 9
400 0 return _radix_to_number($2, $RADIX{lc $1});
401 }
402 9 ▶ if ($t =~ /\A([+-]?)Infinity\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /\A([+-]?)Infinity\z/) 0 9 9
403 0 ▶ return $1 eq '-' ? -(9**9**9) : 9**9**9;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '-' ? : 0 0 0
404 }
405 9 ▶ return _nan() unless $t =~ /\A([+-]?)(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ /\A([+-]?)(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?\z/ 9 0 9
406 0 my $n = _double($t + 0);
407 # `"-0"` (and `"-0.0"`, `"-0e5"`) is negative zero; Perl numifies it to +0.
408 0 ▶ return ($1 eq '-' && $n == 0) ? -(unpack('d', pack('d', 0))) : $n;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '-' && $n == 0 ? : 0 0 0
Condition0%0/3
$1 eq "-" and $n == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$1 eq "-" and $n == 0
$1 eq "-" $n == 0
Truth table0%0/3
A and B
A= $1 eq "-"B= $n == 0
ABresult
0X0
100
111
409 }
410  
411 197 ▶sub _to_string ($v) {
Subroutine _to_string: called CC=9 SCAR=22.7
412 197 ▶ return 'null' if !defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 7 190 197
413 190 ▶ return 'undefined' if _is_undef($v);
Branch: 1 branch
BranchTrueFalseTotal
if _is_undef($v) 4 186 190
414 186 ▶ if (ref $v eq 'JSON::PP::Boolean') { return $v ? 'true' : 'false' }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq "JSON::PP::Boolean") 4 182 186
$v ? : 3 1 4
415 # Array.prototype.toString is join(","): a nil element (`null` or
416 # `undefined`) prints as "", and a nested array flattens through its own
417 # join. A plain object prints as "[object Object]".
418 0 ▶ return join(',', map { _is_nullish($_) ? '' : _to_string($_) } @$v) if ref $v eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
if ref $v eq "ARRAY" 0 182 182
_is_nullish($_) ? : 0 0 0
419 182 ▶ return '[object Object]' if ref $v eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "HASH" 0 182 182
420 182 ▶ return _format_number($v + 0) if _is_number($v);
Branch: 1 branch
BranchTrueFalseTotal
if _is_number($v) 35 147 182
421 147 return "$v";
422 }
423  
424 # _is_object: an array or a plain object, which ToPrimitive turns into its
425 # ToString, so a `+` over it concatenates.
426 36 ▶sub _is_object ($v) {
Subroutine _is_object: called CC=3 SCAR=13.1
427 36 my $r = ref $v;
428 36 ▶ return ($r eq 'ARRAY' || $r eq 'HASH') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$r eq 'ARRAY' || $r eq 'HASH' ? : 0 36 36
Condition33%1/3
$r eq "ARRAY" or $r eq "HASH"
l!l&&r!l&&!r
0036
MC/DC0%0/2
$r eq "ARRAY" or $r eq "HASH"
$r eq "ARRAY" $r eq "HASH"
Truth table33%1/3
A or B
A= $r eq "ARRAY"B= $r eq "HASH"
ABresult
1X1
011
000
429 }
430  
431 # _format_number: JS `Number::toString`. Perl's own stringification is
432 # `%.15g`, which drops digits (`0.1 + 0.2` -> "0.3"), spells the non-finite
433 # doubles "Inf" / "NaN", and pads a small exponent (`1.23456789e-06`).
434 # Integers below 2**53 print exactly; everything else takes the shortest
435 # `%.Ng` that round-trips as a double and re-spells it with ECMA-262's notation rules:
436 # decimal within [1e-6, 1e21), otherwise an unpadded lower-case exponent
437 # (`1.23456789e-7`, `1.23456789e+21`) (#3380).
438 93 ▶sub _format_number ($n) {
Subroutine _format_number: called CC=9 SCAR=22.0
439 93 $n = _double($n);
440 93 ▶ return 'NaN' if $n != $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n != $n 5 88 93
441 88 ▶ return 'Infinity' if $n == 9**9**9;
Branch: 1 branch
BranchTrueFalseTotal
if $n == "Inf" 4 84 88
442 84 ▶ return '-Infinity' if $n == -(9**9**9);
Branch: 1 branch
BranchTrueFalseTotal
if $n == "-Inf" 6 78 84
443 78 ▶ return '0' if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 15 63 78
444 63 ▶ return sprintf('%.0f', $n) if $n == int($n) && abs($n) < 9007199254740992;
Branch: 1 branch
BranchTrueFalseTotal
if $n == int $n and abs $n < '9007199254740992' 42 21 63
Condition100%3/3
$n == int $n and abs $n < '9007199254740992'
!ll&&!rl&&r
15642
MC/DC100%2/2
$n == int $n and abs $n < '9007199254740992'
$n == int $n abs $n < '9007199254740992'
Truth table100%3/3
A and B
A= $n == int $nB= abs $n < '9007199254740992'
ABresult
0X0
100
111
445 21 my $s;
446 21 for my $p (1 .. 17) {
447 127 $s = sprintf('%.*g', $p, $n);
448 127 ▶ last if _double($s + 0) == $n;
Branch: 1 branch
BranchTrueFalseTotal
if _double($s + 0) == $n 21 106 127
449 }
450 21 return _js_notation($s);
451 }
452  
453 # _js_notation: re-spell a shortest round-trip decimal (`[-]d[.ddd][e[+-]x]`)
454 # with ECMA-262's Number::toString notation rules. `$digits` holds the
455 # significant digits, `$point` where the decimal point falls in them.
456 21 ▶sub _js_notation ($shortest) {
Subroutine _js_notation: called CC=13 SCAR=25.7
457 21 ▶ my $sign = $shortest =~ s/\A-// ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
$shortest =~ s/\A-// ? : 8 13 21
458 21 my ($mantissa, $exp) = split /e/i, $shortest, 2;
459 21 my ($int, $frac) = split /\./, $mantissa, 2;
460 21 ▶ $frac //= '';
Condition100%2/2
$frac //= ""
l!l
1110
MC/DC100%1/1
$frac //= ""
$frac
Truth table100%2/2
A
A= $frac
Aresult
11
00
461 21 my $raw = $int . $frac;
462 21 ▶ my $point = length($int) + (defined $exp ? $exp + 0 : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $exp ? : 15 6 21
463 21 (my $digits = $raw) =~ s/\A0+//;
464 21 $point -= length($raw) - length($digits);
465 21 $digits =~ s/0+\z//;
466 21 ▶ $digits = '0' if $digits eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $digits eq "" 0 21 21
467 21 my $k = length $digits;
468 21 my $out;
469 21 ▶ if ($k <= $point && $point <= 21) {
Branch: 3 branches
BranchTrueFalseTotal
if ($k <= $point and $point <= 21) { } 3 18 21
elsif ($point > 0 and $point <= 21) { } 2 16 18
elsif ($point > -6 and $point <= 0) { } 7 9 16
Condition100%3/3
$k <= $point and $point <= 21
!ll&&!rl&&r
1533
MC/DC100%2/2
$k <= $point and $point <= 21
$k <= $point $point <= 21
Truth table100%3/3
A and B
A= $k <= $pointB= $point <= 21
ABresult
0X0
100
111
470 3 $out = $digits . ('0' x ($point - $k));
471 ▶ } elsif ($point > 0 && $point <= 21) {
Condition100%3/3
$point > 0 and $point <= 21
!ll&&!rl&&r
1332
MC/DC100%2/2
$point > 0 and $point <= 21
$point > 0 $point <= 21
Truth table100%3/3
A and B
A= $point > 0B= $point <= 21
ABresult
0X0
100
111
472 2 $out = substr($digits, 0, $point) . '.' . substr($digits, $point);
473 ▶ } elsif ($point > -6 && $point <= 0) {
Condition100%3/3
$point > -6 and $point <= 0
!ll&&!rl&&r
637
MC/DC100%2/2
$point > -6 and $point <= 0
$point > -6 $point <= 0
Truth table100%3/3
A and B
A= $point > -6B= $point <= 0
ABresult
0X0
100
111
474 7 $out = '0.' . ('0' x -$point) . $digits;
475 } else {
476 9 my $e = $point - 1;
477 9 ▶ $out = substr($digits, 0, 1) . ($k > 1 ? '.' . substr($digits, 1) : '')
Branch: 2 branches
BranchTrueFalseTotal
$k > 1 ? : 3 6 9
$e >= 0 ? : 3 6 9
478 . 'e' . ($e >= 0 ? '+' : '-') . abs($e);
479 }
480 21 return $sign . $out;
481 }
482  
483 39 ▶sub _truthy ($v) {
Subroutine _truthy: called CC=9 SCAR=26.5
484 39 ▶ return 0 if _is_nullish($v);
Branch: 1 branch
BranchTrueFalseTotal
if _is_nullish($v) 1 38 39
485 38 ▶ if (ref $v eq 'JSON::PP::Boolean') { return $v ? 1 : 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq "JSON::PP::Boolean") 36 2 38
$v ? : 16 20 36
486 2 ▶ return 1 if ref $v; # arrays / objects are always truthy in JS
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 0 2 2
487 2 ▶ if (_is_string($v)) { return $v ne '' ? 1 : 0 } # incl. the truthy "0"
Branch: 2 branches
BranchTrueFalseTotal
if (_is_string($v)) 2 0 2
$v ne '' ? : 0 2 2
488 0 my $n = $v + 0;
489 0 ▶ return ($n != 0 && $n == $n) ? 1 : 0; # nonzero and not NaN
Branch: 1 branch
BranchTrueFalseTotal
$n != 0 && $n == $n ? : 0 0 0
Condition0%0/3
$n != 0 and $n == $n
!ll&&!rl&&r
000
MC/DC0%0/2
$n != 0 and $n == $n
$n != 0 $n == $n
Truth table0%0/3
A and B
A= $n != 0B= $n == $n
ABresult
0X0
100
111
490 }
491  
492 # _bool: wrap a Perl truthy/falsy into a JS boolean (JSON::PP::Boolean), so
493 # boolean-valued operators (relational, ===, !, Boolean()) return a real
494 # boolean rather than 1/0 — matching the Go evaluator's bool (e.g.
495 # String(a < b) is "true", and `'x' + (a < b)` is "xtrue"). The coercions
496 # above already treat JSON::PP::Boolean correctly.
497 49 ▶sub _bool ($t) { $t ? JSON::PP::true() : JSON::PP::false() }
Subroutine _bool: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$t ? : 25 24 49
498  
499 # ---------------------------------------------------------------------------
500 # Operators
501 # ---------------------------------------------------------------------------
502  
503 113 ▶sub _binary ($op, $l, $r) {
Subroutine _binary: called CC=19 SCAR=30.3
504 113 ▶ if ($op eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "+") 34 79 113
505 # JS `+`: string concatenation once either operand is a string after
506 # ToPrimitive (an array or object converts to its ToString), numeric
507 # addition otherwise.
508 34 ▶ return _to_string($l) . _to_string($r)
Branch: 1 branch
BranchTrueFalseTotal
if _is_string($l) or _is_string($r) or _is_object($l) or _is_object($r) 16 18 34
Condition77%7/9
_is_string($l) or _is_string($r) or _is_object($l) or _is_object($r)
l!l&&r!l&&!r
16018
_is_string($l) or _is_string($r) or _is_object($l)
l!l&&r!l&&!r
16018
_is_string($l) or _is_string($r)
l!l&&r!l&&!r
15118
MC/DC50%2/4
_is_string($l) or _is_string($r) or _is_object($l) or _is_object($r)
_is_string($l) _is_string($r) _is_object($l) _is_object($r)
Truth table60%3/5
A or B or C or D
A= _is_string($l)B= _is_string($r)C= _is_object($l)D= _is_object($r)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
509 if _is_string($l) || _is_string($r) || _is_object($l) || _is_object($r);
510 18 my ($ln, $rn) = (_to_number($l), _to_number($r));
511 18 my $sum = _double($ln + $rn);
512 # Perl adds two integral doubles as integers, which drops the sign of
513 # `-0 + -0`; IEEE addition keeps it.
514 18 ▶ return -(unpack('d', pack('d', 0))) if $sum == 0 && POSIX::signbit($ln) && POSIX::signbit($rn);
Branch: 1 branch
BranchTrueFalseTotal
if $sum == 0 and POSIX::signbit($ln) and POSIX::signbit($rn) 0 18 18
Condition33%2/6
$sum == 0 and POSIX::signbit($ln) and POSIX::signbit($rn)
!ll&&!rl&&r
1800
$sum == 0 and POSIX::signbit($ln)
!ll&&!rl&&r
1800
MC/DC0%0/3
$sum == 0 and POSIX::signbit($ln) and POSIX::signbit($rn)
$sum == 0 POSIX::signbit($ln) POSIX::signbit($rn)
Truth table25%1/4
A and B and C
A= $sum == 0B= POSIX::signbit($ln)C= POSIX::signbit($rn)
ABCresult
0XX0
10X0
1100
1111
515 18 return $sum;
516 }
517 79 ▶ return _double(_to_number($l) - _to_number($r)) if $op eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-" 25 54 79
518 54 ▶ return _double(_to_number($l) * _to_number($r)) if $op eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "*" 7 47 54
519 47 ▶ if ($op eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "/") 8 39 47
520 8 return _divide(_to_number($l), _to_number($r));
521 }
522 39 ▶ return _remainder(_to_number($l), _to_number($r)) if $op eq '%';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "%" 2 37 39
523 37 ▶ return _relational($op, $l, $r) if $op eq '<' || $op eq '<=' || $op eq '>' || $op eq '>=';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "<" or $op eq "<=" or $op eq ">" or $op eq ">=" 34 3 37
Condition88%8/9
$op eq "<" or $op eq "<=" or $op eq ">" or $op eq ">="
l!l&&r!l&&!r
4303
$op eq "<" or $op eq "<=" or $op eq ">"
l!l&&r!l&&!r
2233
$op eq "<" or $op eq "<="
l!l&&r!l&&!r
2035
MC/DC75%3/4
$op eq "<" or $op eq "<=" or $op eq ">" or $op eq ">="
$op eq "<" $op eq "<=" $op eq ">" $op eq ">="
Truth table80%4/5
A or B or C or D
A= $op eq "<"B= $op eq "<="C= $op eq ">"D= $op eq ">="
ABCDresult
1XXX1
01XX1
001X1
00011
00000
524 3 ▶ return _bool(_strict_eq($l, $r)) if $op eq '===';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "===" 2 1 3
525 1 ▶ return _bool(!_strict_eq($l, $r)) if $op eq '!==';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "!==" 1 0 1
526 # Loose equality / bitwise / shift are out of the subset.
527 0 return undef;
528 }
529  
530 # _divide: JS `/` over two numbers, as a double. Division by zero is
531 # finite-valued, not an error: x/0 is ±Infinity, signed by both operands
532 # (`1 / -0` is -Infinity), and 0/0 or NaN/0 is NaN. Perl's native `/` dies
533 # on a zero divisor. Shared with the template runtime's `divide` (#3454).
534 15 ▶sub _divide ($ln, $rn) {
Subroutine _divide: called CC=6 SCAR=17.9
535 15 ▶ if ($rn == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rn == 0) 12 3 15
536 12 ▶ return _nan() if $ln == 0 || $ln != $ln;
Branch: 1 branch
BranchTrueFalseTotal
if $ln == 0 or $ln != $ln 2 10 12
Condition66%2/3
$ln == 0 or $ln != $ln
l!l&&r!l&&!r
2010
MC/DC50%1/2
$ln == 0 or $ln != $ln
$ln == 0 $ln != $ln
Truth table66%2/3
A or B
A= $ln == 0B= $ln != $ln
ABresult
1X1
011
000
537 10 ▶ my $negative = ($ln < 0) != (POSIX::signbit($rn) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
POSIX::signbit($rn) ? : 5 5 10
538 10 ▶ return $negative ? -(9**9**9) : 9**9**9;
Branch: 1 branch
BranchTrueFalseTotal
$negative ? : 6 4 10
539 }
540 3 return _double($ln / $rn);
541 }
542  
543 # _remainder: JS `%` over two numbers, the truncated remainder: it takes the
544 # dividend's sign (`-7 % 2` is -1) and keeps a fraction (`7.5 % 2` is 1.5),
545 # where Perl's native `%` floors and works on integers. A zero divisor, or a
546 # NaN / infinite dividend, gives NaN. Shared with the template runtime's
547 # `mod` (#3474).
548 14 ▶sub _remainder ($ln, $rn) {
Subroutine _remainder: called CC=2 SCAR=6.9
549 14 ▶ return _nan() if $rn == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rn == 0 1 13 14
550 13 return POSIX::fmod($ln, $rn);
551 }
552  
553 36 ▶sub _relational ($op, $l, $r) {
Subroutine _relational: called CC=11 SCAR=24.9
554 # JS Abstract Relational Comparison: both strings → compare by code unit;
555 # otherwise coerce both to numbers (a NaN operand makes it false).
556 36 my $c;
557 36 ▶ if (_is_string($l) && _is_string($r)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_string($l) and _is_string($r)) { } 0 36 36
Condition33%1/3
_is_string($l) and _is_string($r)
!ll&&!rl&&r
3600
MC/DC0%0/2
_is_string($l) and _is_string($r)
_is_string($l) _is_string($r)
Truth table33%1/3
A and B
A= _is_string($l)B= _is_string($r)
ABresult
0X0
100
111
558 0 $c = _compare_utf16($l, $r);
559 }
560 else {
561 36 my $ln = _to_number($l);
562 36 my $rn = _to_number($r);
563 36 ▶ return _bool(0) if $ln != $ln || $rn != $rn; # NaN → false
Branch: 1 branch
BranchTrueFalseTotal
if $ln != $ln or $rn != $rn 1 35 36
Condition66%2/3
$ln != $ln or $rn != $rn
l!l&&r!l&&!r
1035
MC/DC50%1/2
$ln != $ln or $rn != $rn
$ln != $ln $rn != $rn
Truth table66%2/3
A or B
A= $ln != $lnB= $rn != $rn
ABresult
1X1
011
000
564 35 ▶ $c = $ln < $rn ? -1 : $ln > $rn ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$ln < $rn ? : 18 17 35
$ln > $rn ? : 9 8 17
565 }
566 35 ▶ return _bool($c < 0) if $op eq '<';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "<" 2 33 35
567 33 ▶ return _bool($c <= 0) if $op eq '<=';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "<=" 1 32 33
568 32 ▶ return _bool($c > 0) if $op eq '>';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq ">" 2 30 32
569 30 ▶ return _bool($c >= 0) if $op eq '>=';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq ">=" 30 0 30
570 0 return _bool(0);
571 }
572  
573 # _compare_utf16: JS string order, by UTF-16 code unit. Perl's `cmp` orders
574 # characters by code point, which differs where an astral character (whose
575 # leading surrogate is 0xD800-0xDBFF) meets a BMP character above the
576 # surrogates (`"😀" lt "。"` is true in JS); and a string without Perl's
577 # UTF8 flag holds UTF-8 bytes, which `cmp` would read as Latin-1 against a
578 # flagged one. Both are decoded and re-packed as big-endian UTF-16, whose
579 # bytes compare in code-unit order.
580 0 ▶sub _compare_utf16 ($l, $r) {
Subroutine _compare_utf16: not called CC=3 SCAR=24.8
581 0 ▶ return $l cmp $r unless $l =~ /[^\x00-\x7f]/ || $r =~ /[^\x00-\x7f]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /[^\x00-\x7f]/ or $r =~ /[^\x00-\x7f]/ 0 0 0
Condition0%0/3
$l =~ /[^\x00-\x7f]/ or $r =~ /[^\x00-\x7f]/
l!l&&r!l&&!r
000
MC/DC0%0/2
$l =~ /[^\x00-\x7f]/ or $r =~ /[^\x00-\x7f]/
$l =~ /[^\x00-\x7f]/ $r =~ /[^\x00-\x7f]/
Truth table0%0/3
A or B
A= $l =~ /[^\x00-\x7f]/B= $r =~ /[^\x00-\x7f]/
ABresult
1X1
011
000
582 0 return _utf16_be($l) cmp _utf16_be($r);
583 }
584  
585 0 ▶sub _utf16_be ($s) {
Subroutine _utf16_be: not called CC=3 SCAR=24.8
586 0 ▶ utf8::decode($s) unless utf8::is_utf8($s); # no-op on invalid UTF-8
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($s) 0 0 0
587 return join '', map {
588 0 my $o = ord;
589 0 ▶ $o > 0xFFFF
Branch: 1 branch
BranchTrueFalseTotal
$o > 65535 ? : 0 0 0
590 ? pack('n2', 0xD800 + (($o - 0x10000) >> 10), 0xDC00 + (($o - 0x10000) & 0x3FF))
591 : pack('n', $o)
592 } split //, $s;
593 }
594  
595 57 ▶sub _strict_eq ($l, $r) {
Subroutine _strict_eq: called CC=27 SCAR=34.5
596 # Strict `===`: equal JS type and value, no coercion.
597 57 my $ln = _is_number($l);
598 57 my $rn = _is_number($r);
599 57 ▶ if ($ln && $rn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln and $rn) 14 43 57
Condition100%3/3
$ln and $rn
!ll&&!rl&&r
38514
MC/DC100%2/2
$ln and $rn
$ln $rn
Truth table100%3/3
A and B
A= $lnB= $rn
ABresult
0X0
100
111
600 # Compared as doubles: an arithmetic result is already rounded to
601 # one, but a literal or env value on a wide-NV perl is not (#3445).
602 14 my ($lf, $rf) = (_double($l + 0), _double($r + 0));
603 14 ▶ return 0 if $lf != $lf || $rf != $rf; # NaN
Branch: 1 branch
BranchTrueFalseTotal
if $lf != $lf or $rf != $rf 1 13 14
Condition66%2/3
$lf != $lf or $rf != $rf
l!l&&r!l&&!r
1013
MC/DC50%1/2
$lf != $lf or $rf != $rf
$lf != $lf $rf != $rf
Truth table66%2/3
A or B
A= $lf != $lfB= $rf != $rf
ABresult
1X1
011
000
604 13 ▶ return $lf == $rf ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$lf == $rf ? : 10 3 13
605 }
606 43 ▶ return 0 if $ln != $rn; # one numeric, one not
Branch: 1 branch
BranchTrueFalseTotal
if $ln != $rn 8 35 43
607 # `null` is only itself and `undefined` only itself.
608 35 ▶ if (!defined $l) { return !defined $r ? 1 : 0 }
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $l) 3 32 35
!defined($r) ? : 2 1 3
609 32 ▶ return 0 if !defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 5 27 32
610 27 ▶ return (_is_undef($l) && _is_undef($r)) ? 1 : 0 if _is_undef($l) || _is_undef($r);
Branch: 2 branches
BranchTrueFalseTotal
if _is_undef($l) or _is_undef($r) 2 25 27
_is_undef($l) && _is_undef($r) ? : 2 0 2
Condition50%3/6
_is_undef($l) or _is_undef($r)
l!l&&r!l&&!r
2025
_is_undef($l) and _is_undef($r)
!ll&&!rl&&r
002
MC/DC50%1/2
_is_undef($l) or _is_undef($r)
_is_undef($l) _is_undef($r)
MC/DC0%0/2
_is_undef($l) and _is_undef($r)
_is_undef($l) _is_undef($r)
Truth table66%2/3
A or B
A= _is_undef($l)B= _is_undef($r)
ABresult
1X1
011
000
Truth table33%1/3
A and B
A= _is_undef($l)B= _is_undef($r)
ABresult
0X0
100
111
611 25 my $lb = ref $l eq 'JSON::PP::Boolean';
612 25 my $rb = ref $r eq 'JSON::PP::Boolean';
613 25 ▶ if ($lb || $rb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lb or $rb) 2 23 25
Condition66%2/3
$lb or $rb
l!l&&r!l&&!r
2023
MC/DC50%1/2
$lb or $rb
$lb $rb
Truth table66%2/3
A or B
A= $lbB= $rb
ABresult
1X1
011
000
614 2 ▶ return 0 unless $lb && $rb;
Branch: 1 branch
BranchTrueFalseTotal
unless $lb and $rb 0 2 2
Condition33%1/3
$lb and $rb
!ll&&!rl&&r
002
MC/DC0%0/2
$lb and $rb
$lb $rb
Truth table33%1/3
A and B
A= $lbB= $rb
ABresult
0X0
100
111
615 2 ▶ return ((!!$l) == (!!$r)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
(!!$l) == !!$r ? : 1 1 2
616 }
617 # An object or array is equal only to itself: the same reference, not
618 # another structure with the same contents.
619 23 ▶ if (ref $l || ref $r) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $l or ref $r) 9 14 23
Condition66%2/3
ref $l or ref $r
l!l&&r!l&&!r
9014
MC/DC50%1/2
ref $l or ref $r
ref $l ref $r
Truth table66%2/3
A or B
A= ref $lB= ref $r
ABresult
1X1
011
000
620 9 ▶ return (ref $l && ref $r && refaddr($l) == refaddr($r)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $l && ref $r && builtin::refaddr($l) == builtin::refaddr($r) ? : 3 6 9
Condition83%5/6
ref $l and ref $r and builtin::refaddr($l) == builtin::refaddr($r)
!ll&&!rl&&r
153
ref $l and ref $r
!ll&&!rl&&r
018
MC/DC66%2/3
ref $l and ref $r and builtin::refaddr($l) == builtin::refaddr($r)
ref $l ref $r builtin::refaddr($l) == builtin::refaddr($r)
Truth table75%3/4
A and B and C
A= ref $lB= ref $rC= builtin::refaddr($l) == builtin::refaddr($r)
ABCresult
0XX0
10X0
1100
1111
621 }
622 14 ▶ return ($l eq $r ? 1 : 0) if _is_string($l) && _is_string($r);
Branch: 2 branches
BranchTrueFalseTotal
if _is_string($l) and _is_string($r) 14 0 14
$l eq $r ? : 4 10 14
Condition33%1/3
_is_string($l) and _is_string($r)
!ll&&!rl&&r
0014
MC/DC0%0/2
_is_string($l) and _is_string($r)
_is_string($l) _is_string($r)
Truth table33%1/3
A and B
A= _is_string($l)B= _is_string($r)
ABresult
0X0
100
111
623 0 return 0;
624 }
625  
626 # _same_value_zero: `Array.prototype.includes` membership test — `===`
627 # except `NaN` equals itself (and +0/-0 are not distinguished, which the
628 # JSON-decoded values here can't represent anyway). Reuses `_strict_eq`'s
629 # type/value rules and only special-cases the two-NaN case that `_strict_eq`
630 # (deliberately, for `===`) reports as unequal.
631 28 ▶sub _same_value_zero ($l, $r) {
Subroutine _same_value_zero: called CC=5 SCAR=16.6
632 28 ▶ if (_is_number($l) && _is_number($r)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_number($l) and _is_number($r)) 6 22 28
Condition100%3/3
_is_number($l) and _is_number($r)
!ll&&!rl&&r
1846
MC/DC100%2/2
_is_number($l) and _is_number($r)
_is_number($l) _is_number($r)
Truth table100%3/3
A and B
A= _is_number($l)B= _is_number($r)
ABresult
0X0
100
111
633 6 my ($lf, $rf) = ($l + 0, $r + 0);
634 6 ▶ return 1 if $lf != $lf && $rf != $rf; # NaN sameValueZero NaN
Branch: 1 branch
BranchTrueFalseTotal
if $lf != $lf and $rf != $rf 0 6 6
Condition33%1/3
$lf != $lf and $rf != $rf
!ll&&!rl&&r
600
MC/DC0%0/2
$lf != $lf and $rf != $rf
$lf != $lf $rf != $rf
Truth table33%1/3
A and B
A= $lf != $lfB= $rf != $rf
ABresult
0X0
100
111
635 }
636 28 return _strict_eq($l, $r);
637 }
638  
639 1 ▶sub _unary ($op, $v) {
Subroutine _unary: called CC=4 SCAR=25.0
640 1 ▶ return _bool(!_truthy($v)) if $op eq '!';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "!" 1 0 1
641 # JS `-x` keeps the sign of zero: negate the double, never a Perl IV,
642 # whose zero has no sign (`-0` is 0).
643 0 ▶ return -(unpack('d', pack('d', _to_number($v)))) if $op eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-" 0 0 0
644 0 ▶ return _to_number($v) if $op eq '+';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "+" 0 0 0
645 0 return undef;
646 }
647  
648 # ---------------------------------------------------------------------------
649 # Built-in calls (the deterministic allowlist). Locale-sensitive builtins
650 # (localeCompare) are deliberately excluded to keep the backends isomorphic.
651 # ---------------------------------------------------------------------------
652  
653 # _builtin_name: resolve a `call` callee to its builtin name (e.g.
654 # "Math.max"), or '' when the callee is not an allowlisted builtin reference.
655 9 ▶sub _builtin_name ($callee) {
Subroutine _builtin_name: called CC=12 SCAR=30.4
656 9 ▶ return '' unless ref $callee eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callee eq "HASH" 0 9 9
657 9 ▶ my $kind = $callee->{kind} // '';
Condition50%1/2
$callee->{"kind"} // ""
l!l
90
MC/DC0%0/1
$callee->{"kind"} // ""
$callee->{"kind"}
Truth table50%1/2
A
A= $callee->{"kind"}
Aresult
11
00
658 9 ▶ if ($kind eq 'identifier') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "identifier") 1 8 9
659 1 ▶ return $callee->{name} // '';
Condition50%1/2
$callee->{"name"} // ""
l!l
10
MC/DC0%0/1
$callee->{"name"} // ""
$callee->{"name"}
Truth table50%1/2
A
A= $callee->{"name"}
Aresult
11
00
660 }
661 8 ▶ if ($kind eq 'member' && !$callee->{computed}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "member" and not $callee->{"computed"}) 8 0 8
Condition33%1/3
$kind eq "member" and not $callee->{"computed"}
!ll&&!rl&&r
008
MC/DC0%0/2
$kind eq "member" and not $callee->{"computed"}
$kind eq "member" not $callee->{"computed"}
Truth table33%1/3
A and not(B)
A= $kind eq "member"B= not $callee->{"computed"}
ABresult
0X0
100
111
662 8 my $obj = $callee->{object};
663 8 ▶ return '' unless ref $obj eq 'HASH' && ($obj->{kind} // '') eq 'identifier';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj eq "HASH" and ($obj->{"kind"} // "") eq "identifier" 0 8 8
Condition40%2/5
ref $obj eq "HASH" and ($obj->{"kind"} // "") eq "identifier"
!ll&&!rl&&r
008
$obj->{"kind"} // ""
l!l
80
MC/DC0%0/2
ref $obj eq "HASH" and ($obj->{"kind"} // "") eq "identifier"
ref $obj eq "HASH" $obj->{"kind"}
Truth table33%1/3
A and B
A= ref $obj eq "HASH"B= $obj->{"kind"}
ABresult
0X0
100
111
664 8 ▶ return ($obj->{name} // '') . '.' . ($callee->{property} // '');
Condition50%2/4
$obj->{"name"} // ""
l!l
80
$callee->{"property"} // ""
l!l
80
MC/DC0%0/1
$obj->{"name"} // ""
$obj->{"name"}
MC/DC0%0/1
$callee->{"property"} // ""
$callee->{"property"}
Truth table50%1/2
A
A= $obj->{"name"}
Aresult
11
00
Truth table50%1/2
A
A= $callee->{"property"}
Aresult
11
00
665 }
666 0 return '';
667 }
668  
669 # _math_round: half rounds toward +Infinity (JS Math.round: 2.5→3, -2.5→-2),
670 # matching the existing round helper rather than half-away-from-zero.
671 0 ▶sub _math_round ($n) {
Subroutine _math_round: not called CC=1 SCAR=6.9
672 0 return POSIX::floor($n + 0.5);
673 }
674  
675 13 ▶sub _call_builtin ($name, $args) {
Subroutine _call_builtin: called CC=18 SCAR=40.7
676 # An omitted argument is JS `undefined`.
677 13 ▶ my $arg = sub ($i) { $i < @$args ? $args->[$i] : $UNDEF };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$i < @$args ? : 9 0 9
678 13 ▶ if ($name eq 'Math.max') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "Math.max") 0 13 13
679 0 my $m = -(9**9**9); # JS Math.max() with no args is -Infinity
680 0 for my $a (@$args) {
681 0 my $n = _to_number($a);
682 0 ▶ return $n if $n != $n; # any NaN argument ⇒ NaN (JS / Go)
Branch: 1 branch
BranchTrueFalseTotal
if $n != $n 0 0 0
683 0 ▶ $m = $n if $n > $m;
Branch: 1 branch
BranchTrueFalseTotal
if $n > $m 0 0 0
684 }
685 0 return $m;
686 }
687 13 ▶ if ($name eq 'Math.min') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "Math.min") 0 13 13
688 0 my $m = 9**9**9; # JS Math.min() with no args is +Infinity
689 0 for my $a (@$args) {
690 0 my $n = _to_number($a);
691 0 ▶ return $n if $n != $n; # any NaN argument ⇒ NaN (JS / Go)
Branch: 1 branch
BranchTrueFalseTotal
if $n != $n 0 0 0
692 0 ▶ $m = $n if $n < $m;
Branch: 1 branch
BranchTrueFalseTotal
if $n < $m 0 0 0
693 }
694 0 return $m;
695 }
696 13 ▶ return abs(_to_number($arg->(0))) if $name eq 'Math.abs';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "Math.abs" 8 5 13
697 5 ▶ return POSIX::floor(_to_number($arg->(0))) if $name eq 'Math.floor';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "Math.floor" 0 5 5
698 5 ▶ return POSIX::ceil(_to_number($arg->(0))) if $name eq 'Math.ceil';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "Math.ceil" 0 5 5
699 5 ▶ return _math_round(_to_number($arg->(0))) if $name eq 'Math.round';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "Math.round" 0 5 5
700 # `String()` / `Number()` with no argument are "" / 0; `String(undefined)`
701 # is "undefined" and `Number(undefined)` NaN.
702 5 ▶ return @$args ? _to_string($args->[0]) : '' if $name eq 'String';
Branch: 2 branches
BranchTrueFalseTotal
if $name eq "String" 2 3 5
@$args ? : 1 1 2
703 3 ▶ return @$args ? _to_number($args->[0]) : 0 if $name eq 'Number';
Branch: 2 branches
BranchTrueFalseTotal
if $name eq "Number" 2 1 3
@$args ? : 1 1 2
704 1 ▶ return _bool(_truthy($arg->(0))) if $name eq 'Boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "Boolean" 1 0 1
705 # Any other callee is outside the subset (refused upstream).
706 0 return undef;
707 }
708  
709 # ---------------------------------------------------------------------------
710 # Member / index access
711 # ---------------------------------------------------------------------------
712  
713 # _read_property: JS `obj.key`. A key the object does not have, and any read
714 # of a receiver with no such property (a nil, a number), is `undefined`.
715 110 ▶sub _read_property ($obj, $key) {
Subroutine _read_property: called CC=9 SCAR=22.3
716 110 ▶ return $UNDEF if _is_nullish($obj);
Branch: 1 branch
BranchTrueFalseTotal
if _is_nullish($obj) 0 110 110
717 110 ▶ if (ref $obj eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq "HASH") 106 4 110
718 106 ▶ return exists $obj->{$key} ? $obj->{$key} : $UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{$key} ? : 104 2 106
719 }
720 4 ▶ if (ref $obj eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq "ARRAY") 2 2 4
721 2 ▶ return $key eq 'length' ? scalar(@$obj) : $UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
$key eq 'length' ? : 2 0 2
722 }
723 2 ▶ return $UNDEF if ref $obj;
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj 0 2 2
724 # `.length` is a string property only — a numeric scalar (123) has no
725 # `.length` in the subset (JS `(123).length` is undefined), so guard on
726 # _is_string rather than coercing the number to a string. Matches the
727 # Go evaluator (numbers fall through to nil there).
728 2 ▶ return _codepoint_length($obj) if $key eq 'length' && _is_string($obj);
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "length" and _is_string($obj) 1 1 2
Condition66%2/3
$key eq "length" and _is_string($obj)
!ll&&!rl&&r
011
MC/DC50%1/2
$key eq "length" and _is_string($obj)
$key eq "length" _is_string($obj)
Truth table66%2/3
A and B
A= $key eq "length"B= _is_string($obj)
ABresult
0X0
100
111
729 1 return $UNDEF;
730 }
731  
732 # _read_index: JS `obj[index]`, and the template helper `BarefootJS::get`
733 # (which delegates here, so a template read and a callback read cannot
734 # disagree on a key). The key goes through ToPropertyKey (`_to_string`:
735 # `undef` is "null", a JSON boolean "true" / "false", `-0` is "0", `1.0` is
736 # "1"). An array, and a string, are read only through a canonical array
737 # index: "1" reads element 1, while "01", "1e0", "-0", "1.1" and "-1" are
738 # ordinary property names and read `undef`. A string reads one UTF-16 code
739 # unit. A hash reads its own key (spec/js-primitive-semantics.md,
740 # "ToPropertyKey and index read"). A key the receiver does not have, and any
741 # read of a receiver with no properties, is `undefined` (`UNDEF`).
742 48 ▶sub _read_index ($obj, $index) {
Subroutine _read_index: called CC=9 SCAR=22.1
743 48 ▶ return $UNDEF if _is_nullish($obj);
Branch: 1 branch
BranchTrueFalseTotal
if _is_nullish($obj) 2 46 48
744 46 my $key = _to_string($index);
745 46 ▶ if (ref $obj eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq "HASH") 11 35 46
746 11 ▶ return exists $obj->{$key} ? $obj->{$key} : $UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{$key} ? : 6 5 11
747 }
748 35 ▶ return $UNDEF unless $key =~ /\A(?:0|[1-9][0-9]*)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /\A(?:0|[1-9][0-9]*)\z/ 3 32 35
749 32 ▶ if (ref $obj eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq "ARRAY") 4 28 32
750 4 ▶ return $key < @$obj ? $obj->[$key] : $UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
$key < @$obj ? : 2 2 4
751 }
752 28 ▶ return $UNDEF if ref $obj || !_is_string($obj);
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj or not _is_string($obj) 0 28 28
Condition33%1/3
ref $obj or not _is_string($obj)
l!l&&r!l&&!r
0028
MC/DC0%0/2
ref $obj or not _is_string($obj)
ref $obj not _is_string($obj)
Truth table33%1/3
A or not(B)
A= ref $objB= not _is_string($obj)
ABresult
1X1
011
000
753 28 return _utf16_unit_at($obj, $key);
754 }
755  
756 # _utf16_unit_at: the UTF-16 code unit of string $s at index $i, as a
757 # one-character string, or `undefined` past the end. A unit that is one half of
758 # a surrogate pair reads as U+FFFD: a lone surrogate cannot be written out
759 # as UTF-8 (spec/js-primitive-semantics.md, "Out of scope"). A string
760 # without Perl's UTF8 flag holds UTF-8 bytes, so a decoded copy is iterated
761 # (as `_codepoint_length` does): otherwise `"\xc3\xa9x"` would read one byte
762 # per index instead of `é`, `x`.
763 28 ▶sub _utf16_unit_at ($s, $i) {
Subroutine _utf16_unit_at: called CC=6 SCAR=17.9
764 28 ▶ unless (utf8::is_utf8($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (utf8::is_utf8($s)) 14 14 28
765 14 utf8::decode($s); # no-op on invalid-UTF-8 input
766 }
767 28 my $pos = 0;
768 28 for my $ch (split //, $s) {
769 44 ▶ my $width = ord($ch) > 0xFFFF ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ord $ch > 65535 ? : 16 28 44
770 44 ▶ if ($i < $pos + $width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $pos + $width) 20 24 44
771 20 ▶ return $width == 1 ? $ch : "\x{FFFD}";
Branch: 1 branch
BranchTrueFalseTotal
$width == 1 ? : 12 8 20
772 }
773 24 $pos += $width;
774 }
775 8 return $UNDEF;
776 }
777  
778 # ---------------------------------------------------------------------------
779 # Evaluator-driven higher-order folds (the generalization of bf_reduce /
780 # bf_sort onto the evaluator) — the runtime half both Perl backends share.
781 # ---------------------------------------------------------------------------
782  
783 # fold($items, $body, $acc_name, $item_name, $init, $direction, $base_env)
784 #
785 # Fold an arrayref into a value via the evaluator. The reducer $body is a
786 # pure ParsedExpr node evaluated against `{$acc_name => acc, $item_name =>
787 # item}` plus the captured free vars in $base_env per element; $init seeds the
788 # accumulator and $direction is "left" (reduce) or "right" (reduceRight).
789 # Generalizes bf_reduce — any reducer body, not just the +/* arithmetic
790 # catalogue, and acc may appear anywhere. $base_env is optional; the
791 # acc/item keys shadow any same-named base key. Mirrors Go's FoldEval.
792 7 ▶sub fold ($items, $body, $acc_name, $item_name, $init, $direction = 'left', $base_env = undef) {
Subroutine fold: called CC=8 SCAR=20.9
Pod undocumented
793 7 ▶ my @arr = ref $items eq 'ARRAY' ? @$items : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq 'ARRAY' ? : 7 0 7
794 7 ▶ @arr = reverse @arr if ($direction // '') eq 'right';
Branch: 1 branch
BranchTrueFalseTotal
if ($direction // "") eq "right" 2 5 7
Condition50%1/2
$direction // ""
l!l
70
MC/DC0%0/1
$direction // ""
$direction
Truth table50%1/2
A
A= $direction
Aresult
11
00
795 # Seed the env from the captured free vars once; acc / item are
796 # overwritten each iteration (constant base keys carry through).
797 7 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 4 3 7
798 7 my $acc = $init;
799 7 for my $item (@arr) {
800 20 $env{$acc_name} = $acc;
801 20 $env{$item_name} = $item;
802 20 $acc = evaluate($body, \%env);
803 }
804 7 return $acc;
805 }
806  
807 # sort_by($items, $cmp, $param_a, $param_b, $base_env)
808 #
809 # Return a new arrayref ordered by a ParsedExpr comparator $cmp evaluated
810 # against `{$param_a => a, $param_b => b}` plus the captured free vars in
811 # $base_env to a number (negative / zero / positive, like a JS comparator).
812 # Generalizes bf_sort — any comparator body. $base_env is optional. Stable
813 # and non-mutating. Mirrors Go's SortEval.
814 # JS moves every `undefined` element to the end without handing it to the
815 # comparator.
816 9 ▶sub sort_by ($items, $cmp, $param_a, $param_b, $base_env = undef) {
Subroutine sort_by: called CC=7 SCAR=19.5
Pod undocumented
817 # Non-array receiver → empty arrayref, matching the nil-tolerant
818 # BarefootJS->sort helper convention (and avoiding an undef-deref footgun
819 # for callers that use the result as an arrayref). Value-compatible with
820 # the Go SortEval, whose nil slice iterates as empty too.
821 9 ▶ return [] unless ref $items eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $items eq "ARRAY" 2 7 9
822 7 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 3 4 7
823 # Decorate each element with its original index and tie-break on it when
824 # the comparator returns 0, so stability is explicit and independent of
825 # the `sort` pragma / build (portable to the declared minimum Perl, and
826 # matching Go's sort.SliceStable).
827 7 my @defined = grep { !_is_undef($_) } @$items;
828 7 my @tail = grep { _is_undef($_) } @$items;
829 7 my @decorated = map { [ $_, $defined[$_] ] } 0 .. $#defined;
830 my @sorted = sort {
831 7 $env{$param_a} = $a->[1];
832 21 $env{$param_b} = $b->[1];
833 21 my $c = _to_number(evaluate($cmp, \%env));
834 # Explicit sign test rather than `<=> 0`: a NaN comparator result
835 # warns / is undefined under `<=>`, whereas `< 0` / `> 0` are both
836 # false for NaN, yielding 0 (no reordering) — matching JS (NaN
837 # comparator ⇒ keep order) and the Go SortEval sign test. The
838 # original-index tie-break then preserves input order for equal keys.
839 21 ▶ ($c < 0 ? -1 : $c > 0 ? 1 : 0) || ($a->[0] <=> $b->[0])
Branch: 2 branches
BranchTrueFalseTotal
$c < 0 ? : 8 13 21
$c > 0 ? : 9 4 13
Condition66%2/3
($c < 0 ? -1 : ($c > 0 ? 1 : 0)) || $BarefootJS::Evaluator::a->[0] <=> $BarefootJS::Evaluator::b->[0]
l!l&&r!l&&!r
1740
MC/DC0%0/2
($c < 0 ? -1 : ($c > 0 ? 1 : 0)) || $BarefootJS::Evaluator::a->[0] <=> $BarefootJS::Evaluator::b->[0]
($c < 0 ? -1 : ($c > 0 ? 1 : 0)) $BarefootJS::Evaluator::a->[0] <=> $BarefootJS::Evaluator::b->[0]
Truth table66%2/3
A || B
A= ($c < 0 ? -1 : ($c > 0 ? 1 : 0))B= $BarefootJS::Evaluator::a->[0] <=> $BarefootJS::Evaluator::b->[0]
ABresult
1X1
011
000
840 } @decorated;
841 7 return [ (map { $_->[1] } @sorted), @tail ];
842 }
843  
844 # JSON entry points for the adapters: decode the callback body once, then fold /
845 # sort. Mirror the Go `bf_reduce_eval` / `bf_sort_eval` template funcs, which the
846 # adapters emit with a serialized-ParsedExpr body argument.
847 3 ▶sub fold_json ($items, $body_json, $acc_name, $item_name, $init, $direction = 'left', $base_env = undef) {
Subroutine fold_json: called CC=3 SCAR=11.0
Pod undocumented
848 3 require JSON::PP;
849 3 return fold($items, JSON::PP->new->decode($body_json), $acc_name, $item_name, $init, $direction, $base_env);
850 }
851  
852 2 ▶sub sort_by_json ($items, $cmp_json, $param_a, $param_b, $base_env = undef) {
Subroutine sort_by_json: called CC=2 SCAR=6.9
Pod undocumented
853 2 require JSON::PP;
854 2 return sort_by($items, JSON::PP->new->decode($cmp_json), $param_a, $param_b, $base_env);
855 }
856  
857 # ---------------------------------------------------------------------------
858 # Higher-order predicates (#2018, P2) — the generalization of bf_filter /
859 # bf_find / bf_find_index / bf_every / bf_some onto the evaluator. The
860 # predicate $pred is a pure ParsedExpr evaluated against `{$param => item}`
861 # plus the captured free vars in $base_env per element, lifting the
862 # field-equality / truthiness restriction to any pure predicate body. Each
863 # mirrors the corresponding Go helper (FilterEval / EveryEval / SomeEval /
864 # FindEval / FindIndexEval). $base_env is optional.
865 # ---------------------------------------------------------------------------
866  
867 # filter — new arrayref of the elements the predicate keeps. Non-array receiver
868 # → empty arrayref (the BarefootJS->filter nil-tolerant convention).
869 4 ▶sub filter ($items, $pred, $param, $base_env = undef) {
Subroutine filter: called CC=6 SCAR=17.9
Pod undocumented
870 4 ▶ return [] unless ref $items eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $items eq "ARRAY" 0 4 4
871 4 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 2 2 4
872 4 my @out;
873 4 for my $item (@$items) {
874 12 $env{$param} = $item;
875 12 ▶ push @out, $item if _truthy(evaluate($pred, \%env));
Branch: 1 branch
BranchTrueFalseTotal
if _truthy(evaluate($pred, \%env)) 6 6 12
876 }
877 4 return \@out;
878 }
879  
880 # every — 1 iff the predicate holds for every element (vacuously 1 for an empty
881 # receiver, like JS).
882 3 ▶sub every ($items, $pred, $param, $base_env = undef) {
Subroutine every: called CC=6 SCAR=18.6
Pod undocumented
883 3 ▶ my @arr = ref $items eq 'ARRAY' ? @$items : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq 'ARRAY' ? : 3 0 3
884 3 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 0 3 3
885 3 for my $item (@arr) {
886 2 $env{$param} = $item;
887 2 ▶ return 0 unless _truthy(evaluate($pred, \%env));
Branch: 1 branch
BranchTrueFalseTotal
unless _truthy(evaluate($pred, \%env)) 2 0 2
888 }
889 1 return 1;
890 }
891  
892 # some — 1 iff the predicate holds for any element (0 for an empty receiver).
893 3 ▶sub some ($items, $pred, $param, $base_env = undef) {
Subroutine some: called CC=6 SCAR=18.1
Pod undocumented
894 3 ▶ my @arr = ref $items eq 'ARRAY' ? @$items : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq 'ARRAY' ? : 3 0 3
895 3 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 0 3 3
896 3 for my $item (@arr) {
897 4 $env{$param} = $item;
898 4 ▶ return 1 if _truthy(evaluate($pred, \%env));
Branch: 1 branch
BranchTrueFalseTotal
if _truthy(evaluate($pred, \%env)) 2 2 4
899 }
900 1 return 0;
901 }
902  
903 # find — first matching element, or `undefined`. $forward false searches from
904 # the end (findLast).
905 4 ▶sub find ($items, $pred, $param, $forward = 1, $base_env = undef) {
Subroutine find: called CC=8 SCAR=20.9
Pod undocumented
906 4 ▶ my @arr = ref $items eq 'ARRAY' ? @$items : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq 'ARRAY' ? : 4 0 4
907 4 ▶ @arr = reverse @arr unless $forward;
Branch: 1 branch
BranchTrueFalseTotal
unless $forward 1 3 4
908 4 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 0 4 4
909 4 for my $item (@arr) {
910 5 $env{$param} = $item;
911 5 ▶ return $item if _truthy(evaluate($pred, \%env));
Branch: 1 branch
BranchTrueFalseTotal
if _truthy(evaluate($pred, \%env)) 3 2 5
912 }
913 1 return $UNDEF;
914 }
915  
916 # find_index — index of the first matching element, or -1. $forward false →
917 # findLastIndex (the index is into the original array either way).
918 5 ▶sub find_index ($items, $pred, $param, $forward = 1, $base_env = undef) {
Subroutine find_index: called CC=8 SCAR=20.8
Pod undocumented
919 5 ▶ my @arr = ref $items eq 'ARRAY' ? @$items : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq 'ARRAY' ? : 5 0 5
920 5 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 1 4 5
921 5 ▶ my @idx = $forward ? ( 0 .. $#arr ) : reverse( 0 .. $#arr );
Branch: 1 branch
BranchTrueFalseTotal
$forward ? : 3 2 5
922 5 for my $i (@idx) {
923 7 $env{$param} = $arr[$i];
924 7 ▶ return $i if _truthy(evaluate($pred, \%env));
Branch: 1 branch
BranchTrueFalseTotal
if _truthy(evaluate($pred, \%env)) 3 4 7
925 }
926 2 return -1;
927 }
928  
929 # flat_map — project each element through $proj (a pure ParsedExpr) and flatten
930 # the results one level. A projection yielding an arrayref contributes its
931 # elements; any other value contributes itself (JS `.flatMap` keeps a non-array
932 # return as a single element). Generalizes bf->flat_map / flat_map_tuple to any
933 # pure projection. Mirrors Go's FlatMapEval. $base_env is optional.
934 3 ▶sub flat_map ($items, $proj, $param, $base_env = undef) {
Subroutine flat_map: called CC=6 SCAR=18.7
Pod undocumented
935 3 ▶ my @arr = ref $items eq 'ARRAY' ? @$items : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq 'ARRAY' ? : 3 0 3
936 3 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 0 3 3
937 3 my @out;
938 3 for my $item (@arr) {
939 6 $env{$param} = $item;
940 6 my $v = evaluate($proj, \%env);
941 6 ▶ if (ref $v eq 'ARRAY') { push @out, @$v }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 6 0 6
942 0 else { push @out, $v }
943 }
944 3 return \@out;
945 }
946  
947 # map_items — project each element through $proj (a pure ParsedExpr), keeping
948 # each result as one element (no flatten): JS value-producing `.map(cb)`
949 # (#2073). Named map_items (not `map`) so the Perl builtin stays unshadowed.
950 # Mirrors Go's MapEval. $base_env is optional.
951 4 ▶sub map_items ($items, $proj, $param, $base_env = undef) {
Subroutine map_items: called CC=5 SCAR=16.3
Pod undocumented
952 4 ▶ my @arr = ref $items eq 'ARRAY' ? @$items : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq 'ARRAY' ? : 4 0 4
953 4 ▶ my %env = $base_env ? %$base_env : ();
Branch: 1 branch
BranchTrueFalseTotal
$base_env ? : 0 4 4
954 4 my @out;
955 4 for my $item (@arr) {
956 7 $env{$param} = $item;
957 7 push @out, evaluate($proj, \%env);
958 }
959 4 return \@out;
960 }
961  
962 # ---------------------------------------------------------------------------
963 # JSON-string seams — the adapters emit `bf->filter_eval($recv, '<json>', …)`;
964 # the predicate body arrives as a JSON string here, decoded then handed to the
965 # helper above (mirroring fold_json / sort_by_json).
966 # ---------------------------------------------------------------------------
967  
968 1 ▶sub filter_json ($items, $pred_json, $param, $base_env = undef) {
Subroutine filter_json: called CC=2 SCAR=6.9
Pod undocumented
969 1 require JSON::PP;
970 1 return filter($items, JSON::PP->new->decode($pred_json), $param, $base_env);
971 }
972  
973 1 ▶sub every_json ($items, $pred_json, $param, $base_env = undef) {
Subroutine every_json: called CC=2 SCAR=6.9
Pod undocumented
974 1 require JSON::PP;
975 1 return every($items, JSON::PP->new->decode($pred_json), $param, $base_env);
976 }
977  
978 1 ▶sub some_json ($items, $pred_json, $param, $base_env = undef) {
Subroutine some_json: called CC=2 SCAR=6.9
Pod undocumented
979 1 require JSON::PP;
980 1 return some($items, JSON::PP->new->decode($pred_json), $param, $base_env);
981 }
982  
983 1 ▶sub find_json ($items, $pred_json, $param, $forward = 1, $base_env = undef) {
Subroutine find_json: called CC=3 SCAR=11.0
Pod undocumented
984 1 require JSON::PP;
985 1 return find($items, JSON::PP->new->decode($pred_json), $param, $forward, $base_env);
986 }
987  
988 1 ▶sub find_index_json ($items, $pred_json, $param, $forward = 1, $base_env = undef) {
Subroutine find_index_json: called CC=3 SCAR=11.0
Pod undocumented
989 1 require JSON::PP;
990 1 return find_index($items, JSON::PP->new->decode($pred_json), $param, $forward, $base_env);
991 }
992  
993 1 ▶sub flat_map_json ($items, $proj_json, $param, $base_env = undef) {
Subroutine flat_map_json: called CC=2 SCAR=6.9
Pod undocumented
994 1 require JSON::PP;
995 1 return flat_map($items, JSON::PP->new->decode($proj_json), $param, $base_env);
996 }
997  
998 1 ▶sub map_json ($items, $proj_json, $param, $base_env = undef) {
Subroutine map_json: called CC=2 SCAR=6.9
Pod undocumented
999 1 require JSON::PP;
1000 1 return map_items($items, JSON::PP->new->decode($proj_json), $param, $base_env);
1001 }
1002  
1003 18 1;
« lib/BarefootJS.pm ↑ Summary blib/lib/BarefootJS/DevReload.pm »