include/jsf_interp.h

filter: Statementstmt 99.4% 384 / 386 Branchbran 80.7% 575 / 712 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 87.3% 959 / 1098 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/jsf_compiled.h ↑ Summary include/jsf_arena.h »
1 #ifndef JSF_INTERP_H
2 #define JSF_INTERP_H
3  
4 /* The validation engine. is_valid() runs with ctx->errors == NULL: fail-fast,
5 * no instance-location bookkeeping, zero allocation on the valid path. validate()
6 * / errors() run with a sink AV and a reused JSON-Pointer buffer (ctx->iloc),
7 * collecting every error with instanceLocation / keyword / schemaLocation.
8 * Combinators (anyOf/oneOf/not/if) probe their branches with a throwaway ctx so
9 * a branch that is *allowed* to fail does not leak errors into the sink.
10 *
11 * Needs jsf_arena.h, jsf_ir.h, jsf_types.h, jsf_compiled.h, jsf_err.h + Perl. */
12  
13 #include <math.h>
14  
15 #define JSF_MAX_DEPTH 1024
16  
17 static int jsf_validate(pTHX_ jsf_compiled_t *C, uint32_t off, SV *data, jsf_ctx_t *ctx);
18  
19 /* ---- annotation collector for unevaluatedProperties/Items --------------- *
20 * Per data-instance: the set of property names / item indices that some
21 * keyword or successful in-place applicator has already evaluated. Only used
22 * when the schema declares unevaluated* (C->has_unevaluated); NULL otherwise. */
23 typedef struct jsf_annot { HV *props; HV *items; int all_items; } jsf_annot;
24  
25 1379 static jsf_annot *jsf_annot_new(pTHX) {
26 1379 jsf_annot *a = (jsf_annot *)malloc(sizeof *a);
27 1379 ▶ if (!a) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!a) return NULL; 0 1379 1379
28 1379 a->props = newHV(); a->items = newHV(); a->all_items = 0;
29 1379 return a;
30 }
31 1379 static void jsf_annot_free(pTHX_ jsf_annot *a) {
32 1379 ▶ if (!a) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!a) return; 0 1379 1379
33 1379 SvREFCNT_dec((SV *)a->props); SvREFCNT_dec((SV *)a->items); free(a);
34 }
35 425 static void jsf_annot_merge(pTHX_ jsf_annot *dst, jsf_annot *src) {
36 HE *he;
37 425 ▶ if (!dst || !src) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!dst || !src) return; 425 0 425
if (!dst || !src) return; 0 425 425
38 622 ▶ hv_iterinit(src->props); while ((he = hv_iternext(src->props))) { STRLEN kl; char *k = HePV(he, kl); (void)hv_store(dst->props, k, kl, &PL_sv_yes, 0); }
Branch: 2 branches
BranchTrueFalseTotal
hv_iterinit(src->props); while ((he = hv_iternext(src->props))) { STRLEN kl; char *k = HePV(he, kl); (void)hv_store(dst->props, k, kl, &PL_sv_yes, 0); } 0 197 197
hv_iterinit(src->props); while ((he = hv_iternext(src->props))) { STRLEN kl; char *k = HePV(he, kl); (void)hv_store(dst->props, k, kl, &PL_sv_yes, 0); } 197 425 622
39 528 ▶ hv_iterinit(src->items); while ((he = hv_iternext(src->items))) { STRLEN kl; char *k = HePV(he, kl); (void)hv_store(dst->items, k, kl, &PL_sv_yes, 0); }
Branch: 2 branches
BranchTrueFalseTotal
hv_iterinit(src->items); while ((he = hv_iternext(src->items))) { STRLEN kl; char *k = HePV(he, kl); (void)hv_store(dst->items, k, kl, &PL_sv_yes, 0); } 0 103 103
hv_iterinit(src->items); while ((he = hv_iternext(src->items))) { STRLEN kl; char *k = HePV(he, kl); (void)hv_store(dst->items, k, kl, &PL_sv_yes, 0); } 103 425 528
40 425 dst->all_items |= src->all_items;
41 }
42 755 static void jsf_annot_add_key(pTHX_ jsf_annot *a, const char *k, STRLEN kl) {
43 755 ▶ if (a) (void)hv_store(a->props, k, kl, &PL_sv_yes, 0);
Branch: 1 branch
BranchTrueFalseTotal
if (a) (void)hv_store(a->props, k, kl, &PL_sv_yes, 0); 253 502 755
44 755 }
45 352 static void jsf_annot_add_idx(pTHX_ jsf_annot *a, IV i) {
46 352 ▶ if (a) { char b[24]; int n = (int)my_snprintf(b, sizeof b, "%" IVdf, i); (void)hv_store(a->items, b, n, &PL_sv_yes, 0); }
Branch: 1 branch
BranchTrueFalseTotal
if (a) { char b[24]; int n = (int)my_snprintf(b, sizeof b, "%" IVdf, i); (void)hv_store(a->items, b, n, &PL_sv_yes, 0); } 176 176 352
47 352 }
48 137 static int jsf_annot_has_idx(pTHX_ jsf_annot *a, IV i) {
49 char b[24]; int n;
50 137 ▶ if (!a) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!a) return 0; 0 137 137
51 137 ▶ if (a->all_items) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (a->all_items) return 1; 13 124 137
52 124 n = (int)my_snprintf(b, sizeof b, "%" IVdf, i);
53 124 return hv_exists(a->items, b, n);
54 }
55  
56 /* ---- JSON value equality (const/enum, uniqueItems) ---------------------- */
57 518 static int jsf_json_equal(pTHX_ SV *a, SV *b) {
58 518 unsigned ta = jsf_classify_type(aTHX_ a);
59 518 unsigned tb = jsf_classify_type(aTHX_ b);
60 518 ▶ if ((ta & JSF_T_NUMBER) && (tb & JSF_T_NUMBER))
Branch: 2 branches
BranchTrueFalseTotal
if ((ta & JSF_T_NUMBER) && (tb & JSF_T_NUMBER)) 176 342 518
if ((ta & JSF_T_NUMBER) && (tb & JSF_T_NUMBER)) 134 42 176
61 134 return jsf__nv_of(aTHX_ a) == jsf__nv_of(aTHX_ b);
62 384 ▶ if ((ta & JSF_T_STRING) && (tb & JSF_T_STRING)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((ta & JSF_T_STRING) && (tb & JSF_T_STRING)) { 187 197 384
if ((ta & JSF_T_STRING) && (tb & JSF_T_STRING)) { 179 8 187
63 179 ▶ STRLEN la, lb; const char *sa = SvPV_const(a, la); const char *sb = SvPV_const(b, lb);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN la, lb; const char *sa = SvPV_const(a, la); const char *sb = SvPV_const(b, lb); 179 0 179
64 179 ▶ return la == lb && memcmp(sa, sb, la) == 0;
Branch: 2 branches
BranchTrueFalseTotal
return la == lb && memcmp(sa, sb, la) == 0; 167 12 179
return la == lb && memcmp(sa, sb, la) == 0; 99 68 167
65 }
66 205 ▶ if ((ta & JSF_T_BOOLEAN) && (tb & JSF_T_BOOLEAN)) return (SvTRUE(a) ? 1 : 0) == (SvTRUE(b) ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
if ((ta & JSF_T_BOOLEAN) && (tb & JSF_T_BOOLEAN)) return (SvTRUE(a) ? 1 : 0) == (SvTRUE(b) ? 1 : 0); 52 153 205
if ((ta & JSF_T_BOOLEAN) && (tb & JSF_T_BOOLEAN)) return (SvTRUE(a) ? 1 : 0) == (SvTRUE(b) ? 1 : 0); 24 28 52
67 181 ▶ if ((ta & JSF_T_NULL) && (tb & JSF_T_NULL)) return 1;
Branch: 2 branches
BranchTrueFalseTotal
if ((ta & JSF_T_NULL) && (tb & JSF_T_NULL)) return 1; 10 171 181
if ((ta & JSF_T_NULL) && (tb & JSF_T_NULL)) return 1; 2 8 10
68 179 ▶ if ((ta & JSF_T_ARRAY) && (tb & JSF_T_ARRAY)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((ta & JSF_T_ARRAY) && (tb & JSF_T_ARRAY)) { 40 139 179
if ((ta & JSF_T_ARRAY) && (tb & JSF_T_ARRAY)) { 32 8 40
69 32 AV *aa = (AV *)SvRV(a), *ab = (AV *)SvRV(b);
70 32 SSize_t i, na = av_len(aa) + 1;
71 32 ▶ if (na != av_len(ab) + 1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (na != av_len(ab) + 1) return 0; 1 31 32
72 42 ▶ for (i = 0; i < na; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < na; i++) { 30 12 42
73 30 SV **x = av_fetch(aa, i, 0), **y = av_fetch(ab, i, 0);
74 30 ▶ if (!jsf_json_equal(aTHX_ x ? *x : &PL_sv_undef, y ? *y : &PL_sv_undef)) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!jsf_json_equal(aTHX_ x ? *x : &PL_sv_undef, y ? *y : &PL_sv_undef)) return 0; 30 0 30
if (!jsf_json_equal(aTHX_ x ? *x : &PL_sv_undef, y ? *y : &PL_sv_undef)) return 0; 30 0 30
if (!jsf_json_equal(aTHX_ x ? *x : &PL_sv_undef, y ? *y : &PL_sv_undef)) return 0; 19 11 30
75 }
76 12 return 1;
77 }
78 147 ▶ if ((ta & JSF_T_OBJECT) && (tb & JSF_T_OBJECT)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((ta & JSF_T_OBJECT) && (tb & JSF_T_OBJECT)) { 53 94 147
if ((ta & JSF_T_OBJECT) && (tb & JSF_T_OBJECT)) { 32 21 53
79 32 HV *ha = (HV *)SvRV(a), *hb = (HV *)SvRV(b); HE *he;
80 32 ▶ if (HvKEYS(ha) != HvKEYS(hb)) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (HvKEYS(ha) != HvKEYS(hb)) return 0; 0 32 32
if (HvKEYS(ha) != HvKEYS(hb)) return 0; 0 32 32
if (HvKEYS(ha) != HvKEYS(hb)) return 0; 2 30 32
81 30 hv_iterinit(ha);
82 49 ▶ while ((he = hv_iternext(ha))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(ha))) { 33 16 49
83 33 ▶ STRLEN kl; char *k = HePV(he, kl);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN kl; char *k = HePV(he, kl); 0 33 33
84 33 SV **y = hv_fetch(hb, k, (I32)kl, 0);
85 33 ▶ if (!y || !jsf_json_equal(aTHX_ HeVAL(he), *y)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!y || !jsf_json_equal(aTHX_ HeVAL(he), *y)) return 0; 32 1 33
if (!y || !jsf_json_equal(aTHX_ HeVAL(he), *y)) return 0; 13 19 32
86 }
87 16 return 1;
88 }
89 115 return 0;
90 }
91  
92 /* enum/const under coercion: a string standing in for a number or a
93 * boolean must also compare as one, or "?page=1" passes `type: integer`
94 * and then fails `enum: [1, 2]` on the string it still is. Only the
95 * instance (a) is read across domains - the schema side keeps the type
96 * it declared. */
97 12 static int jsf_json_equal_coerced(pTHX_ SV *a, SV *b) {
98 12 unsigned ta = jsf_classify_type(aTHX_ a);
99 12 unsigned tb = jsf_classify_type(aTHX_ b);
100 12 ▶ if ((ta & JSF_T_STRING) && !(tb & JSF_T_STRING)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((ta & JSF_T_STRING) && !(tb & JSF_T_STRING)) { 10 2 12
if ((ta & JSF_T_STRING) && !(tb & JSF_T_STRING)) { 9 1 10
101 9 ▶ if ((tb & JSF_T_NUMBER) && looks_like_number(a))
Branch: 2 branches
BranchTrueFalseTotal
if ((tb & JSF_T_NUMBER) && looks_like_number(a)) 7 2 9
if ((tb & JSF_T_NUMBER) && looks_like_number(a)) 7 0 7
102 7 return SvNV(a) == jsf__nv_of(aTHX_ b);
103 2 ▶ if (tb & JSF_T_BOOLEAN) {
Branch: 1 branch
BranchTrueFalseTotal
if (tb & JSF_T_BOOLEAN) { 2 0 2
104 2 STRLEN l; const char *s = SvPV_const(a, l);
105 3 ▶ if (l == 4 && memEQ(s, "true", 4)) return SvTRUE(b) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
if (l == 4 && memEQ(s, "true", 4)) return SvTRUE(b) ? 1 : 0; 1 1 2
if (l == 4 && memEQ(s, "true", 4)) return SvTRUE(b) ? 1 : 0; 1 0 1
106 1 ▶ if (l == 5 && memEQ(s, "false", 5)) return SvTRUE(b) ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
if (l == 5 && memEQ(s, "false", 5)) return SvTRUE(b) ? 0 : 1; 1 0 1
if (l == 5 && memEQ(s, "false", 5)) return SvTRUE(b) ? 0 : 1; 1 0 1
107 }
108 }
109 3 return jsf_json_equal(aTHX_ a, b);
110 }
111  
112 /* ---- pattern regex (compiled once, cached) ------------------------------ */
113 110 static REGEXP *jsf_get_regex(pTHX_ jsf_compiled_t *C, uint32_t pat_off) {
114 int i; uint32_t len; const char *p; SV *pat; REGEXP *rx;
115 122 ▶ for (i = 0; i < C->rxn; i++) if (C->rx[i].pat_off == pat_off) return C->rx[i].rx;
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < C->rxn; i++) if (C->rx[i].pat_off == pat_off) return C->rx[i].rx; 86 12 98
for (i = 0; i < C->rxn; i++) if (C->rx[i].pat_off == pat_off) return C->rx[i].rx; 98 24 122
116 24 p = jsf_str_bytes(C->arena, pat_off, &len);
117 24 pat = sv_2mortal(newSVpvn(p, len));
118 24 rx = pregcomp(pat, 0);
119 24 ▶ if (C->rxn == C->rxcap) {
Branch: 1 branch
BranchTrueFalseTotal
if (C->rxn == C->rxcap) { 21 3 24
120 21 ▶ int nc = C->rxcap ? C->rxcap * 2 : 8;
Branch: 1 branch
BranchTrueFalseTotal
int nc = C->rxcap ? C->rxcap * 2 : 8; 0 21 21
121 21 jsf_rxent *nr = (jsf_rxent *)realloc(C->rx, nc * sizeof(jsf_rxent));
122 21 ▶ if (!nr) return rx;
Branch: 1 branch
BranchTrueFalseTotal
if (!nr) return rx; 0 21 21
123 21 C->rx = nr; C->rxcap = nc;
124 }
125 24 C->rx[C->rxn].pat_off = pat_off; C->rx[C->rxn].rx = rx; C->rxn++;
126 24 return rx;
127 }
128  
129 110 static int jsf_rx_match(pTHX_ REGEXP *rx, SV *sv) {
130 STRLEN l; char *s;
131 110 ▶ if (!rx) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (!rx) return 1; 0 110 110
132 110 s = SvPV(sv, l);
133 110 return pregexec(rx, s, s + l, s, 0, sv, 1) ? 1 : 0;
134 }
135  
136 53 static int jsf_find_prop(jsf_proptab *pt, jsf_propent *en, char *base,
137 const char *k, STRLEN kl) {
138 53 int lo = 0, hi = (int)pt->n - 1;
139 93 ▶ while (lo <= hi) {
Branch: 1 branch
BranchTrueFalseTotal
while (lo <= hi) { 67 26 93
140 67 int mid = (lo + hi) >> 1;
141 67 const char *nm = base + en[mid].name_off + sizeof(jsf_str_t);
142 67 uint32_t nl = en[mid].name_len, m = nl < (uint32_t)kl ? nl : (uint32_t)kl;
143 67 int c = memcmp(k, nm, m);
144 67 ▶ if (c == 0) c = ((uint32_t)kl < nl) ? -1 : ((uint32_t)kl > nl ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
if (c == 0) c = ((uint32_t)kl < nl) ? -1 : ((uint32_t)kl > nl ? 1 : 0); 28 39 67
if (c == 0) c = ((uint32_t)kl < nl) ? -1 : ((uint32_t)kl > nl ? 1 : 0); 27 1 28
145 67 ▶ if (c == 0) return mid;
Branch: 1 branch
BranchTrueFalseTotal
if (c == 0) return mid; 27 40 67
146 40 ▶ if (c < 0) hi = mid - 1; else lo = mid + 1;
Branch: 1 branch
BranchTrueFalseTotal
if (c < 0) hi = mid - 1; else lo = mid + 1; 10 30 40
147 }
148 26 return -1;
149 }
150  
151 /* ---- instanceLocation buffer (JSON Pointer, RFC 6901 escaping) ---------- */
152 10 static STRLEN jsf_iloc_push_key(pTHX_ SV *iloc, const char *k, STRLEN kl) {
153 10 STRLEN save = SvCUR(iloc), i; int special = 0;
154 36 ▶ for (i = 0; i < kl; i++) if (k[i] == '~' || k[i] == '/') { special = 1; break; }
Branch: 3 branches
BranchTrueFalseTotal
for (i = 0; i < kl; i++) if (k[i] == '~' || k[i] == '/') { special = 1; break; } 27 1 28
for (i = 0; i < kl; i++) if (k[i] == '~' || k[i] == '/') { special = 1; break; } 1 26 27
for (i = 0; i < kl; i++) if (k[i] == '~' || k[i] == '/') { special = 1; break; } 28 8 36
155 10 sv_catpvn(iloc, "/", 1);
156 10 ▶ if (!special) { sv_catpvn(iloc, k, kl); }
Branch: 1 branch
BranchTrueFalseTotal
if (!special) { sv_catpvn(iloc, k, kl); } 8 2 10
157 8 ▶ else for (i = 0; i < kl; i++) {
Branch: 1 branch
BranchTrueFalseTotal
else for (i = 0; i < kl; i++) { 6 2 8
158 6 ▶ if (k[i] == '~') sv_catpvn(iloc, "~0", 2);
Branch: 1 branch
BranchTrueFalseTotal
if (k[i] == '~') sv_catpvn(iloc, "~0", 2); 1 5 6
159 5 ▶ else if (k[i] == '/') sv_catpvn(iloc, "~1", 2);
Branch: 1 branch
BranchTrueFalseTotal
else if (k[i] == '/') sv_catpvn(iloc, "~1", 2); 1 4 5
160 4 else sv_catpvn(iloc, k + i, 1);
161 }
162 10 return save;
163 }
164 5 static STRLEN jsf_iloc_push_idx(pTHX_ SV *iloc, IV idx) {
165 5 STRLEN save = SvCUR(iloc);
166 5 sv_catpvf(iloc, "/%" IVdf, idx);
167 5 return save;
168 }
169 15 static void jsf_iloc_pop(SV *iloc, STRLEN save) {
170 15 SvCUR_set(iloc, save);
171 15 SvPVX(iloc)[save] = '\0';
172 15 }
173  
174 /* ---- error push (cold path) --------------------------------------------- */
175 15 static void jsf_err_push(pTHX_ jsf_ctx_t *ctx, jsf_compiled_t *C, uint32_t off, const char *kw) {
176 15 jsf_node_t *n = (jsf_node_t *)jsf_arena_ptr(C->arena, off);
177 15 uint32_t sl; const char *sp = jsf_str_bytes(C->arena, n->schema_path_off, &sl);
178 15 HV *e = newHV();
179 15 SV *schemaLoc = newSVpvn(sp, sl);
180 15 sv_catpvs(schemaLoc, "/");
181 15 sv_catpv(schemaLoc, kw);
182 15 (void)hv_stores(e, "instanceLocation", newSVsv(ctx->iloc));
183 15 (void)hv_stores(e, "keyword", newSVpv(kw, 0));
184 15 (void)hv_stores(e, "schemaLocation", schemaLoc);
185 15 (void)hv_stores(e, "message", newSVpvf("failed '%s' constraint", kw));
186 15 av_push(ctx->errors, newRV_noinc((SV *)e));
187 15 }
188  
189 /* coercion (opt-in): which type bits a string can stand in for */
190 16 static unsigned jsf_coerce_bits(pTHX_ uint32_t mask, SV *data, unsigned t) {
191 STRLEN l; const char *s;
192 16 ▶ if (!(t & JSF_T_STRING)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!(t & JSF_T_STRING)) return 0; 0 16 16
193 16 s = SvPV_const(data, l);
194 16 ▶ if ((mask & (JSF_T_NUMBER | JSF_T_INTEGER)) && looks_like_number(data)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((mask & (JSF_T_NUMBER | JSF_T_INTEGER)) && looks_like_number(data)) { 11 5 16
if ((mask & (JSF_T_NUMBER | JSF_T_INTEGER)) && looks_like_number(data)) { 10 1 11
195 10 NV nv = SvNV(data);
196 /* zero fractional part at any magnitude - see jsf_classify_type on
197 * why this is not (NV)(IV)nv */
198 10 ▶ int integral = (nv - nv == 0) && (nv == Perl_floor(nv));
Branch: 2 branches
BranchTrueFalseTotal
int integral = (nv - nv == 0) && (nv == Perl_floor(nv)); 10 0 10
int integral = (nv - nv == 0) && (nv == Perl_floor(nv)); 8 2 10
199 10 ▶ if (mask & JSF_T_NUMBER) return (unsigned)(JSF_T_NUMBER | (integral ? JSF_T_INTEGER : 0));
Branch: 2 branches
BranchTrueFalseTotal
if (mask & JSF_T_NUMBER) return (unsigned)(JSF_T_NUMBER | (integral ? JSF_T_INTEGER : 0)); 1 9 10
if (mask & JSF_T_NUMBER) return (unsigned)(JSF_T_NUMBER | (integral ? JSF_T_INTEGER : 0)); 0 1 1
200 9 ▶ if ((mask & JSF_T_INTEGER) && integral) return JSF_T_NUMBER | JSF_T_INTEGER;
Branch: 2 branches
BranchTrueFalseTotal
if ((mask & JSF_T_INTEGER) && integral) return JSF_T_NUMBER | JSF_T_INTEGER; 9 0 9
if ((mask & JSF_T_INTEGER) && integral) return JSF_T_NUMBER | JSF_T_INTEGER; 8 1 9
201 }
202 7 ▶ if (mask & JSF_T_BOOLEAN) {
Branch: 1 branch
BranchTrueFalseTotal
if (mask & JSF_T_BOOLEAN) { 5 2 7
203 5 ▶ if ((l == 4 && memEQ(s, "true", 4)) || (l == 5 && memEQ(s, "false", 5))) return JSF_T_BOOLEAN;
Branch: 4 branches
BranchTrueFalseTotal
if ((l == 4 && memEQ(s, "true", 4)) || (l == 5 && memEQ(s, "false", 5))) return JSF_T_BOOLEAN; 2 3 5
if ((l == 4 && memEQ(s, "true", 4)) || (l == 5 && memEQ(s, "false", 5))) return JSF_T_BOOLEAN; 0 2 2
if ((l == 4 && memEQ(s, "true", 4)) || (l == 5 && memEQ(s, "false", 5))) return JSF_T_BOOLEAN; 2 1 3
if ((l == 4 && memEQ(s, "true", 4)) || (l == 5 && memEQ(s, "false", 5))) return JSF_T_BOOLEAN; 2 0 2
204 }
205 3 return 0;
206 }
207  
208 /* run a subschema as a boolean probe (no error leakage, no annotations) */
209 246 static int jsf_probe(pTHX_ jsf_compiled_t *C, uint32_t off, SV *data, jsf_ctx_t *parent) {
210 jsf_ctx_t p;
211 246 p.errors = NULL; p.iloc = NULL; p.collect = 0; p.depth = parent->depth; p.ann = NULL;
212 246 p.dynscope = parent->dynscope;
213 246 return jsf_validate(aTHX_ C, off, data, &p);
214 }
215  
216 /* probe that collects annotations into `ann` (for in-place applicators whose
217 * successful branches contribute to the parent's evaluated set) */
218 421 static int jsf_probe_ann(pTHX_ jsf_compiled_t *C, uint32_t off, SV *data, jsf_ctx_t *parent, jsf_annot *ann) {
219 jsf_ctx_t p;
220 421 p.errors = NULL; p.iloc = NULL; p.collect = 0; p.depth = parent->depth; p.ann = ann;
221 421 p.dynscope = parent->dynscope;
222 421 return jsf_validate(aTHX_ C, off, data, &p);
223 }
224  
225 #define JSF_FAIL(kw) do { \
226 if (ctx->errors) jsf_err_push(aTHX_ ctx, C, off, (kw)); \
227 ok = 0; if (!ctx->collect) goto done; \
228 } while (0)
229  
230 /* recurse into a data child (a new instance): keep the instanceLocation in sync
231 * and give the child its own annotation collector. */
232 #define JSF_CHILD(coff, cdata, pushexpr) do { \
233 STRLEN _sav = 0; int _r; jsf_annot *_oa = ctx->ann; \
234 if (ctx->errors) _sav = (pushexpr); \
235 ctx->ann = C->has_unevaluated ? jsf_annot_new(aTHX) : NULL; \
236 _r = jsf_validate(aTHX_ C, (coff), (cdata), ctx); \
237 if (ctx->ann) jsf_annot_free(aTHX_ ctx->ann); \
238 ctx->ann = _oa; \
239 if (ctx->errors) jsf_iloc_pop(ctx->iloc, _sav); \
240 if (!_r) { ok = 0; if (!ctx->collect) goto done; } \
241 } while (0)
242  
243 4098 static int jsf_validate(pTHX_ jsf_compiled_t *C, uint32_t off, SV *data, jsf_ctx_t *ctx) {
244 4098 jsf_arena_t *a = C->arena;
245 4098 jsf_node_t *n = (jsf_node_t *)jsf_arena_ptr(a, off);
246 unsigned t;
247 4098 int ok = 1;
248 4098 HV *filled = NULL; /* apply_defaults working copy (freed at done) */
249 4098 jsf_annot *sink = NULL, *local = NULL; /* evaluated-set (unevaluated*) */
250 4098 int pushed_dyn = 0; /* pushed this resource's base onto the dynamic scope */
251  
252 4098 ▶ if (n->tag == JSF_TAG_TRUE) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (n->tag == JSF_TAG_TRUE) return 1; 310 3788 4098
253 3788 ▶ if (n->tag == JSF_TAG_FALSE) { if (ctx->errors) jsf_err_push(aTHX_ ctx, C, off, "false"); return 0; }
Branch: 2 branches
BranchTrueFalseTotal
if (n->tag == JSF_TAG_FALSE) { if (ctx->errors) jsf_err_push(aTHX_ ctx, C, off, "false"); return 0; } 127 3661 3788
if (n->tag == JSF_TAG_FALSE) { if (ctx->errors) jsf_err_push(aTHX_ ctx, C, off, "false"); return 0; } 0 127 127
254 3661 ▶ if (++ctx->depth > JSF_MAX_DEPTH) { ctx->depth--; return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (++ctx->depth > JSF_MAX_DEPTH) { ctx->depth--; return 0; } 0 3661 3661
255  
256 /* This frame collects its own evaluated set (from its keywords and its
257 * in-place applicators); on success it merges into the caller's set (sink).
258 * A sibling ("cousin") subschema therefore does not see it. */
259 3661 sink = ctx->ann;
260 3661 ▶ if (C->has_unevaluated) { local = jsf_annot_new(aTHX); ctx->ann = local; }
Branch: 1 branch
BranchTrueFalseTotal
if (C->has_unevaluated) { local = jsf_annot_new(aTHX); ctx->ann = local; } 962 2699 3661
261  
262 /* track the dynamic scope: push this node's resource base when it differs
263 * from the current innermost, so $dynamicRef can search it. */
264 3661 ▶ if (C->has_dynamic && ctx->dynscope) {
Branch: 2 branches
BranchTrueFalseTotal
if (C->has_dynamic && ctx->dynscope) { 346 3315 3661
if (C->has_dynamic && ctx->dynscope) { 346 0 346
265 346 uint32_t bl2; const char *bp2 = jsf_str_bytes(a, n->base_off, &bl2);
266 346 SSize_t top = av_len(ctx->dynscope); int same = 0;
267 346 ▶ if (top >= 0) { SV **tp = av_fetch(ctx->dynscope, top, 0);
Branch: 1 branch
BranchTrueFalseTotal
if (top >= 0) { SV **tp = av_fetch(ctx->dynscope, top, 0); 293 53 346
268 586 ▶ if (tp && *tp) { STRLEN tl; const char *ts = SvPV_const(*tp, tl); if (tl == bl2 && memEQ(ts, bp2, bl2)) same = 1; } }
Branch: 4 branches
BranchTrueFalseTotal
if (tp && *tp) { STRLEN tl; const char *ts = SvPV_const(*tp, tl); if (tl == bl2 && memEQ(ts, bp2, bl2)) same = 1; } } 293 0 293
if (tp && *tp) { STRLEN tl; const char *ts = SvPV_const(*tp, tl); if (tl == bl2 && memEQ(ts, bp2, bl2)) same = 1; } } 293 0 293
if (tp && *tp) { STRLEN tl; const char *ts = SvPV_const(*tp, tl); if (tl == bl2 && memEQ(ts, bp2, bl2)) same = 1; } } 182 111 293
if (tp && *tp) { STRLEN tl; const char *ts = SvPV_const(*tp, tl); if (tl == bl2 && memEQ(ts, bp2, bl2)) same = 1; } } 165 17 182
269 346 ▶ if (!same) { av_push(ctx->dynscope, newSVpvn(bp2, bl2)); pushed_dyn = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (!same) { av_push(ctx->dynscope, newSVpvn(bp2, bl2)); pushed_dyn = 1; } 181 165 346
270 }
271  
272 3661 ▶ if ((n->present & JSF_HAS_REF) && n->ref_off) {
Branch: 2 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_REF) && n->ref_off) { 488 3173 3661
if ((n->present & JSF_HAS_REF) && n->ref_off) { 488 0 488
273 488 ▶ if (!jsf_validate(aTHX_ C, n->ref_off, data, ctx)) { ok = 0; if (!ctx->collect) goto done; }
Branch: 2 branches
BranchTrueFalseTotal
if (!jsf_validate(aTHX_ C, n->ref_off, data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 151 337 488
if (!jsf_validate(aTHX_ C, n->ref_off, data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 151 0 151
274 }
275 /* $dynamicRef: outermost matching $dynamicAnchor in the dynamic scope wins;
276 * otherwise fall back to the lexical target (ref_off). */
277 3510 ▶ if (n->present & JSF_HAS_DYNREF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_DYNREF) { 60 3450 3510
278 60 uint32_t target = n->ref_off;
279 60 ▶ if (ctx->dynscope && n->dynref_name_off) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->dynscope && n->dynref_name_off) { 60 0 60
if (ctx->dynscope && n->dynref_name_off) { 46 14 60
280 46 uint32_t nml; const char *nm = jsf_str_bytes(a, n->dynref_name_off, &nml);
281 46 SSize_t i, top = av_len(ctx->dynscope);
282 65 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 65 0 65
283 65 SV **b = av_fetch(ctx->dynscope, i, 0);
284 SV *key; STRLEN kl; const char *kp; SV **te;
285 65 ▶ if (!b || !*b) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!b || !*b) continue; 65 0 65
if (!b || !*b) continue; 0 65 65
286 65 key = sv_2mortal(newSVsv(*b)); sv_catpvs(key, "#"); sv_catpvn(key, nm, nml);
287 65 kp = SvPV_const(key, kl);
288 65 te = hv_fetch(C->dynmap, kp, (I32)kl, 0);
289 65 ▶ if (te && *te && SvIOK(*te)) { target = (uint32_t)SvIV(*te); break; }
Branch: 3 branches
BranchTrueFalseTotal
if (te && *te && SvIOK(*te)) { target = (uint32_t)SvIV(*te); break; } 46 19 65
if (te && *te && SvIOK(*te)) { target = (uint32_t)SvIV(*te); break; } 46 0 46
if (te && *te && SvIOK(*te)) { target = (uint32_t)SvIV(*te); break; } 46 0 46
290 }
291 }
292 60 ▶ if (target && !jsf_validate(aTHX_ C, target, data, ctx)) { ok = 0; if (!ctx->collect) goto done; }
Branch: 3 branches
BranchTrueFalseTotal
if (target && !jsf_validate(aTHX_ C, target, data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 60 0 60
if (target && !jsf_validate(aTHX_ C, target, data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 19 41 60
if (target && !jsf_validate(aTHX_ C, target, data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 19 0 19
293 }
294  
295 3491 t = jsf_classify_type(aTHX_ data);
296 3491 ▶ if (C->coerce && (n->present & JSF_HAS_TYPE) && !(t & n->type_mask))
Branch: 3 branches
BranchTrueFalseTotal
if (C->coerce && (n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) 18 3473 3491
if (C->coerce && (n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) 18 0 18
if (C->coerce && (n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) 16 2 18
297 16 t |= jsf_coerce_bits(aTHX_ n->type_mask, data, t);
298  
299 /* the validation vocabulary (type/const/enum, the numeric/string/count
300 * keywords) is skipped when a custom $schema metaschema disables it. */
301 3491 ▶ if (!C->no_validation_vocab) {
Branch: 1 branch
BranchTrueFalseTotal
if (!C->no_validation_vocab) { 3484 7 3491
302  
303 3484 ▶ if ((n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) JSF_FAIL("type");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) JSF_FAIL("type"); 1154 2330 3484
if ((n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) JSF_FAIL("type"); 229 925 1154
if ((n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) JSF_FAIL("type"); 7 222 229
if ((n->present & JSF_HAS_TYPE) && !(t & n->type_mask)) JSF_FAIL("type"); 222 7 229
304  
305 3262 ▶ if (n->present & JSF_HAS_CONST) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_CONST) { 261 3001 3262
306 261 SV **cv = av_fetch(C->keep, n->const_keep, 0);
307 522 ▶ int eq = cv && (C->coerce
Branch: 1 branch
BranchTrueFalseTotal
int eq = cv && (C->coerce 261 0 261
308 2 ? jsf_json_equal_coerced(aTHX_ data, *cv)
309 259 : jsf_json_equal(aTHX_ data, *cv));
310 261 ▶ if (!eq) JSF_FAIL("const");
Branch: 3 branches
BranchTrueFalseTotal
if (!eq) JSF_FAIL("const"); 112 149 261
if (!eq) JSF_FAIL("const"); 0 112 112
if (!eq) JSF_FAIL("const"); 112 0 112
311 }
312 3150 ▶ if (n->present & JSF_HAS_ENUM) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_ENUM) { 74 3076 3150
313 74 int found = 0; uint32_t i;
314 146 ▶ for (i = 0; i < n->enum_n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n->enum_n; i++) { 112 34 146
315 112 SV **ev = av_fetch(C->keep, n->enum_keep + i, 0);
316 224 ▶ if (ev && (C->coerce
Branch: 3 branches
BranchTrueFalseTotal
if (ev && (C->coerce 112 0 112
if (ev && (C->coerce 10 102 112
if (ev && (C->coerce 40 72 112
317 10 ? jsf_json_equal_coerced(aTHX_ data, *ev)
318 142 : jsf_json_equal(aTHX_ data, *ev))) { found = 1; break; }
319 }
320 74 ▶ if (!found) JSF_FAIL("enum");
Branch: 3 branches
BranchTrueFalseTotal
if (!found) JSF_FAIL("enum"); 34 40 74
if (!found) JSF_FAIL("enum"); 0 34 34
if (!found) JSF_FAIL("enum"); 34 0 34
321 }
322  
323 /* Gated on the keywords actually present: a number the schema only gives a
324 * `type` is never read numerically at all, which is both one branch cheaper
325 * and one fewer chance to touch the value. */
326 3116 ▶ if ((t & JSF_T_NUMBER)
Branch: 1 branch
BranchTrueFalseTotal
if ((t & JSF_T_NUMBER) 709 2407 3116
327 709 ▶ && (n->present & (JSF_HAS_MIN | JSF_HAS_MAX | JSF_HAS_EXMIN
Branch: 1 branch
BranchTrueFalseTotal
&& (n->present & (JSF_HAS_MIN | JSF_HAS_MAX | JSF_HAS_EXMIN 192 517 709
328 | JSF_HAS_EXMAX | JSF_HAS_MULOF))) {
329 192 NV x = jsf__nv_of(aTHX_ data);
330 192 ▶ if ((n->present & JSF_HAS_MIN) && x < n->minimum) JSF_FAIL("minimum");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MIN) && x < n->minimum) JSF_FAIL("minimum"); 71 121 192
if ((n->present & JSF_HAS_MIN) && x < n->minimum) JSF_FAIL("minimum"); 33 38 71
if ((n->present & JSF_HAS_MIN) && x < n->minimum) JSF_FAIL("minimum"); 3 30 33
if ((n->present & JSF_HAS_MIN) && x < n->minimum) JSF_FAIL("minimum"); 30 3 33
331 162 ▶ if ((n->present & JSF_HAS_MAX) && x > n->maximum) JSF_FAIL("maximum");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MAX) && x > n->maximum) JSF_FAIL("maximum"); 27 135 162
if ((n->present & JSF_HAS_MAX) && x > n->maximum) JSF_FAIL("maximum"); 10 17 27
if ((n->present & JSF_HAS_MAX) && x > n->maximum) JSF_FAIL("maximum"); 0 10 10
if ((n->present & JSF_HAS_MAX) && x > n->maximum) JSF_FAIL("maximum"); 10 0 10
332 152 ▶ if ((n->present & JSF_HAS_EXMIN) && x <= n->exmin) JSF_FAIL("exclusiveMinimum");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_EXMIN) && x <= n->exmin) JSF_FAIL("exclusiveMinimum"); 10 142 152
if ((n->present & JSF_HAS_EXMIN) && x <= n->exmin) JSF_FAIL("exclusiveMinimum"); 4 6 10
if ((n->present & JSF_HAS_EXMIN) && x <= n->exmin) JSF_FAIL("exclusiveMinimum"); 0 4 4
if ((n->present & JSF_HAS_EXMIN) && x <= n->exmin) JSF_FAIL("exclusiveMinimum"); 4 0 4
333 148 ▶ if ((n->present & JSF_HAS_EXMAX) && x >= n->exmax) JSF_FAIL("exclusiveMaximum");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_EXMAX) && x >= n->exmax) JSF_FAIL("exclusiveMaximum"); 18 130 148
if ((n->present & JSF_HAS_EXMAX) && x >= n->exmax) JSF_FAIL("exclusiveMaximum"); 9 9 18
if ((n->present & JSF_HAS_EXMAX) && x >= n->exmax) JSF_FAIL("exclusiveMaximum"); 0 9 9
if ((n->present & JSF_HAS_EXMAX) && x >= n->exmax) JSF_FAIL("exclusiveMaximum"); 9 0 9
334 139 ▶ if (n->present & JSF_HAS_MULOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_MULOF) { 76 63 139
335 76 NV m = n->mulof;
336 76 ▶ if (m != 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if (m != 0.0) { 76 0 76
337 76 ▶ NV eps = 1e-9 * (fabs(m) > 1.0 ? fabs(m) : 1.0), r = fmod(x, m);
Branch: 1 branch
BranchTrueFalseTotal
NV eps = 1e-9 * (fabs(m) > 1.0 ? fabs(m) : 1.0), r = fmod(x, m); 70 6 76
338 76 ▶ if (fabs(r) > eps && fabs(fabs(r) - fabs(m)) > eps) JSF_FAIL("multipleOf");
Branch: 4 branches
BranchTrueFalseTotal
if (fabs(r) > eps && fabs(fabs(r) - fabs(m)) > eps) JSF_FAIL("multipleOf"); 37 39 76
if (fabs(r) > eps && fabs(fabs(r) - fabs(m)) > eps) JSF_FAIL("multipleOf"); 36 1 37
if (fabs(r) > eps && fabs(fabs(r) - fabs(m)) > eps) JSF_FAIL("multipleOf"); 0 36 36
if (fabs(r) > eps && fabs(fabs(r) - fabs(m)) > eps) JSF_FAIL("multipleOf"); 36 0 36
339 }
340 }
341 }
342  
343 3027 ▶ if (t & JSF_T_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if (t & JSF_T_STRING) { 476 2551 3027
344 476 ▶ if (n->present & (JSF_HAS_MINLEN | JSF_HAS_MAXLEN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & (JSF_HAS_MINLEN | JSF_HAS_MAXLEN)) { 45 431 476
345 45 UV len = (UV)sv_len_utf8(data);
346 45 ▶ if ((n->present & JSF_HAS_MINLEN) && len < n->min_length) JSF_FAIL("minLength");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MINLEN) && len < n->min_length) JSF_FAIL("minLength"); 23 22 45
if ((n->present & JSF_HAS_MINLEN) && len < n->min_length) JSF_FAIL("minLength"); 9 14 23
if ((n->present & JSF_HAS_MINLEN) && len < n->min_length) JSF_FAIL("minLength"); 0 9 9
if ((n->present & JSF_HAS_MINLEN) && len < n->min_length) JSF_FAIL("minLength"); 9 0 9
347 36 ▶ if ((n->present & JSF_HAS_MAXLEN) && len > n->max_length) JSF_FAIL("maxLength");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MAXLEN) && len > n->max_length) JSF_FAIL("maxLength"); 26 10 36
if ((n->present & JSF_HAS_MAXLEN) && len > n->max_length) JSF_FAIL("maxLength"); 10 16 26
if ((n->present & JSF_HAS_MAXLEN) && len > n->max_length) JSF_FAIL("maxLength"); 0 10 10
if ((n->present & JSF_HAS_MAXLEN) && len > n->max_length) JSF_FAIL("maxLength"); 10 0 10
348 }
349 470 if ((n->present & JSF_HAS_PATTERN) &&
350 17 ▶ !jsf_rx_match(aTHX_ jsf_get_regex(aTHX_ C, n->pattern_off), data)) JSF_FAIL("pattern");
Branch: 2 branches
BranchTrueFalseTotal
!jsf_rx_match(aTHX_ jsf_get_regex(aTHX_ C, n->pattern_off), data)) JSF_FAIL("pattern"); 0 4 4
!jsf_rx_match(aTHX_ jsf_get_regex(aTHX_ C, n->pattern_off), data)) JSF_FAIL("pattern"); 4 0 4
351 }
352  
353 } /* end validation-vocabulary scalar keywords */
354  
355 3011 ▶ if (t & JSF_T_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (t & JSF_T_ARRAY) { 466 2545 3011
356 466 AV *av = (AV *)SvRV(data);
357 466 SSize_t i, cnt = av_len(av) + 1;
358 466 uint32_t prefn = 0;
359 466 ▶ if ((n->present & JSF_HAS_MINITEMS) && (UV)cnt < n->min_items) JSF_FAIL("minItems");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MINITEMS) && (UV)cnt < n->min_items) JSF_FAIL("minItems"); 12 454 466
if ((n->present & JSF_HAS_MINITEMS) && (UV)cnt < n->min_items) JSF_FAIL("minItems"); 5 7 12
if ((n->present & JSF_HAS_MINITEMS) && (UV)cnt < n->min_items) JSF_FAIL("minItems"); 0 5 5
if ((n->present & JSF_HAS_MINITEMS) && (UV)cnt < n->min_items) JSF_FAIL("minItems"); 5 0 5
360 461 ▶ if ((n->present & JSF_HAS_MAXITEMS) && (UV)cnt > n->max_items) JSF_FAIL("maxItems");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MAXITEMS) && (UV)cnt > n->max_items) JSF_FAIL("maxItems"); 12 449 461
if ((n->present & JSF_HAS_MAXITEMS) && (UV)cnt > n->max_items) JSF_FAIL("maxItems"); 5 7 12
if ((n->present & JSF_HAS_MAXITEMS) && (UV)cnt > n->max_items) JSF_FAIL("maxItems"); 0 5 5
if ((n->present & JSF_HAS_MAXITEMS) && (UV)cnt > n->max_items) JSF_FAIL("maxItems"); 5 0 5
361 456 ▶ if (n->present & JSF_HAS_PREFIX) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_PREFIX) { 135 321 456
362 135 jsf_offlist *ol = (jsf_offlist *)jsf_arena_ptr(a, n->prefix_off);
363 135 uint32_t *offs = (uint32_t *)((char *)ol + sizeof(jsf_offlist));
364 135 prefn = ol->n;
365 342 ▶ for (i = 0; i < cnt && (uint32_t)i < prefn; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < cnt && (uint32_t)i < prefn; i++) { 283 59 342
for (i = 0; i < cnt && (uint32_t)i < prefn; i++) { 221 62 283
366 221 SV **el = av_fetch(av, i, 0);
367 221 jsf_annot_add_idx(aTHX_ ctx->ann, i);
368 221 ▶ if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i));
Branch: 7 branches
BranchTrueFalseTotal
if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 221 0 221
if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 0 221 221
if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 107 114 221
if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 107 114 221
if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 0 221 221
if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 14 207 221
if (el) JSF_CHILD(offs[i], *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 14 0 14
369 }
370 }
371 442 ▶ if (n->present & JSF_HAS_ITEMS) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_ITEMS) { 119 323 442
372 221 ▶ for (i = (SSize_t)prefn; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = (SSize_t)prefn; i < cnt; i++) { 143 78 221
373 143 SV **el = av_fetch(av, i, 0);
374 143 ▶ if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i));
Branch: 7 branches
BranchTrueFalseTotal
if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 143 0 143
if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 5 138 143
if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 17 126 143
if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 17 126 143
if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 5 138 143
if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 43 100 143
if (el) JSF_CHILD(n->items_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 41 2 43
375 }
376 78 ▶ if (ctx->ann && cnt > (SSize_t)prefn) ctx->ann->all_items = 1; /* items covers the tail */
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->ann && cnt > (SSize_t)prefn) ctx->ann->all_items = 1; /* items covers the tail */ 7 71 78
if (ctx->ann && cnt > (SSize_t)prefn) ctx->ann->all_items = 1; /* items covers the tail */ 6 1 7
377 }
378 401 ▶ if (n->unique) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->unique) { 44 357 401
379 110 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 85 25 110
380 85 SSize_t j; SV **ei = av_fetch(av, i, 0);
381 158 ▶ for (j = i + 1; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = i + 1; j < cnt; j++) { 92 66 158
382 92 SV **ej = av_fetch(av, j, 0);
383 92 ▶ if (ei && ej && jsf_json_equal(aTHX_ *ei, *ej)) { JSF_FAIL("uniqueItems"); }
Branch: 5 branches
BranchTrueFalseTotal
if (ei && ej && jsf_json_equal(aTHX_ *ei, *ej)) { JSF_FAIL("uniqueItems"); } 92 0 92
if (ei && ej && jsf_json_equal(aTHX_ *ei, *ej)) { JSF_FAIL("uniqueItems"); } 92 0 92
if (ei && ej && jsf_json_equal(aTHX_ *ei, *ej)) { JSF_FAIL("uniqueItems"); } 19 73 92
if (ei && ej && jsf_json_equal(aTHX_ *ei, *ej)) { JSF_FAIL("uniqueItems"); } 0 19 19
if (ei && ej && jsf_json_equal(aTHX_ *ei, *ej)) { JSF_FAIL("uniqueItems"); } 19 0 19
384 }
385 }
386 }
387 382 ▶ if (n->present & JSF_HAS_CONTAINS) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_CONTAINS) { 82 300 382
388 82 ▶ UV matched = 0, minc = (n->present & JSF_HAS_MINCONT) ? n->min_contains : 1;
Branch: 1 branch
BranchTrueFalseTotal
UV matched = 0, minc = (n->present & JSF_HAS_MINCONT) ? n->min_contains : 1; 37 45 82
389 262 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 180 82 262
390 180 SV **el = av_fetch(av, i, 0);
391 180 ▶ if (el && jsf_probe(aTHX_ C, n->contains_off, *el, ctx)) { matched++; jsf_annot_add_idx(aTHX_ ctx->ann, i); }
Branch: 2 branches
BranchTrueFalseTotal
if (el && jsf_probe(aTHX_ C, n->contains_off, *el, ctx)) { matched++; jsf_annot_add_idx(aTHX_ ctx->ann, i); } 180 0 180
if (el && jsf_probe(aTHX_ C, n->contains_off, *el, ctx)) { matched++; jsf_annot_add_idx(aTHX_ ctx->ann, i); } 91 89 180
392 }
393 82 ▶ if (matched < minc) JSF_FAIL("contains");
Branch: 3 branches
BranchTrueFalseTotal
if (matched < minc) JSF_FAIL("contains"); 30 52 82
if (matched < minc) JSF_FAIL("contains"); 0 30 30
if (matched < minc) JSF_FAIL("contains"); 30 0 30
394 52 ▶ if ((n->present & JSF_HAS_MAXCONT) && matched > n->max_contains) JSF_FAIL("maxContains");
Branch: 4 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MAXCONT) && matched > n->max_contains) JSF_FAIL("maxContains"); 16 36 52
if ((n->present & JSF_HAS_MAXCONT) && matched > n->max_contains) JSF_FAIL("maxContains"); 8 8 16
if ((n->present & JSF_HAS_MAXCONT) && matched > n->max_contains) JSF_FAIL("maxContains"); 0 8 8
if ((n->present & JSF_HAS_MAXCONT) && matched > n->max_contains) JSF_FAIL("maxContains"); 8 0 8
395 }
396 }
397  
398 2889 ▶ if (t & JSF_T_OBJECT) {
Branch: 1 branch
BranchTrueFalseTotal
if (t & JSF_T_OBJECT) { 1314 1575 2889
399 1314 HV *hv = (HV *)SvRV(data);
400 1314 jsf_proptab *pt = NULL; jsf_propent *en = NULL; char *base = a->base;
401  
402 /* apply_defaults: fill missing properties that have a `default` into a
403 * shallow working copy (never the caller's data). Only allocates when
404 * a defaulted property is actually absent. */
405 1314 ▶ if (C->apply_defaults && (n->present & JSF_HAS_PROPS)) {
Branch: 2 branches
BranchTrueFalseTotal
if (C->apply_defaults && (n->present & JSF_HAS_PROPS)) { 6 1308 1314
if (C->apply_defaults && (n->present & JSF_HAS_PROPS)) { 6 0 6
406 6 jsf_proptab *dpt = (jsf_proptab *)jsf_arena_ptr(a, n->props_off);
407 6 jsf_propent *den = (jsf_propent *)((char *)dpt + sizeof(jsf_proptab));
408 6 uint32_t p; int need = 0;
409 13 ▶ for (p = 0; p < dpt->n && !need; p++) {
Branch: 2 branches
BranchTrueFalseTotal
for (p = 0; p < dpt->n && !need; p++) { 10 3 13
for (p = 0; p < dpt->n && !need; p++) { 7 3 10
410 7 jsf_node_t *ch = (jsf_node_t *)jsf_arena_ptr(a, den[p].child_off);
411 7 ▶ if (ch->present & JSF_HAS_DEFAULT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ch->present & JSF_HAS_DEFAULT) { 5 2 7
412 5 uint32_t nl; const char *nm = jsf_str_bytes(a, den[p].name_off, &nl);
413 5 ▶ if (!hv_exists(hv, nm, (I32)nl)) need = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_exists(hv, nm, (I32)nl)) need = 1; 4 1 5
414 }
415 }
416 6 ▶ if (need) {
Branch: 1 branch
BranchTrueFalseTotal
if (need) { 4 2 6
417 11 ▶ for (p = 0; p < dpt->n; p++) {
Branch: 1 branch
BranchTrueFalseTotal
for (p = 0; p < dpt->n; p++) { 7 4 11
418 7 jsf_node_t *ch = (jsf_node_t *)jsf_arena_ptr(a, den[p].child_off);
419 7 ▶ if (ch->present & JSF_HAS_DEFAULT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ch->present & JSF_HAS_DEFAULT) { 4 3 7
420 4 uint32_t nl; const char *nm = jsf_str_bytes(a, den[p].name_off, &nl);
421 4 ▶ if (!hv_exists(hv, nm, (I32)nl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_exists(hv, nm, (I32)nl)) { 4 0 4
422 4 SV **dv = av_fetch(C->keep, ch->default_keep, 0);
423 4 ▶ (void)hv_store(hv, nm, (I32)nl, newSVsv(dv ? *dv : &PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_store(hv, nm, (I32)nl, newSVsv(dv ? *dv : &PL_sv_undef), 0); 4 0 4
424 }
425 }
426 }
427 }
428 }
429  
430 1314 ▶ if (n->present & JSF_HAS_PROPS) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_PROPS) { 672 642 1314
431 uint32_t p;
432 672 pt = (jsf_proptab *)jsf_arena_ptr(a, n->props_off);
433 672 en = (jsf_propent *)((char *)pt + sizeof(jsf_proptab));
434 1686 ▶ for (p = 0; p < pt->n; p++) {
Branch: 1 branch
BranchTrueFalseTotal
for (p = 0; p < pt->n; p++) { 1104 582 1686
435 1104 uint32_t nl; const char *nm = jsf_str_bytes(a, en[p].name_off, &nl);
436 1104 SV **vp = (SV **)hv_common(hv, NULL, nm, nl, 0, HV_FETCH_JUST_SV, NULL, en[p].hash);
437 1104 ▶ if (vp && *vp) {
Branch: 2 branches
BranchTrueFalseTotal
if (vp && *vp) { 617 487 1104
if (vp && *vp) { 617 0 617
438 617 jsf_annot_add_key(aTHX_ ctx->ann, nm, nl);
439 617 ▶ JSF_CHILD(en[p].child_off, *vp, jsf_iloc_push_key(aTHX_ ctx->iloc, nm, nl));
Branch: 6 branches
BranchTrueFalseTotal
JSF_CHILD(en[p].child_off, *vp, jsf_iloc_push_key(aTHX_ ctx->iloc, nm, nl)); 10 607 617
JSF_CHILD(en[p].child_off, *vp, jsf_iloc_push_key(aTHX_ ctx->iloc, nm, nl)); 160 457 617
JSF_CHILD(en[p].child_off, *vp, jsf_iloc_push_key(aTHX_ ctx->iloc, nm, nl)); 160 457 617
JSF_CHILD(en[p].child_off, *vp, jsf_iloc_push_key(aTHX_ ctx->iloc, nm, nl)); 10 607 617
JSF_CHILD(en[p].child_off, *vp, jsf_iloc_push_key(aTHX_ ctx->iloc, nm, nl)); 97 520 617
JSF_CHILD(en[p].child_off, *vp, jsf_iloc_push_key(aTHX_ ctx->iloc, nm, nl)); 90 7 97
440 }
441 }
442 }
443 1224 ▶ if (n->present & (JSF_HAS_PATPROPS | JSF_HAS_ADDPROPS | JSF_HAS_PROPNAMES)) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & (JSF_HAS_PATPROPS | JSF_HAS_ADDPROPS | JSF_HAS_PROPNAMES)) { 132 1092 1224
444 132 HE *he; hv_iterinit(hv);
445 249 ▶ while ((he = hv_iternext(hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(hv))) { 159 90 249
446 159 ▶ STRLEN kl; char *k = HePV(he, kl); SV *val = HeVAL(he);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN kl; char *k = HePV(he, kl); SV *val = HeVAL(he); 0 159 159
447 159 int matched = 0;
448 159 ▶ if ((n->present & JSF_HAS_PROPS) && jsf_find_prop(pt, en, base, k, kl) >= 0) matched = 1;
Branch: 2 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_PROPS) && jsf_find_prop(pt, en, base, k, kl) >= 0) matched = 1; 53 106 159
if ((n->present & JSF_HAS_PROPS) && jsf_find_prop(pt, en, base, k, kl) >= 0) matched = 1; 27 26 53
449 159 ▶ if (n->present & JSF_HAS_PATPROPS) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_PATPROPS) { 85 74 159
450 85 jsf_pattab *qt = (jsf_pattab *)jsf_arena_ptr(a, n->patprops_off);
451 85 jsf_patent *pe = (jsf_patent *)((char *)qt + sizeof(jsf_pattab));
452 85 SV *ksv = sv_2mortal(newSVpvn(k, kl)); uint32_t q;
453 169 ▶ for (q = 0; q < qt->n; q++) {
Branch: 1 branch
BranchTrueFalseTotal
for (q = 0; q < qt->n; q++) { 97 72 169
454 97 ▶ if (jsf_rx_match(aTHX_ jsf_get_regex(aTHX_ C, pe[q].pat_off), ksv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (jsf_rx_match(aTHX_ jsf_get_regex(aTHX_ C, pe[q].pat_off), ksv)) { 45 52 97
455 45 matched = 1;
456 45 jsf_annot_add_key(aTHX_ ctx->ann, k, kl);
457 74 ▶ JSF_CHILD(pe[q].child_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl));
Branch: 6 branches
BranchTrueFalseTotal
JSF_CHILD(pe[q].child_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 0 45 45
JSF_CHILD(pe[q].child_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 15 30 45
JSF_CHILD(pe[q].child_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 15 30 45
JSF_CHILD(pe[q].child_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 0 45 45
JSF_CHILD(pe[q].child_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 13 32 45
JSF_CHILD(pe[q].child_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 13 0 13
458 }
459 }
460 }
461 146 ▶ if ((n->present & JSF_HAS_ADDPROPS) && !matched) {
Branch: 2 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_ADDPROPS) && !matched) { 67 79 146
if ((n->present & JSF_HAS_ADDPROPS) && !matched) { 38 29 67
462 38 ▶ if (n->addprops_off == JSF_NULL_OFF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->addprops_off == JSF_NULL_OFF) { 16 22 38
463 16 STRLEN sav = 0;
464 16 ▶ if (ctx->errors) sav = jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl);
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->errors) sav = jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl); 0 16 16
465 16 ▶ JSF_FAIL("additionalProperties");
Branch: 2 branches
BranchTrueFalseTotal
JSF_FAIL("additionalProperties"); 0 16 16
JSF_FAIL("additionalProperties"); 16 0 16
466 0 ▶ if (ctx->errors) jsf_iloc_pop(ctx->iloc, sav);
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->errors) jsf_iloc_pop(ctx->iloc, sav); 0 0 0
467 } else {
468 22 jsf_annot_add_key(aTHX_ ctx->ann, k, kl);
469 22 ▶ JSF_CHILD(n->addprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl));
Branch: 6 branches
BranchTrueFalseTotal
JSF_CHILD(n->addprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 0 22 22
JSF_CHILD(n->addprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 7 15 22
JSF_CHILD(n->addprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 7 15 22
JSF_CHILD(n->addprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 0 22 22
JSF_CHILD(n->addprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 7 15 22
JSF_CHILD(n->addprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 7 0 7
470 }
471 }
472 123 ▶ if (n->present & JSF_HAS_PROPNAMES) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_PROPNAMES) { 20 103 123
473 20 SV *ksv = sv_2mortal(newSVpvn(k, kl));
474 20 ▶ if (!jsf_probe(aTHX_ C, n->propnames_off, ksv, ctx)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!jsf_probe(aTHX_ C, n->propnames_off, ksv, ctx)) { 6 14 20
475 6 STRLEN sav = 0;
476 6 ▶ if (ctx->errors) sav = jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl);
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->errors) sav = jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl); 0 6 6
477 6 ▶ JSF_FAIL("propertyNames");
Branch: 2 branches
BranchTrueFalseTotal
JSF_FAIL("propertyNames"); 0 6 6
JSF_FAIL("propertyNames"); 6 0 6
478 0 ▶ if (ctx->errors) jsf_iloc_pop(ctx->iloc, sav);
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->errors) jsf_iloc_pop(ctx->iloc, sav); 0 0 0
479 }
480 }
481 }
482 }
483 1182 ▶ if ((n->present & JSF_HAS_MINPROPS) && (UV)HvKEYS(hv) < n->min_props) JSF_FAIL("minProperties");
Branch: 5 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MINPROPS) && (UV)HvKEYS(hv) < n->min_props) JSF_FAIL("minProperties"); 10 1172 1182
if ((n->present & JSF_HAS_MINPROPS) && (UV)HvKEYS(hv) < n->min_props) JSF_FAIL("minProperties"); 0 10 10
if ((n->present & JSF_HAS_MINPROPS) && (UV)HvKEYS(hv) < n->min_props) JSF_FAIL("minProperties"); 4 6 10
if ((n->present & JSF_HAS_MINPROPS) && (UV)HvKEYS(hv) < n->min_props) JSF_FAIL("minProperties"); 0 4 4
if ((n->present & JSF_HAS_MINPROPS) && (UV)HvKEYS(hv) < n->min_props) JSF_FAIL("minProperties"); 4 0 4
484 1178 ▶ if ((n->present & JSF_HAS_MAXPROPS) && (UV)HvKEYS(hv) > n->max_props) JSF_FAIL("maxProperties");
Branch: 5 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_MAXPROPS) && (UV)HvKEYS(hv) > n->max_props) JSF_FAIL("maxProperties"); 9 1169 1178
if ((n->present & JSF_HAS_MAXPROPS) && (UV)HvKEYS(hv) > n->max_props) JSF_FAIL("maxProperties"); 0 9 9
if ((n->present & JSF_HAS_MAXPROPS) && (UV)HvKEYS(hv) > n->max_props) JSF_FAIL("maxProperties"); 4 5 9
if ((n->present & JSF_HAS_MAXPROPS) && (UV)HvKEYS(hv) > n->max_props) JSF_FAIL("maxProperties"); 0 4 4
if ((n->present & JSF_HAS_MAXPROPS) && (UV)HvKEYS(hv) > n->max_props) JSF_FAIL("maxProperties"); 4 0 4
485 1174 ▶ if (n->present & JSF_HAS_REQUIRED) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_REQUIRED) { 394 780 1174
486 394 jsf_reqset *rs = (jsf_reqset *)jsf_arena_ptr(a, n->required_off);
487 394 jsf_reqent *re = (jsf_reqent *)((char *)rs + sizeof(jsf_reqset));
488 uint32_t r;
489 660 ▶ for (r = 0; r < rs->n; r++) {
Branch: 1 branch
BranchTrueFalseTotal
for (r = 0; r < rs->n; r++) { 412 248 660
490 412 uint32_t nl; const char *nm = jsf_str_bytes(a, re[r].name_off, &nl);
491 412 ▶ if (!hv_exists(hv, nm, (I32)nl)) JSF_FAIL("required");
Branch: 3 branches
BranchTrueFalseTotal
if (!hv_exists(hv, nm, (I32)nl)) JSF_FAIL("required"); 151 261 412
if (!hv_exists(hv, nm, (I32)nl)) JSF_FAIL("required"); 5 146 151
if (!hv_exists(hv, nm, (I32)nl)) JSF_FAIL("required"); 146 5 151
492 }
493 }
494 1028 ▶ if (n->present & JSF_HAS_DEPREQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_DEPREQ) { 19 1009 1028
495 19 jsf_deptab *dt = (jsf_deptab *)jsf_arena_ptr(a, n->depreq_off);
496 19 jsf_depent *de = (jsf_depent *)((char *)dt + sizeof(jsf_deptab));
497 uint32_t di;
498 34 ▶ for (di = 0; di < dt->n; di++) {
Branch: 1 branch
BranchTrueFalseTotal
for (di = 0; di < dt->n; di++) { 22 12 34
499 22 uint32_t nl; const char *nm = jsf_str_bytes(a, de[di].name_off, &nl);
500 22 ▶ if (hv_exists(hv, nm, (I32)nl) && de[di].names_off) {
Branch: 2 branches
BranchTrueFalseTotal
if (hv_exists(hv, nm, (I32)nl) && de[di].names_off) { 13 9 22
if (hv_exists(hv, nm, (I32)nl) && de[di].names_off) { 13 0 13
501 13 jsf_offlist *ol = (jsf_offlist *)jsf_arena_ptr(a, de[di].names_off);
502 13 uint32_t *offs = (uint32_t *)((char *)ol + sizeof(jsf_offlist)); uint32_t z;
503 20 ▶ for (z = 0; z < ol->n; z++) {
Branch: 1 branch
BranchTrueFalseTotal
for (z = 0; z < ol->n; z++) { 14 6 20
504 14 uint32_t rl; const char *rn = jsf_str_bytes(a, offs[z], &rl);
505 14 ▶ if (!hv_exists(hv, rn, (I32)rl)) JSF_FAIL("dependentRequired");
Branch: 3 branches
BranchTrueFalseTotal
if (!hv_exists(hv, rn, (I32)rl)) JSF_FAIL("dependentRequired"); 7 7 14
if (!hv_exists(hv, rn, (I32)rl)) JSF_FAIL("dependentRequired"); 0 7 7
if (!hv_exists(hv, rn, (I32)rl)) JSF_FAIL("dependentRequired"); 7 0 7
506 }
507 }
508 }
509 }
510 1021 ▶ if (n->present & JSF_HAS_DEPSCHEMAS) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_DEPSCHEMAS) { 25 996 1021
511 25 jsf_dstab *dt = (jsf_dstab *)jsf_arena_ptr(a, n->depsch_off);
512 25 jsf_dsent *de = (jsf_dsent *)((char *)dt + sizeof(jsf_dstab));
513 uint32_t di;
514 49 ▶ for (di = 0; di < dt->n; di++) {
Branch: 1 branch
BranchTrueFalseTotal
for (di = 0; di < dt->n; di++) { 35 14 49
515 35 uint32_t nl; const char *nm = jsf_str_bytes(a, de[di].name_off, &nl);
516 54 if (hv_exists(hv, nm, (I32)nl) &&
517 30 ▶ !jsf_validate(aTHX_ C, de[di].sch_off, data, ctx)) { ok = 0; if (!ctx->collect) goto done; }
Branch: 1 branch
BranchTrueFalseTotal
!jsf_validate(aTHX_ C, de[di].sch_off, data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 11 0 11
518 }
519 }
520 }
521  
522 2585 ▶ if (n->present & JSF_HAS_ALLOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_ALLOF) { 107 2478 2585
523 107 jsf_offlist *ol = (jsf_offlist *)jsf_arena_ptr(a, n->allof_off);
524 107 uint32_t *offs = (uint32_t *)((char *)ol + sizeof(jsf_offlist)); uint32_t i;
525 242 ▶ for (i = 0; i < ol->n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ol->n; i++) 180 62 242
526 180 ▶ if (!jsf_validate(aTHX_ C, offs[i], data, ctx)) { ok = 0; if (!ctx->collect) goto done; }
Branch: 2 branches
BranchTrueFalseTotal
if (!jsf_validate(aTHX_ C, offs[i], data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 45 135 180
if (!jsf_validate(aTHX_ C, offs[i], data, ctx)) { ok = 0; if (!ctx->collect) goto done; } 45 0 45
527 }
528 /* anyOf: probe EVERY branch (no break); each successful branch merges its
529 * evaluated set into this frame's set (jsf_probe_ann's frame merges into
530 * ctx->ann on success). Collecting from all matches is required by spec. */
531 2540 ▶ if (n->present & JSF_HAS_ANYOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_ANYOF) { 50 2490 2540
532 50 jsf_offlist *ol = (jsf_offlist *)jsf_arena_ptr(a, n->anyof_off);
533 50 uint32_t *offs = (uint32_t *)((char *)ol + sizeof(jsf_offlist)); uint32_t i; int any = 0;
534 140 ▶ for (i = 0; i < ol->n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ol->n; i++) 90 50 140
535 90 ▶ if (jsf_probe_ann(aTHX_ C, offs[i], data, ctx, ctx->ann)) any = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (jsf_probe_ann(aTHX_ C, offs[i], data, ctx, ctx->ann)) any = 1; 49 41 90
536 50 ▶ if (!any) JSF_FAIL("anyOf");
Branch: 3 branches
BranchTrueFalseTotal
if (!any) JSF_FAIL("anyOf"); 13 37 50
if (!any) JSF_FAIL("anyOf"); 0 13 13
if (!any) JSF_FAIL("anyOf"); 13 0 13
537 }
538 2527 ▶ if (n->present & JSF_HAS_ONEOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_ONEOF) { 109 2418 2527
539 109 jsf_offlist *ol = (jsf_offlist *)jsf_arena_ptr(a, n->oneof_off);
540 109 uint32_t *offs = (uint32_t *)((char *)ol + sizeof(jsf_offlist)); uint32_t i, c2 = 0;
541 367 ▶ for (i = 0; i < ol->n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ol->n; i++) 258 109 367
542 258 ▶ if (jsf_probe_ann(aTHX_ C, offs[i], data, ctx, ctx->ann)) c2++;
Branch: 1 branch
BranchTrueFalseTotal
if (jsf_probe_ann(aTHX_ C, offs[i], data, ctx, ctx->ann)) c2++; 99 159 258
543 109 ▶ if (c2 != 1) JSF_FAIL("oneOf");
Branch: 3 branches
BranchTrueFalseTotal
if (c2 != 1) JSF_FAIL("oneOf"); 55 54 109
if (c2 != 1) JSF_FAIL("oneOf"); 0 55 55
if (c2 != 1) JSF_FAIL("oneOf"); 55 0 55
544 }
545 2472 ▶ if (n->present & JSF_HAS_NOT) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_NOT) { 46 2426 2472
546 /* `not` discards its own annotations, but its internal unevaluated* must
547 * still apply - jsf_probe gives it its own frame with no sink. */
548 46 ▶ if (jsf_probe(aTHX_ C, n->not_off, data, ctx)) JSF_FAIL("not");
Branch: 3 branches
BranchTrueFalseTotal
if (jsf_probe(aTHX_ C, n->not_off, data, ctx)) JSF_FAIL("not"); 28 18 46
if (jsf_probe(aTHX_ C, n->not_off, data, ctx)) JSF_FAIL("not"); 0 28 28
if (jsf_probe(aTHX_ C, n->not_off, data, ctx)) JSF_FAIL("not"); 28 0 28
549 }
550 2444 ▶ if (n->present & JSF_HAS_IF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_IF) { 73 2371 2444
551 73 int branchok = 1;
552 73 ▶ if (jsf_probe_ann(aTHX_ C, n->if_off, data, ctx, ctx->ann)) {
Branch: 1 branch
BranchTrueFalseTotal
if (jsf_probe_ann(aTHX_ C, n->if_off, data, ctx, ctx->ann)) { 39 34 73
553 39 ▶ if (n->then_off) branchok = jsf_validate(aTHX_ C, n->then_off, data, ctx);
Branch: 1 branch
BranchTrueFalseTotal
if (n->then_off) branchok = jsf_validate(aTHX_ C, n->then_off, data, ctx); 28 11 39
554 } else {
555 34 ▶ if (n->else_off) branchok = jsf_validate(aTHX_ C, n->else_off, data, ctx);
Branch: 1 branch
BranchTrueFalseTotal
if (n->else_off) branchok = jsf_validate(aTHX_ C, n->else_off, data, ctx); 20 14 34
556 }
557 73 ▶ if (!branchok) { ok = 0; if (!ctx->collect) goto done; }
Branch: 2 branches
BranchTrueFalseTotal
if (!branchok) { ok = 0; if (!ctx->collect) goto done; } 16 57 73
if (!branchok) { ok = 0; if (!ctx->collect) goto done; } 16 0 16
558 }
559  
560 /* unevaluated*: after every other keyword and in-place applicator, apply to
561 * any property / item not in this instance's evaluated set. */
562 2428 ▶ if ((n->present & JSF_HAS_UNEVALPROPS) && (t & JSF_T_OBJECT)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_UNEVALPROPS) && (t & JSF_T_OBJECT)) { 145 2283 2428
if ((n->present & JSF_HAS_UNEVALPROPS) && (t & JSF_T_OBJECT)) { 139 6 145
563 139 HV *hv = (HV *)SvRV(data); HE *he;
564 139 hv_iterinit(hv);
565 272 ▶ while ((he = hv_iternext(hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(hv))) { 184 88 272
566 184 ▶ STRLEN kl; char *k = HePV(he, kl); SV *val = HeVAL(he);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN kl; char *k = HePV(he, kl); SV *val = HeVAL(he); 0 184 184
567 184 ▶ if (ctx->ann && hv_exists(ctx->ann->props, k, kl)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->ann && hv_exists(ctx->ann->props, k, kl)) continue; 184 0 184
if (ctx->ann && hv_exists(ctx->ann->props, k, kl)) continue; 113 71 184
568 71 jsf_annot_add_key(aTHX_ ctx->ann, k, kl);
569 71 ▶ JSF_CHILD(n->unevalprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl));
Branch: 6 branches
BranchTrueFalseTotal
JSF_CHILD(n->unevalprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 0 71 71
JSF_CHILD(n->unevalprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 71 0 71
JSF_CHILD(n->unevalprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 71 0 71
JSF_CHILD(n->unevalprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 0 71 71
JSF_CHILD(n->unevalprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 51 20 71
JSF_CHILD(n->unevalprops_off, val, jsf_iloc_push_key(aTHX_ ctx->iloc, k, kl)); 51 0 51
570 }
571 }
572 2377 ▶ if ((n->present & JSF_HAS_UNEVALITEMS) && (t & JSF_T_ARRAY)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((n->present & JSF_HAS_UNEVALITEMS) && (t & JSF_T_ARRAY)) { 2304 73 2377
if ((n->present & JSF_HAS_UNEVALITEMS) && (t & JSF_T_ARRAY)) { 6 67 73
573 67 AV *av = (AV *)SvRV(data); SSize_t i, cnt = av_len(av) + 1;
574 176 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 137 39 176
575 SV **el;
576 137 ▶ if (jsf_annot_has_idx(aTHX_ ctx->ann, i)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (jsf_annot_has_idx(aTHX_ ctx->ann, i)) continue; 97 40 137
577 40 el = av_fetch(av, i, 0);
578 40 jsf_annot_add_idx(aTHX_ ctx->ann, i);
579 40 ▶ if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i));
Branch: 7 branches
BranchTrueFalseTotal
if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 40 0 40
if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 0 40 40
if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 40 0 40
if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 40 0 40
if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 0 40 40
if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 28 12 40
if (el) JSF_CHILD(n->unevalitems_off, *el, jsf_iloc_push_idx(aTHX_ ctx->iloc, i)); 28 0 28
580 }
581 }
582  
583 2349 done:
584 3661 ▶ if (filled) SvREFCNT_dec((SV *)filled);
Branch: 1 branch
BranchTrueFalseTotal
if (filled) SvREFCNT_dec((SV *)filled); 0 3661 3661
585 3661 ▶ if (pushed_dyn) { SV *x = av_pop(ctx->dynscope); if (x) SvREFCNT_dec(x); }
Branch: 2 branches
BranchTrueFalseTotal
if (pushed_dyn) { SV *x = av_pop(ctx->dynscope); if (x) SvREFCNT_dec(x); } 181 3480 3661
if (pushed_dyn) { SV *x = av_pop(ctx->dynscope); if (x) SvREFCNT_dec(x); } 181 0 181
586 3661 ctx->ann = sink; /* restore caller's set */
587 3661 ▶ if (ok && sink && local) jsf_annot_merge(aTHX_ sink, local);
Branch: 3 branches
BranchTrueFalseTotal
if (ok && sink && local) jsf_annot_merge(aTHX_ sink, local); 2329 1332 3661
if (ok && sink && local) jsf_annot_merge(aTHX_ sink, local); 425 1904 2329
if (ok && sink && local) jsf_annot_merge(aTHX_ sink, local); 425 0 425
588 3661 ▶ if (local) jsf_annot_free(aTHX_ local);
Branch: 1 branch
BranchTrueFalseTotal
if (local) jsf_annot_free(aTHX_ local); 962 2699 3661
589 3661 ctx->depth--;
590 3661 return ok;
591 }
592  
593 #undef JSF_FAIL
594 #undef JSF_CHILD
595  
596 1477 static int jsf_run(pTHX_ jsf_compiled_t *C, SV *data, AV *errors) {
597 jsf_ctx_t ctx;
598 1477 ctx.errors = errors;
599 1477 ctx.collect = errors ? 1 : 0;
600 1477 ctx.depth = 0;
601 1477 ▶ ctx.iloc = errors ? sv_2mortal(newSVpvs("")) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ctx.iloc = errors ? sv_2mortal(newSVpvs("")) : NULL; 15 1462 1477
602 1477 ctx.ann = NULL; /* the root frame creates its own collector */
603 1477 ▶ ctx.dynscope = C->has_dynamic ? (AV *)sv_2mortal((SV *)newAV()) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ctx.dynscope = C->has_dynamic ? (AV *)sv_2mortal((SV *)newAV()) : NULL; 53 1424 1477
604 1477 return jsf_validate(aTHX_ C, C->root, data, &ctx);
605 }
606  
607 1462 static int jsf_is_valid(pTHX_ jsf_compiled_t *C, SV *data) {
608 1462 return jsf_run(aTHX_ C, data, NULL);
609 }
610  
611 #endif /* JSF_INTERP_H */
« include/jsf_compiled.h ↑ Summary include/jsf_arena.h »