@sourcemeta/blaze 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +65 -0
- package/index.d.mts +15 -0
- package/index.mjs +3709 -0
- package/package.json +71 -0
package/index.mjs
ADDED
|
@@ -0,0 +1,3709 @@
|
|
|
1
|
+
const DEPTH_LIMIT = 300;
|
|
2
|
+
const ANNOTATION_EMIT = 44;
|
|
3
|
+
const ANNOTATION_TO_PARENT = 45;
|
|
4
|
+
const ANNOTATION_BASENAME_TO_PARENT = 46;
|
|
5
|
+
const CONTROL_GROUP_START = 85;
|
|
6
|
+
const CONTROL_EVALUATE_END = 89;
|
|
7
|
+
const URI_REGEX = /^[a-zA-Z][a-zA-Z0-9+\-.]*:[^\s]*$/;
|
|
8
|
+
|
|
9
|
+
function buildJsonPointer(tokens, length) {
|
|
10
|
+
if (length === 0) return '';
|
|
11
|
+
let result = '';
|
|
12
|
+
for (let index = 0; index < length; index++) {
|
|
13
|
+
const token = String(tokens[index]);
|
|
14
|
+
result += '/' + token.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const Type = {
|
|
20
|
+
Null: 0,
|
|
21
|
+
Boolean: 1,
|
|
22
|
+
Integer: 2,
|
|
23
|
+
Real: 3,
|
|
24
|
+
String: 4,
|
|
25
|
+
Array: 5,
|
|
26
|
+
Object: 6,
|
|
27
|
+
Decimal: 7
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function jsonTypeOf(value) {
|
|
31
|
+
if (value === null) return Type.Null;
|
|
32
|
+
switch (typeof value) {
|
|
33
|
+
case 'boolean': return Type.Boolean;
|
|
34
|
+
case 'number': return Number.isInteger(value) ? Type.Integer : Type.Real;
|
|
35
|
+
case 'string': return Type.String;
|
|
36
|
+
case 'object': return Array.isArray(value) ? Type.Array : Type.Object;
|
|
37
|
+
default: return Type.Null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isIntegral(value) {
|
|
42
|
+
return typeof value === 'number' && Number.isFinite(value) && Math.floor(value) === value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function resolveInstance(instance, relativeInstanceLocation) {
|
|
46
|
+
const length = relativeInstanceLocation.length;
|
|
47
|
+
if (length === 0) return instance;
|
|
48
|
+
if (length === 1) {
|
|
49
|
+
if (instance === undefined || instance === null) return undefined;
|
|
50
|
+
return instance[relativeInstanceLocation[0]];
|
|
51
|
+
}
|
|
52
|
+
let current = instance;
|
|
53
|
+
for (let index = 0; index < length; index++) {
|
|
54
|
+
if (current === undefined || current === null) return undefined;
|
|
55
|
+
current = current[relativeInstanceLocation[index]];
|
|
56
|
+
}
|
|
57
|
+
return current;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function prepareInstruction(instruction) {
|
|
61
|
+
const wrapper = instruction[5];
|
|
62
|
+
if (wrapper === undefined || wrapper === null) {
|
|
63
|
+
instruction[5] = null;
|
|
64
|
+
} else {
|
|
65
|
+
const typeIndex = wrapper[0];
|
|
66
|
+
if (typeIndex === 0 || wrapper.length === 1) {
|
|
67
|
+
instruction[5] = null;
|
|
68
|
+
} else {
|
|
69
|
+
const payload = wrapper[1];
|
|
70
|
+
switch (typeIndex) {
|
|
71
|
+
case 4:
|
|
72
|
+
instruction[5] = payload[0];
|
|
73
|
+
break;
|
|
74
|
+
case 9:
|
|
75
|
+
try { instruction[5] = new RegExp(payload, 'u'); }
|
|
76
|
+
catch { instruction[5] = new RegExp(payload); }
|
|
77
|
+
break;
|
|
78
|
+
case 13: {
|
|
79
|
+
if (Array.isArray(payload)) {
|
|
80
|
+
const object = Object.create(null);
|
|
81
|
+
for (let index = 0; index < payload.length; index++) {
|
|
82
|
+
object[payload[index][0]] = payload[index][1];
|
|
83
|
+
}
|
|
84
|
+
instruction[5] = object;
|
|
85
|
+
} else {
|
|
86
|
+
instruction[5] = payload;
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 15: {
|
|
91
|
+
if (Array.isArray(payload)) {
|
|
92
|
+
const object = Object.create(null);
|
|
93
|
+
for (let index = 0; index < payload.length; index++) {
|
|
94
|
+
object[payload[index][0]] = payload[index][1];
|
|
95
|
+
}
|
|
96
|
+
instruction[5] = object;
|
|
97
|
+
} else {
|
|
98
|
+
instruction[5] = payload;
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 16: {
|
|
103
|
+
payload[0] = new Set(payload[0]);
|
|
104
|
+
const regexes = payload[2];
|
|
105
|
+
for (let index = 0; index < regexes.length; index++) {
|
|
106
|
+
try { regexes[index] = new RegExp(regexes[index], 'u'); }
|
|
107
|
+
catch { regexes[index] = new RegExp(regexes[index]); }
|
|
108
|
+
}
|
|
109
|
+
instruction[5] = payload;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
instruction[5] = payload;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const opcode = instruction[0];
|
|
120
|
+
if (opcode === 27 && Array.isArray(instruction[5])) {
|
|
121
|
+
const values = instruction[5];
|
|
122
|
+
let allPrimitive = true;
|
|
123
|
+
for (let index = 0; index < values.length; index++) {
|
|
124
|
+
const element = values[index];
|
|
125
|
+
if (element !== null && typeof element === 'object') {
|
|
126
|
+
allPrimitive = false;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (allPrimitive) {
|
|
131
|
+
instruction[5] = { set: new Set(values), values, primitive: true };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (instruction.length < 7) {
|
|
136
|
+
instruction.push(undefined);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
instruction.push(handlers[opcode] || null);
|
|
140
|
+
|
|
141
|
+
const children = instruction[6];
|
|
142
|
+
if (children) {
|
|
143
|
+
for (let index = 0; index < children.length; index++) {
|
|
144
|
+
prepareInstruction(children[index]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function resolveJumpTargets(instructions, targets) {
|
|
150
|
+
for (let index = 0; index < instructions.length; index++) {
|
|
151
|
+
const instruction = instructions[index];
|
|
152
|
+
if (instruction[0] === 91) {
|
|
153
|
+
const targetIndex = instruction[5];
|
|
154
|
+
if (targetIndex < targets.length) {
|
|
155
|
+
instruction[5] = targets[targetIndex];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const children = instruction[6];
|
|
159
|
+
if (children) {
|
|
160
|
+
resolveJumpTargets(children, targets);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const FNV_OFFSET = 14695981039346656037n;
|
|
166
|
+
const FNV_PRIME = 1099511628211n;
|
|
167
|
+
const MASK_53 = (1n << 53n) - 1n;
|
|
168
|
+
|
|
169
|
+
function blazeHash(resource, fragment) {
|
|
170
|
+
let result = FNV_OFFSET & MASK_53;
|
|
171
|
+
for (let index = 0; index < fragment.length; index++) {
|
|
172
|
+
result ^= BigInt(fragment.charCodeAt(index));
|
|
173
|
+
result = (result * FNV_PRIME) & MASK_53;
|
|
174
|
+
}
|
|
175
|
+
return Number((BigInt(resource) + result) & MASK_53);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function collectAnchorNames(targets, result) {
|
|
179
|
+
for (let targetIndex = 0; targetIndex < targets.length; targetIndex++) {
|
|
180
|
+
collectAnchorNamesFromInstructions(targets[targetIndex], result);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function collectAnchorNamesFromInstructions(instructions, result) {
|
|
185
|
+
for (let index = 0; index < instructions.length; index++) {
|
|
186
|
+
const instruction = instructions[index];
|
|
187
|
+
if (instruction[0] === 90 && typeof instruction[5] === 'string') {
|
|
188
|
+
result.add(instruction[5]);
|
|
189
|
+
}
|
|
190
|
+
if (instruction[6]) {
|
|
191
|
+
collectAnchorNamesFromInstructions(instruction[6], result);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function compile(template) {
|
|
197
|
+
const targets = template[2];
|
|
198
|
+
for (let targetIndex = 0; targetIndex < targets.length; targetIndex++) {
|
|
199
|
+
const target = targets[targetIndex];
|
|
200
|
+
for (let index = 0; index < target.length; index++) {
|
|
201
|
+
prepareInstruction(target[index]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
for (let targetIndex = 0; targetIndex < targets.length; targetIndex++) {
|
|
206
|
+
resolveJumpTargets(targets[targetIndex], targets);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const labels = new Map();
|
|
210
|
+
const rawLabels = template[3];
|
|
211
|
+
for (let index = 0; index < rawLabels.length; index++) {
|
|
212
|
+
const pair = rawLabels[index];
|
|
213
|
+
labels.set(pair[0], pair[1]);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const anchors = new Map();
|
|
217
|
+
if (template[0]) {
|
|
218
|
+
const anchorNames = new Set();
|
|
219
|
+
collectAnchorNames(targets, anchorNames);
|
|
220
|
+
const resourceCount = targets.length;
|
|
221
|
+
for (const anchor of anchorNames) {
|
|
222
|
+
for (let resource = 0; resource <= resourceCount; resource++) {
|
|
223
|
+
const hash = blazeHash(resource, anchor);
|
|
224
|
+
const targetIndex = labels.get(hash);
|
|
225
|
+
if (targetIndex !== undefined) {
|
|
226
|
+
anchors.set(resource + ':' + anchor, targets[targetIndex]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
template[4] = labels;
|
|
233
|
+
template[5] = anchors;
|
|
234
|
+
return template;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function emitResolve(varName, instanceExpr, relInstance) {
|
|
238
|
+
if (relInstance.length === 0) return `var ${varName}=${instanceExpr};`;
|
|
239
|
+
if (relInstance.length === 1) return `var ${varName}=${instanceExpr}==null?void 0:${instanceExpr}[${JSON.stringify(relInstance[0])}];`;
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function compileInstructionToCode(instruction, captures, visited, budget) {
|
|
244
|
+
if (budget[0] <= 0) { var ci = captures.length; captures.push(instruction); return 'return _fh['+instruction[0]+'](_c['+ci+'],i,d,_t,_v);'; }
|
|
245
|
+
var opcode = instruction[0], ri = instruction[2], value = instruction[5], children = instruction[6];
|
|
246
|
+
function R(v) { return emitResolve(v, 'i', ri); }
|
|
247
|
+
function inlineCondition(child, tv) {
|
|
248
|
+
var op = child[0], cr = child[2], cv = child[5];
|
|
249
|
+
if (cr.length !== 0) return null;
|
|
250
|
+
switch (op) {
|
|
251
|
+
case 11: return '{if(_es(' + tv + ')!==' + cv + ')return false;}';
|
|
252
|
+
case 38: return 'if(' + tv + '!=null&&typeof ' + tv + "==='object'&&!Array.isArray(" + tv + ')){' + emitResolve('t', tv, cr) + 'if(t!==void 0&&_es(t)!==' + cv + ')return false;}';
|
|
253
|
+
default: return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function seq(ci, tv) { var c = ''; for (var j = 0; j < ci.length; j++) { var inl = inlineCondition(ci[j], tv); if (inl !== null) { budget[0] -= inl.length; c += inl; continue; } var r = compileInstructionToCode(ci[j], captures, visited, budget); if (r === null) { var idx = captures.length; captures.push(ci[j]); c += 'if(!_e(_c['+idx+'],'+tv+',d+1,_t,_v))return false;'; } else { budget[0] -= r.length; c += 'if(!(function(i,d,_t,_v){'+r+'})('+tv+',d+1,_t,_v))return false;'; } } return c; }
|
|
257
|
+
function lb(ci, iv) { return seq(ci, iv); }
|
|
258
|
+
function fb(op) { var ci = captures.length; captures.push(instruction); return 'return _fh['+op+'](_c['+ci+'],i,d,_t,_v);'; }
|
|
259
|
+
function cc(child, tv) { var r = compileInstructionToCode(child, captures, visited, budget); if (r === null) { var ci = captures.length; captures.push(child); return '_e(_c['+ci+'],'+tv+',d+1,_t,_v)'; } budget[0] -= r.length; return '(function(i,d,_t,_v){'+r+'})('+tv+',d+1,_t,_v)'; }
|
|
260
|
+
var IO = "if(i==null||typeof i!=='object'||Array.isArray(i))return true;";
|
|
261
|
+
var TO = "if(t==null||typeof t!=='object'||Array.isArray(t))";
|
|
262
|
+
switch (opcode) {
|
|
263
|
+
case 0: return 'return false;';
|
|
264
|
+
case 1: { var r=R('t'); return r?r+TO+'return true;return Object.hasOwn(t,'+JSON.stringify(value)+');':null; }
|
|
265
|
+
case 2: { var r=R('t'); return r?r+"return t!=null&&typeof t==='object'&&!Array.isArray(t)&&Object.hasOwn(t,"+JSON.stringify(value)+');':null; }
|
|
266
|
+
case 3: { var r=R('t'); if(!r)return null; var c=r+TO+'return true;'; for(var j=0;j<value.length;j++)c+='if(!Object.hasOwn(t,'+JSON.stringify(value[j])+'))return false;'; return c+'return true;'; }
|
|
267
|
+
case 4: { var r=R('t'); if(!r)return null; var c=r+TO+'return false;'; for(var j=0;j<value.length;j++)c+='if(!Object.hasOwn(t,'+JSON.stringify(value[j])+'))return false;'; return c+'return true;'; }
|
|
268
|
+
case 5: { var r=R('t'); if(!r)return null; var c=r+TO+'return true;var s=0;for(var k in t)s++;if(s!=='+value.length+')return false;'; for(var j=0;j<value.length;j++)c+='if(!Object.hasOwn(t,'+JSON.stringify(value[j])+'))return false;'; return c+'return true;'; }
|
|
269
|
+
case 6: { var r=R('t'); if(!r)return null; var c=r+TO+'return false;var s=0;for(var k in t)s++;if(s!=='+value.length+')return false;'; for(var j=0;j<value.length;j++)c+='if(!Object.hasOwn(t,'+JSON.stringify(value[j])+'))return false;'; return c+'return true;'; }
|
|
270
|
+
case 7: return fb(7); case 8: return fb(8);
|
|
271
|
+
case 9: { var r=R('t'); return r?r+'var a=_jt(t);if(a==='+value+')return true;return '+value+'===2&&_ii(t);':null; }
|
|
272
|
+
case 10: { var r=R('t'); return r?r+'var a=_jt(t);if(('+value+'&(1<<a))!==0)return true;return('+value+'&4)!==0&&_ii(t);':null; }
|
|
273
|
+
case 11: { var r=R('t'); return r?r+'return _es(t)==='+value+';':null; }
|
|
274
|
+
case 12: { var r=R('t'); return r?r+'return('+value+'&(1<<_es(t)))!==0;':null; }
|
|
275
|
+
case 13: { var r=R('t'); return r?r+"if(typeof t!=='string')return false;var l=_ul(t);if(l<"+value[0]+')return false;'+(value[1]!==null?'if(l>'+value[1]+')return false;':'')+'return true;':null; }
|
|
276
|
+
case 14: { var r=R('t'); return r?r+"return typeof t==='string'&&_ul(t)<="+value+';':null; }
|
|
277
|
+
case 15: { var r=R('t'); return r?r+'if(!Array.isArray(t))return false;if(t.length<'+value[0]+')return false;'+(value[1]!==null?'if(t.length>'+value[1]+')return false;':'')+'return true;':null; }
|
|
278
|
+
case 16: { var r=R('t'); return r?r+'return Array.isArray(t)&&t.length<='+value+';':null; }
|
|
279
|
+
case 17: { var r=R('t'); return r?r+TO+'return false;var s=0;for(var k in t)s++;if(s<'+value[0]+')return false;'+(value[1]!==null?'if(s>'+value[1]+')return false;':'')+'return true;':null; }
|
|
280
|
+
case 18: { var r=R('t'); return r?r+TO+'return false;var s=0;for(var k in t)s++;return s<='+value+';':null; }
|
|
281
|
+
case 19: return fb(19); case 20: return fb(20); case 21: return fb(21);
|
|
282
|
+
case 22: { var r=R('t'); return r?r+'if(!Array.isArray(t))return true;return t.length<'+value+';':null; }
|
|
283
|
+
case 23: { var r=R('t'); return r?r+'if(!Array.isArray(t))return true;return t.length>'+value+';':null; }
|
|
284
|
+
case 24: { var r=R('t'); return r?r+TO+'return true;var s=0;for(var k in t)s++;return s<'+value+';':null; }
|
|
285
|
+
case 25: { var r=R('t'); return r?r+TO+'return true;var s=0;for(var k in t)s++;return s>'+value+';':null; }
|
|
286
|
+
case 26: { if(typeof value==='string'||typeof value==='number'||typeof value==='boolean'||value===null){var r=R('t');return r?r+'return t==='+JSON.stringify(value)+';':null;}return fb(26); }
|
|
287
|
+
case 27: return fb(27); case 28: return fb(28);
|
|
288
|
+
case 29: { var r=R('t'); return r?r+"if(typeof t!=='number')return true;return t>="+value+';':null; }
|
|
289
|
+
case 30: { var r=R('t'); return r?r+"if(typeof t!=='number')return true;return t<="+value+';':null; }
|
|
290
|
+
case 31: { var r=R('t'); return r?r+"if(typeof t!=='number')return true;return t>"+value+';':null; }
|
|
291
|
+
case 32: { var r=R('t'); return r?r+"if(typeof t!=='number')return true;return t<"+value+';':null; }
|
|
292
|
+
case 33: return fb(33); case 34: return fb(34); case 35: return fb(35);
|
|
293
|
+
case 36: { var r=R('t'); return r?IO+r+'if(t===void 0)return true;var a=_jt(t);return a==='+value+'||('+value+'===2&&_ii(t));':null; }
|
|
294
|
+
case 37: return fb(37);
|
|
295
|
+
case 38: { var r=R('t'); return r?IO+r+'if(t===void 0)return true;return _es(t)==='+value+';':null; }
|
|
296
|
+
case 39: return fb(39);
|
|
297
|
+
case 40: { var r=R('t'); return r?IO+r+'if(t===void 0)return true;return('+value+'&(1<<_es(t)))!==0;':null; }
|
|
298
|
+
case 41: return fb(41); case 42: return fb(42); case 43: return fb(43);
|
|
299
|
+
case 44: return 'return true;'; case 45: return 'return true;'; case 46: return 'return true;'; case 47: return 'return true;';
|
|
300
|
+
case 48: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return 'return false;'; var c=r; for(var j=0;j<children.length;j++)c+='if(!'+cc(children[j],'t')+')return true;'; return c+'return false;'; }
|
|
301
|
+
case 49: return fb(49);
|
|
302
|
+
case 50: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return 'return true;'; if(value){var c=r+'var __r=false;';for(var j=0;j<children.length;j++)c+='if('+cc(children[j],'t')+')__r=true;';return c+'return __r;';} var c=r;for(var j=0;j<children.length;j++)c+='if('+cc(children[j],'t')+')return true;';return c+'return false;'; }
|
|
303
|
+
case 51: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return 'return true;'; return r+seq(children,'t')+'return true;'; }
|
|
304
|
+
case 52: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return 'return false;'; var c=r+'var __r=true,__m=false;';for(var j=0;j<children.length;j++){c+='if('+cc(children[j],'t')+'){if(__m){__r=false;'+(!value?'return false;':'')+ '}else __m=true;}';}return c+'return __r&&__m;'; }
|
|
305
|
+
case 53: return fb(53);
|
|
306
|
+
case 54: { var r=R('t'); if(!r)return null; var c=r+'if(_jt(t)!=='+value+')return true;'; if(children&&children.length>0)c+=seq(children,'t'); return c+'return true;'; }
|
|
307
|
+
case 55: { var r=R('t'); if(!r)return null; var c=r+TO+'return true;if(!Object.hasOwn(t,'+JSON.stringify(value)+'))return true;'; if(children&&children.length>0)c+=seq(children,'t'); return c+'return true;'; }
|
|
308
|
+
case 56: { var r=R('t'); if(!r)return null; var c=r+'if(!Array.isArray(t)||t.length<='+value+')return true;'; if(children&&children.length>0)c+=seq(children,'t'); return c+'return true;'; }
|
|
309
|
+
case 57: return fb(57); case 58: return fb(58);
|
|
310
|
+
case 59: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return r+'return true;'; var mi=captures.length; captures.push(value); var gf=''; for(var gi=0;gi<children.length;gi++){var gc=children[gi][6]; if(gc&&gc.length>0){gf+='function(i,d,_t,_v){'+lb(gc,'i')+'return true;},';}else{gf+='null,';}} return r+TO+'return true;var __cg=['+gf+'];for(var k in t){var __mi=_c['+mi+'][k];if(__mi!==void 0){var __cf=__cg[__mi];if(__cf&&!__cf(t,d,_t,_v))return false;}}return true;'; }
|
|
311
|
+
case 60: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return r+'return true;'; var mi=captures.length; captures.push(value); var gf=''; for(var gi=0;gi<children.length;gi++){var gc=children[gi][6]; if(gc&&gc.length>0){gf+='function(i,d,_t,_v){'+lb(gc,'i')+'return true;},';}else{gf+='null,';}} return r+TO+'return true;var __cg=['+gf+'];for(var k in t){var __mi=_c['+mi+'][k];if(__mi===void 0)return false;var __cf=__cg[__mi];if(__cf&&!__cf(t,d,_t,_v))return false;}return true;'; }
|
|
312
|
+
case 61: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return r+'return true;'; return r+TO+'return true;for(var k in t){'+lb(children,'t[k]')+'}return true;'; }
|
|
313
|
+
case 62: return fb(62); case 63: return fb(63); case 64: return fb(64); case 65: return fb(65); case 66: return fb(66);
|
|
314
|
+
case 67: return fb(67); case 68: return fb(68); case 69: return fb(69); case 70: return fb(70);
|
|
315
|
+
case 71: { var r=R('t'); return r?r+TO+'return true;for(var k in t){if(_es(t[k])!=='+value+')return false;}return true;':null; }
|
|
316
|
+
case 72: return fb(72); case 73: return fb(73); case 74: return fb(74); case 75: return fb(75);
|
|
317
|
+
case 76: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return r+'return true;'; return r+'if(!Array.isArray(t))return true;for(var j=0;j<t.length;j++){'+lb(children,'t[j]')+'}return true;'; }
|
|
318
|
+
case 77: { var r=R('t'); if(!r)return null; if(!children||children.length===0)return r+'return true;'; return r+'if(!Array.isArray(t)||'+value+'>=t.length)return true;for(var j='+value+';j<t.length;j++){'+lb(children,'t[j]')+'}return true;'; }
|
|
319
|
+
case 78: return fb(78);
|
|
320
|
+
case 79: { var r=R('t'); return r?r+'if(!Array.isArray(t))return true;for(var j=0;j<t.length;j++){var a=_jt(t[j]);if(a!=='+value+'&&!('+value+'===2&&_ii(t[j])))return false;}return true;':null; }
|
|
321
|
+
case 80: { var r=R('t'); return r?r+'if(!Array.isArray(t))return true;for(var j=0;j<t.length;j++){if(_es(t[j])!=='+value+')return false;}return true;':null; }
|
|
322
|
+
case 81: { var r=R('t'); return r?r+'if(!Array.isArray(t))return true;for(var j=0;j<t.length;j++){if(('+value+'&(1<<_es(t[j])))===0)return false;}return true;':null; }
|
|
323
|
+
case 82: return fb(82); case 83: return fb(83); case 84: return fb(84);
|
|
324
|
+
case 85: { if(!children||children.length===0)return 'return true;'; var c=''; for(var j=0;j<children.length;j++){var r2=compileInstructionToCode(children[j],captures,visited,budget); if(r2===null){var ci=captures.length;captures.push(children[j]);c+='if(!_e(_c['+ci+'],i,d+1,_t,_v))return false;';}else{budget[0]-=r2.length;c+='if(!(function(i,d,_t,_v){'+r2+'})(i,d+1,_t,_v))return false;';}} return c+'return true;'; }
|
|
325
|
+
case 86: { var r=R('t'); if(!r)return null; var c=r+TO+'return true;if(!Object.hasOwn(t,'+JSON.stringify(value)+'))return true;'; if(children&&children.length>0)c+=seq(children,'i'); return c+'return true;'; }
|
|
326
|
+
case 87: { var c=IO+'if(!Object.hasOwn(i,'+JSON.stringify(value)+'))return true;'; if(children&&children.length>0)c+=seq(children,'i'); return c+'return true;'; }
|
|
327
|
+
case 88: { var c='if(_jt(i)!=='+value+')return true;'; if(children&&children.length>0)c+=seq(children,'i'); return c+'return true;'; }
|
|
328
|
+
case 89: return 'return true;';
|
|
329
|
+
case 90: return fb(90);
|
|
330
|
+
case 91: { if(!value)return 'return true;'; if(visited&&visited.has(instruction))return fb(91); if(!visited)visited=new Set(); visited.add(instruction); var r=R('t'); if(!r)return fb(91); var c=r; for(var j=0;j<value.length;j++){var r2=compileInstructionToCode(value[j],captures,visited,budget); if(r2===null){var ci=captures.length;captures.push(value[j]);c+='if(!_e(_c['+ci+'],t,d+1,_t,_v))return false;';}else{budget[0]-=r2.length;c+='if(!(function(i,d,_t,_v){'+r2+'})(t,d+1,_t,_v))return false;';}} return c+'return true;'; }
|
|
331
|
+
default: return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function generateNativeValidator(template) {
|
|
336
|
+
if (template[0] || template[1]) return null;
|
|
337
|
+
const targets = template[2];
|
|
338
|
+
if (targets.length === 0) return () => true;
|
|
339
|
+
const instructions = targets[0];
|
|
340
|
+
if (instructions.length === 0) return () => true;
|
|
341
|
+
|
|
342
|
+
const capturedInstructions = [];
|
|
343
|
+
const budget = [5000000];
|
|
344
|
+
let body = '';
|
|
345
|
+
for (let index = 0; index < instructions.length; index++) {
|
|
346
|
+
const code = compileInstructionToCode(instructions[index], capturedInstructions, null, budget);
|
|
347
|
+
if (code === null) return null;
|
|
348
|
+
budget[0] -= code.length;
|
|
349
|
+
body += `if(!(function(i,d,_t,_v){${code}})(instance,0,_t,_v))return false;`;
|
|
350
|
+
}
|
|
351
|
+
body += 'return true;';
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
const fn = eval(
|
|
355
|
+
'(function(_es,_jt,_ii,_ul,_e,_fh,_c,_t){' +
|
|
356
|
+
'return function(instance,_v){' + body + '};' +
|
|
357
|
+
'})'
|
|
358
|
+
);
|
|
359
|
+
return fn(
|
|
360
|
+
effectiveTypeStrictReal, jsonTypeOf, isIntegral, unicodeLength,
|
|
361
|
+
evaluateInstructionFast, fastHandlers, capturedInstructions, template
|
|
362
|
+
);
|
|
363
|
+
} catch {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
class Blaze {
|
|
369
|
+
constructor(template) {
|
|
370
|
+
compile(template);
|
|
371
|
+
this.template = template;
|
|
372
|
+
this.callbackMode = false;
|
|
373
|
+
this.trackMode = false;
|
|
374
|
+
this.dynamicMode = false;
|
|
375
|
+
this.callback = null;
|
|
376
|
+
this.evaluatePathLength = 0;
|
|
377
|
+
this.evaluatePathTokens = null;
|
|
378
|
+
this.instanceLocationLength = 0;
|
|
379
|
+
this.instanceLocationTokens = null;
|
|
380
|
+
this.resources = null;
|
|
381
|
+
this.evaluated = null;
|
|
382
|
+
this.propertyTarget = undefined;
|
|
383
|
+
this.propertyParent = undefined;
|
|
384
|
+
this.propertyKey = undefined;
|
|
385
|
+
this._nativeValidate = generateNativeValidator(template);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
validate(instance, callback) {
|
|
389
|
+
if (callback === undefined && this._nativeValidate) {
|
|
390
|
+
return this._nativeValidate(instance, this);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const template = this.template;
|
|
394
|
+
const targets = template[2];
|
|
395
|
+
if (targets.length === 0) return true;
|
|
396
|
+
|
|
397
|
+
const track = template[1];
|
|
398
|
+
const dynamic = template[0];
|
|
399
|
+
this.trackMode = track;
|
|
400
|
+
this.dynamicMode = dynamic;
|
|
401
|
+
this.callbackMode = callback !== undefined;
|
|
402
|
+
this.callback = callback;
|
|
403
|
+
|
|
404
|
+
if (this.callbackMode) {
|
|
405
|
+
this.evaluatePathLength = 0;
|
|
406
|
+
this.evaluatePathTokens = [];
|
|
407
|
+
this.instanceLocationLength = 0;
|
|
408
|
+
this.instanceLocationTokens = [];
|
|
409
|
+
this.resources = [];
|
|
410
|
+
if (track || dynamic) {
|
|
411
|
+
evaluateInstruction = evaluateInstructionTrackedCallback;
|
|
412
|
+
if (track) {
|
|
413
|
+
this.evaluated = [];
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
evaluateInstruction = evaluateInstructionFastCallback;
|
|
417
|
+
}
|
|
418
|
+
} else if (track || dynamic) {
|
|
419
|
+
evaluateInstruction = evaluateInstructionTracked;
|
|
420
|
+
if (track) {
|
|
421
|
+
this.evaluatePathLength = 0;
|
|
422
|
+
this.evaluatePathTokens = [];
|
|
423
|
+
this.evaluated = [];
|
|
424
|
+
}
|
|
425
|
+
if (dynamic) {
|
|
426
|
+
this.resources = [];
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
evaluateInstruction = evaluateInstructionFast;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const instructions = targets[0];
|
|
433
|
+
let result = true;
|
|
434
|
+
for (let index = 0; index < instructions.length; index++) {
|
|
435
|
+
if (!evaluateInstruction(instructions[index], instance, 0, template, this)) {
|
|
436
|
+
result = false;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
this.resources = null;
|
|
442
|
+
this.evaluated = null;
|
|
443
|
+
this.evaluatePathTokens = null;
|
|
444
|
+
this.instanceLocationTokens = null;
|
|
445
|
+
this.callback = null;
|
|
446
|
+
this.callbackMode = false;
|
|
447
|
+
return result;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
snapshotPathTokens() {
|
|
451
|
+
return this.evaluatePathTokens.slice(0, this.evaluatePathLength);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
pushPath(relativeSchemaLocation) {
|
|
455
|
+
for (let index = 0; index < relativeSchemaLocation.length; index++) {
|
|
456
|
+
if (this.evaluatePathLength < this.evaluatePathTokens.length) {
|
|
457
|
+
this.evaluatePathTokens[this.evaluatePathLength] = relativeSchemaLocation[index];
|
|
458
|
+
} else {
|
|
459
|
+
this.evaluatePathTokens.push(relativeSchemaLocation[index]);
|
|
460
|
+
}
|
|
461
|
+
this.evaluatePathLength++;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
popPath(count) {
|
|
466
|
+
this.evaluatePathLength -= count;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
callbackPush(instruction) {
|
|
470
|
+
if (!this.trackMode) {
|
|
471
|
+
this.pushPath(instruction[1]);
|
|
472
|
+
}
|
|
473
|
+
const relInstance = instruction[2];
|
|
474
|
+
for (let index = 0; index < relInstance.length; index++) {
|
|
475
|
+
this.pushInstanceToken(relInstance[index]);
|
|
476
|
+
}
|
|
477
|
+
this.callback("pre", true, instruction,
|
|
478
|
+
buildJsonPointer(this.evaluatePathTokens, this.evaluatePathLength),
|
|
479
|
+
buildJsonPointer(this.instanceLocationTokens, this.instanceLocationLength),
|
|
480
|
+
null);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
callbackPop(instruction, result) {
|
|
484
|
+
const isAnnotation = instruction[0] >= ANNOTATION_EMIT &&
|
|
485
|
+
instruction[0] <= ANNOTATION_BASENAME_TO_PARENT;
|
|
486
|
+
this.callback("post", result, instruction,
|
|
487
|
+
buildJsonPointer(this.evaluatePathTokens, this.evaluatePathLength),
|
|
488
|
+
buildJsonPointer(this.instanceLocationTokens, this.instanceLocationLength),
|
|
489
|
+
isAnnotation ? instruction[5] : null);
|
|
490
|
+
if (!this.trackMode) {
|
|
491
|
+
this.popPath(instruction[1].length);
|
|
492
|
+
}
|
|
493
|
+
const relInstance = instruction[2];
|
|
494
|
+
for (let index = 0; index < relInstance.length; index++) {
|
|
495
|
+
this.popInstanceToken();
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
callbackAnnotation(instruction) {
|
|
500
|
+
if (!this.trackMode) {
|
|
501
|
+
this.pushPath(instruction[1]);
|
|
502
|
+
}
|
|
503
|
+
const relInstance = instruction[2];
|
|
504
|
+
for (let index = 0; index < relInstance.length; index++) {
|
|
505
|
+
this.pushInstanceToken(relInstance[index]);
|
|
506
|
+
}
|
|
507
|
+
const evaluatePath = buildJsonPointer(this.evaluatePathTokens, this.evaluatePathLength);
|
|
508
|
+
const opcode = instruction[0];
|
|
509
|
+
let instanceLocation;
|
|
510
|
+
if (opcode === ANNOTATION_EMIT) {
|
|
511
|
+
instanceLocation = buildJsonPointer(this.instanceLocationTokens, this.instanceLocationLength);
|
|
512
|
+
} else {
|
|
513
|
+
const parentLength = this.instanceLocationLength > 0 ? this.instanceLocationLength - 1 : 0;
|
|
514
|
+
instanceLocation = buildJsonPointer(this.instanceLocationTokens, parentLength);
|
|
515
|
+
}
|
|
516
|
+
let annotationValue = instruction[5];
|
|
517
|
+
if (opcode === ANNOTATION_BASENAME_TO_PARENT && this.instanceLocationLength > 0) {
|
|
518
|
+
annotationValue = this.instanceLocationTokens[this.instanceLocationLength - 1];
|
|
519
|
+
}
|
|
520
|
+
this.callback("pre", true, instruction, evaluatePath, instanceLocation, null);
|
|
521
|
+
this.callback("post", true, instruction, evaluatePath, instanceLocation, annotationValue);
|
|
522
|
+
if (!this.trackMode) {
|
|
523
|
+
this.popPath(instruction[1].length);
|
|
524
|
+
}
|
|
525
|
+
for (let index = 0; index < relInstance.length; index++) {
|
|
526
|
+
this.popInstanceToken();
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
pushInstanceToken(token) {
|
|
531
|
+
if (this.instanceLocationLength < this.instanceLocationTokens.length) {
|
|
532
|
+
this.instanceLocationTokens[this.instanceLocationLength] = token;
|
|
533
|
+
} else {
|
|
534
|
+
this.instanceLocationTokens.push(token);
|
|
535
|
+
}
|
|
536
|
+
this.instanceLocationLength++;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
popInstanceToken() {
|
|
540
|
+
this.instanceLocationLength--;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
markEvaluated(target, parent, key) {
|
|
544
|
+
this.evaluated.push({
|
|
545
|
+
instance: target,
|
|
546
|
+
parent: parent,
|
|
547
|
+
key: key,
|
|
548
|
+
pathTokens: this.snapshotPathTokens(),
|
|
549
|
+
pathLength: this.evaluatePathLength,
|
|
550
|
+
skip: false
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
isEvaluated(target, parent, key) {
|
|
555
|
+
const pathLen = this.evaluatePathLength;
|
|
556
|
+
const initialLen = pathLen <= 1 ? 0 : pathLen - 1;
|
|
557
|
+
const initialTokens = this.evaluatePathTokens;
|
|
558
|
+
const isPrimitive = target === null || typeof target !== 'object';
|
|
559
|
+
const hasLocation = parent !== undefined;
|
|
560
|
+
|
|
561
|
+
for (let index = this.evaluated.length - 1; index >= 0; index--) {
|
|
562
|
+
const entry = this.evaluated[index];
|
|
563
|
+
if (entry.skip) continue;
|
|
564
|
+
|
|
565
|
+
if (isPrimitive && hasLocation && entry.parent !== undefined) {
|
|
566
|
+
if (entry.parent !== parent || entry.key !== key) continue;
|
|
567
|
+
} else {
|
|
568
|
+
if (entry.instance !== target) continue;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (initialLen === 0) return true;
|
|
572
|
+
if (entry.pathLength < initialLen) continue;
|
|
573
|
+
let match = true;
|
|
574
|
+
for (let token = 0; token < initialLen; token++) {
|
|
575
|
+
if (entry.pathTokens[token] !== initialTokens[token]) {
|
|
576
|
+
match = false;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (match) return true;
|
|
581
|
+
}
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
unevaluate() {
|
|
586
|
+
const pathLen = this.evaluatePathLength;
|
|
587
|
+
const tokens = this.evaluatePathTokens;
|
|
588
|
+
for (let index = 0; index < this.evaluated.length; index++) {
|
|
589
|
+
const entry = this.evaluated[index];
|
|
590
|
+
if (entry.skip) continue;
|
|
591
|
+
if (entry.pathLength < pathLen) continue;
|
|
592
|
+
let match = true;
|
|
593
|
+
for (let token = 0; token < pathLen; token++) {
|
|
594
|
+
if (entry.pathTokens[token] !== tokens[token]) {
|
|
595
|
+
match = false;
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if (match) entry.skip = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function evaluateInstructionFast(instruction, instance, depth, template, evaluator) {
|
|
605
|
+
if (depth > DEPTH_LIMIT) {
|
|
606
|
+
throw new Error('The evaluation path depth limit was reached likely due to infinite recursion');
|
|
607
|
+
}
|
|
608
|
+
const handler = fastHandlers[instruction[0]];
|
|
609
|
+
if (!handler) return true;
|
|
610
|
+
return handler(instruction, instance, depth, template, evaluator);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function evaluateInstructionTracked(instruction, instance, depth, template, evaluator) {
|
|
614
|
+
if (depth > DEPTH_LIMIT) {
|
|
615
|
+
throw new Error('The evaluation path depth limit was reached likely due to infinite recursion');
|
|
616
|
+
}
|
|
617
|
+
const handler = fastHandlers[instruction[0]];
|
|
618
|
+
if (!handler) return true;
|
|
619
|
+
|
|
620
|
+
const type = instruction[0];
|
|
621
|
+
if (type < 85 || type > 89) {
|
|
622
|
+
if (evaluator.trackMode) {
|
|
623
|
+
evaluator.pushPath(instruction[1]);
|
|
624
|
+
}
|
|
625
|
+
if (evaluator.dynamicMode) {
|
|
626
|
+
evaluator.resources.push(instruction[4]);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const result = handler(instruction, instance, depth, template, evaluator);
|
|
630
|
+
|
|
631
|
+
if (evaluator.trackMode) {
|
|
632
|
+
evaluator.popPath(instruction[1].length);
|
|
633
|
+
}
|
|
634
|
+
if (evaluator.dynamicMode) {
|
|
635
|
+
evaluator.resources.pop();
|
|
636
|
+
}
|
|
637
|
+
return result;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return handler(instruction, instance, depth, template, evaluator);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function evaluateInstructionFastCallback(instruction, instance, depth, template, evaluator) {
|
|
644
|
+
if (depth > DEPTH_LIMIT) {
|
|
645
|
+
throw new Error('The evaluation path depth limit was reached likely due to infinite recursion');
|
|
646
|
+
}
|
|
647
|
+
const handler = handlers[instruction[0]];
|
|
648
|
+
if (!handler) return true;
|
|
649
|
+
return handler(instruction, instance, depth, template, evaluator);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function evaluateInstructionTrackedCallback(instruction, instance, depth, template, evaluator) {
|
|
653
|
+
if (depth > DEPTH_LIMIT) {
|
|
654
|
+
throw new Error('The evaluation path depth limit was reached likely due to infinite recursion');
|
|
655
|
+
}
|
|
656
|
+
const handler = handlers[instruction[0]];
|
|
657
|
+
if (!handler) return true;
|
|
658
|
+
|
|
659
|
+
const type = instruction[0];
|
|
660
|
+
if (type < CONTROL_GROUP_START || type > CONTROL_EVALUATE_END) {
|
|
661
|
+
if (evaluator.trackMode) {
|
|
662
|
+
evaluator.pushPath(instruction[1]);
|
|
663
|
+
}
|
|
664
|
+
if (evaluator.dynamicMode) {
|
|
665
|
+
evaluator.resources.push(instruction[4]);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const result = handler(instruction, instance, depth, template, evaluator);
|
|
669
|
+
|
|
670
|
+
if (evaluator.trackMode) {
|
|
671
|
+
evaluator.popPath(instruction[1].length);
|
|
672
|
+
}
|
|
673
|
+
if (evaluator.dynamicMode) {
|
|
674
|
+
evaluator.resources.pop();
|
|
675
|
+
}
|
|
676
|
+
return result;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return handler(instruction, instance, depth, template, evaluator);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
let evaluateInstruction = evaluateInstructionFast;
|
|
683
|
+
|
|
684
|
+
function effectiveTypeStrictReal(value) {
|
|
685
|
+
if (value === null) return Type.Null;
|
|
686
|
+
switch (typeof value) {
|
|
687
|
+
case 'boolean': return Type.Boolean;
|
|
688
|
+
case 'number': return Number.isInteger(value) ? Type.Integer : Type.Real;
|
|
689
|
+
case 'string': return Type.String;
|
|
690
|
+
case 'object': return Array.isArray(value) ? Type.Array : Type.Object;
|
|
691
|
+
default: return Type.Null;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function typeSetTest(bitmask, typeIndex) {
|
|
696
|
+
return (bitmask & (1 << typeIndex)) !== 0;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function jsonEqual(left, right) {
|
|
700
|
+
if (left === right) return true;
|
|
701
|
+
if (left === null || right === null) return left === right;
|
|
702
|
+
if (typeof left !== typeof right) return false;
|
|
703
|
+
if (typeof left !== 'object') return left === right;
|
|
704
|
+
if (Array.isArray(left) !== Array.isArray(right)) return false;
|
|
705
|
+
if (Array.isArray(left)) {
|
|
706
|
+
if (left.length !== right.length) return false;
|
|
707
|
+
for (let index = 0; index < left.length; index++) {
|
|
708
|
+
if (!jsonEqual(left[index], right[index])) return false;
|
|
709
|
+
}
|
|
710
|
+
return true;
|
|
711
|
+
}
|
|
712
|
+
const keysLeft = Object.keys(left);
|
|
713
|
+
const keysRight = Object.keys(right);
|
|
714
|
+
if (keysLeft.length !== keysRight.length) return false;
|
|
715
|
+
for (let index = 0; index < keysLeft.length; index++) {
|
|
716
|
+
const key = keysLeft[index];
|
|
717
|
+
if (!Object.hasOwn(right, key)) return false;
|
|
718
|
+
if (!jsonEqual(left[key], right[key])) return false;
|
|
719
|
+
}
|
|
720
|
+
return true;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function fastHash(value) {
|
|
724
|
+
if (value === null) return 2;
|
|
725
|
+
switch (typeof value) {
|
|
726
|
+
case 'boolean': return value ? 1 : 0;
|
|
727
|
+
case 'number': return 4 + ((value | 0) & 255);
|
|
728
|
+
case 'string': return 3 + value.length;
|
|
729
|
+
case 'object':
|
|
730
|
+
if (Array.isArray(value)) {
|
|
731
|
+
let hash = 6;
|
|
732
|
+
for (let index = 0; index < value.length; index++) hash += 1 + fastHash(value[index]);
|
|
733
|
+
return hash;
|
|
734
|
+
} else {
|
|
735
|
+
let hash = 7;
|
|
736
|
+
for (const key in value) hash += 1 + key.length + fastHash(value[key]);
|
|
737
|
+
return hash;
|
|
738
|
+
}
|
|
739
|
+
default: return 2;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function isUnique(array) {
|
|
744
|
+
const length = array.length;
|
|
745
|
+
if (length <= 1) return true;
|
|
746
|
+
const first = array[0];
|
|
747
|
+
const firstType = typeof first;
|
|
748
|
+
if (first !== null && firstType !== 'object') {
|
|
749
|
+
let allPrimitive = true;
|
|
750
|
+
for (let index = 1; index < length; index++) {
|
|
751
|
+
const element = array[index];
|
|
752
|
+
if (element === null || typeof element === 'object') {
|
|
753
|
+
allPrimitive = false;
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (allPrimitive) {
|
|
758
|
+
const set = new Set();
|
|
759
|
+
for (let index = 0; index < length; index++) {
|
|
760
|
+
const size = set.size;
|
|
761
|
+
set.add(array[index]);
|
|
762
|
+
if (set.size === size) return false;
|
|
763
|
+
}
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
const hashes = new Array(length);
|
|
768
|
+
for (let index = 0; index < length; index++) {
|
|
769
|
+
hashes[index] = fastHash(array[index]);
|
|
770
|
+
}
|
|
771
|
+
for (let index = 1; index < length; index++) {
|
|
772
|
+
for (let previous = 0; previous < index; previous++) {
|
|
773
|
+
if (hashes[index] === hashes[previous] && jsonEqual(array[index], array[previous])) return false;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
return true;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function isDivisibleBy(value, divisor) {
|
|
780
|
+
if (divisor === 0) return false;
|
|
781
|
+
const remainder = value % divisor;
|
|
782
|
+
if (remainder === 0) return true;
|
|
783
|
+
return Math.abs(remainder) < 1e-9 || Math.abs(remainder - divisor) < 1e-9 ||
|
|
784
|
+
Math.abs(remainder + divisor) < 1e-9;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function unicodeLength(string) {
|
|
788
|
+
let count = 0;
|
|
789
|
+
for (let index = 0; index < string.length; index++) {
|
|
790
|
+
count++;
|
|
791
|
+
const code = string.charCodeAt(index);
|
|
792
|
+
if (code >= 0xD800 && code <= 0xDBFF) index++;
|
|
793
|
+
}
|
|
794
|
+
return count;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function objectSize(object) {
|
|
798
|
+
let count = 0;
|
|
799
|
+
for (const key in object) count++;
|
|
800
|
+
return count;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function isObject(value) {
|
|
804
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function AssertionFail(instruction, instance, depth, template, evaluator) {
|
|
808
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
809
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
810
|
+
return false;
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
function AssertionDefines(instruction, instance, depth, template, evaluator) {
|
|
814
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
815
|
+
if (!isObject(target)) return true;
|
|
816
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
817
|
+
const __result = Object.hasOwn(target, instruction[5]);
|
|
818
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
819
|
+
return __result;
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
function AssertionDefinesStrict(instruction, instance, depth, template, evaluator) {
|
|
823
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
824
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
825
|
+
if (!isObject(target)) {
|
|
826
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
const __result = Object.hasOwn(target, instruction[5]);
|
|
830
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
831
|
+
return __result;
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
function AssertionDefinesAll(instruction, instance, depth, template, evaluator) {
|
|
835
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
836
|
+
if (!isObject(target)) return true;
|
|
837
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
838
|
+
const strings = instruction[5];
|
|
839
|
+
for (let index = 0; index < strings.length; index++) {
|
|
840
|
+
if (!Object.hasOwn(target, strings[index])) {
|
|
841
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
846
|
+
return true;
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
function AssertionDefinesAllStrict(instruction, instance, depth, template, evaluator) {
|
|
850
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
851
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
852
|
+
if (!isObject(target)) {
|
|
853
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
const strings = instruction[5];
|
|
857
|
+
for (let index = 0; index < strings.length; index++) {
|
|
858
|
+
if (!Object.hasOwn(target, strings[index])) {
|
|
859
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
864
|
+
return true;
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
function AssertionDefinesExactly(instruction, instance, depth, template, evaluator) {
|
|
868
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
869
|
+
if (!isObject(target)) return true;
|
|
870
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
871
|
+
let targetSize = 0;
|
|
872
|
+
for (const key in target) targetSize++;
|
|
873
|
+
const strings = instruction[5];
|
|
874
|
+
if (targetSize !== strings.length) {
|
|
875
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
876
|
+
return false;
|
|
877
|
+
}
|
|
878
|
+
for (let index = 0; index < strings.length; index++) {
|
|
879
|
+
if (!Object.hasOwn(target, strings[index])) {
|
|
880
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
885
|
+
return true;
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
function AssertionDefinesExactlyStrict(instruction, instance, depth, template, evaluator) {
|
|
889
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
890
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
891
|
+
if (!isObject(target)) {
|
|
892
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
893
|
+
return false;
|
|
894
|
+
}
|
|
895
|
+
let targetSize = 0;
|
|
896
|
+
for (const key in target) targetSize++;
|
|
897
|
+
const strings = instruction[5];
|
|
898
|
+
if (targetSize !== strings.length) {
|
|
899
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
900
|
+
return false;
|
|
901
|
+
}
|
|
902
|
+
for (let index = 0; index < strings.length; index++) {
|
|
903
|
+
if (!Object.hasOwn(target, strings[index])) {
|
|
904
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
909
|
+
return true;
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
function AssertionDefinesExactlyStrictHash3(instruction, instance, depth, template, evaluator) {
|
|
913
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
914
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
915
|
+
if (!isObject(target)) {
|
|
916
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
const entries = instruction[5][0];
|
|
920
|
+
let count = 0;
|
|
921
|
+
for (const key in target) count++;
|
|
922
|
+
if (count !== 3) {
|
|
923
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
const __result = Object.hasOwn(target, entries[0][1]) &&
|
|
927
|
+
Object.hasOwn(target, entries[1][1]) &&
|
|
928
|
+
Object.hasOwn(target, entries[2][1]);
|
|
929
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
930
|
+
return __result;
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
function AssertionPropertyDependencies(instruction, instance, depth, template, evaluator) {
|
|
934
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
935
|
+
if (!isObject(target)) return true;
|
|
936
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
937
|
+
const value = instruction[5];
|
|
938
|
+
for (const property in value) {
|
|
939
|
+
if (!Object.hasOwn(target, property)) continue;
|
|
940
|
+
const dependencies = value[property];
|
|
941
|
+
for (let index = 0; index < dependencies.length; index++) {
|
|
942
|
+
if (!Object.hasOwn(target, dependencies[index])) {
|
|
943
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
949
|
+
return true;
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
function AssertionType(instruction, instance, depth, template, evaluator) {
|
|
953
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
954
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
955
|
+
const expected = instruction[5];
|
|
956
|
+
const actual = jsonTypeOf(target);
|
|
957
|
+
if (actual === expected) {
|
|
958
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
961
|
+
if (expected === Type.Integer && isIntegral(target)) {
|
|
962
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
963
|
+
return true;
|
|
964
|
+
}
|
|
965
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
966
|
+
return false;
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
function AssertionTypeAny(instruction, instance, depth, template, evaluator) {
|
|
970
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
971
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
972
|
+
const bitmask = instruction[5];
|
|
973
|
+
const typeIndex = jsonTypeOf(target);
|
|
974
|
+
if (typeSetTest(bitmask, typeIndex)) {
|
|
975
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
976
|
+
return true;
|
|
977
|
+
}
|
|
978
|
+
if (typeSetTest(bitmask, Type.Integer) && isIntegral(target)) {
|
|
979
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
980
|
+
return true;
|
|
981
|
+
}
|
|
982
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
983
|
+
return false;
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
function AssertionTypeStrict(instruction, instance, depth, template, evaluator) {
|
|
987
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
988
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
989
|
+
const __result = effectiveTypeStrictReal(target) === instruction[5];
|
|
990
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
991
|
+
return __result;
|
|
992
|
+
};
|
|
993
|
+
|
|
994
|
+
function AssertionTypeStrictAny(instruction, instance, depth, template, evaluator) {
|
|
995
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
996
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
997
|
+
const __result = typeSetTest(instruction[5], effectiveTypeStrictReal(target));
|
|
998
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
999
|
+
return __result;
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
function AssertionTypeStringBounded(instruction, instance, depth, template, evaluator) {
|
|
1003
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1004
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1005
|
+
if (typeof target !== 'string') {
|
|
1006
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
const range = instruction[5];
|
|
1010
|
+
const length = unicodeLength(target);
|
|
1011
|
+
if (length < range[0]) {
|
|
1012
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
if (range[1] !== null && length > range[1]) {
|
|
1016
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1017
|
+
return false;
|
|
1018
|
+
}
|
|
1019
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1020
|
+
return true;
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
function AssertionTypeStringUpper(instruction, instance, depth, template, evaluator) {
|
|
1024
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1025
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1026
|
+
const __result = typeof target === 'string' && unicodeLength(target) <= instruction[5];
|
|
1027
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1028
|
+
return __result;
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
function AssertionTypeArrayBounded(instruction, instance, depth, template, evaluator) {
|
|
1032
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1033
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1034
|
+
if (!Array.isArray(target)) {
|
|
1035
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1036
|
+
return false;
|
|
1037
|
+
}
|
|
1038
|
+
const range = instruction[5];
|
|
1039
|
+
if (target.length < range[0]) {
|
|
1040
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
if (range[1] !== null && target.length > range[1]) {
|
|
1044
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1045
|
+
return false;
|
|
1046
|
+
}
|
|
1047
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1048
|
+
return true;
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
function AssertionTypeArrayUpper(instruction, instance, depth, template, evaluator) {
|
|
1052
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1053
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1054
|
+
const __result = Array.isArray(target) && target.length <= instruction[5];
|
|
1055
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1056
|
+
return __result;
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
function AssertionTypeObjectBounded(instruction, instance, depth, template, evaluator) {
|
|
1060
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1061
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1062
|
+
if (!isObject(target)) {
|
|
1063
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
const range = instruction[5];
|
|
1067
|
+
const size = objectSize(target);
|
|
1068
|
+
if (size < range[0]) {
|
|
1069
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1070
|
+
return false;
|
|
1071
|
+
}
|
|
1072
|
+
if (range[1] !== null && size > range[1]) {
|
|
1073
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1074
|
+
return false;
|
|
1075
|
+
}
|
|
1076
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1077
|
+
return true;
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
function AssertionTypeObjectUpper(instruction, instance, depth, template, evaluator) {
|
|
1081
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1082
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1083
|
+
if (!isObject(target)) {
|
|
1084
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1085
|
+
return false;
|
|
1086
|
+
}
|
|
1087
|
+
const __result = objectSize(target) <= instruction[5];
|
|
1088
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1089
|
+
return __result;
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
function AssertionRegex(instruction, instance, depth, template, evaluator) {
|
|
1093
|
+
const target = evaluator.propertyTarget !== undefined
|
|
1094
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
1095
|
+
if (typeof target !== 'string') return true;
|
|
1096
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1097
|
+
const __result = instruction[5].test(target);
|
|
1098
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1099
|
+
return __result;
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
function AssertionStringSizeLess(instruction, instance, depth, template, evaluator) {
|
|
1103
|
+
const target = evaluator.propertyTarget !== undefined
|
|
1104
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
1105
|
+
if (typeof target !== 'string') return true;
|
|
1106
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1107
|
+
const __result = unicodeLength(target) < instruction[5];
|
|
1108
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1109
|
+
return __result;
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
function AssertionStringSizeGreater(instruction, instance, depth, template, evaluator) {
|
|
1113
|
+
const target = evaluator.propertyTarget !== undefined
|
|
1114
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
1115
|
+
if (typeof target !== 'string') return true;
|
|
1116
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1117
|
+
const __result = unicodeLength(target) > instruction[5];
|
|
1118
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1119
|
+
return __result;
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
function AssertionArraySizeLess(instruction, instance, depth, template, evaluator) {
|
|
1123
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1124
|
+
if (!Array.isArray(target)) return true;
|
|
1125
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1126
|
+
const __result = target.length < instruction[5];
|
|
1127
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1128
|
+
return __result;
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
function AssertionArraySizeGreater(instruction, instance, depth, template, evaluator) {
|
|
1132
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1133
|
+
if (!Array.isArray(target)) return true;
|
|
1134
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1135
|
+
const __result = target.length > instruction[5];
|
|
1136
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1137
|
+
return __result;
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
function AssertionObjectSizeLess(instruction, instance, depth, template, evaluator) {
|
|
1141
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1142
|
+
if (!isObject(target)) return true;
|
|
1143
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1144
|
+
const __result = objectSize(target) < instruction[5];
|
|
1145
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1146
|
+
return __result;
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
function AssertionObjectSizeGreater(instruction, instance, depth, template, evaluator) {
|
|
1150
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1151
|
+
if (!isObject(target)) return true;
|
|
1152
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1153
|
+
const __result = objectSize(target) > instruction[5];
|
|
1154
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1155
|
+
return __result;
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
function AssertionEqual(instruction, instance, depth, template, evaluator) {
|
|
1159
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1160
|
+
let __result;
|
|
1161
|
+
if (evaluator.propertyTarget !== undefined) {
|
|
1162
|
+
const value = instruction[5];
|
|
1163
|
+
__result = typeof value === 'string' && value === evaluator.propertyTarget;
|
|
1164
|
+
} else {
|
|
1165
|
+
__result = jsonEqual(resolveInstance(instance, instruction[2]), instruction[5]);
|
|
1166
|
+
}
|
|
1167
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1168
|
+
return __result;
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1171
|
+
function AssertionEqualsAny(instruction, instance, depth, template, evaluator) {
|
|
1172
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1173
|
+
const value = instruction[5];
|
|
1174
|
+
const target = evaluator.propertyTarget !== undefined
|
|
1175
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
1176
|
+
if (value.primitive) {
|
|
1177
|
+
const __result = value.set.has(target);
|
|
1178
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1179
|
+
return __result;
|
|
1180
|
+
}
|
|
1181
|
+
const values = Array.isArray(value) ? value : value.values;
|
|
1182
|
+
for (let index = 0; index < values.length; index++) {
|
|
1183
|
+
if (jsonEqual(target, values[index])) {
|
|
1184
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1185
|
+
return true;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1189
|
+
return false;
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
function AssertionEqualsAnyStringHash(instruction, instance, depth, template, evaluator) {
|
|
1193
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1194
|
+
const target = evaluator.propertyTarget !== undefined
|
|
1195
|
+
? evaluator.propertyTarget
|
|
1196
|
+
: resolveInstance(instance, instruction[2]);
|
|
1197
|
+
if (typeof target !== 'string') {
|
|
1198
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1199
|
+
return false;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
const value = instruction[5];
|
|
1203
|
+
const entries = value[0];
|
|
1204
|
+
const tableOfContents = value[1];
|
|
1205
|
+
|
|
1206
|
+
const stringSize = target.length;
|
|
1207
|
+
if (stringSize < tableOfContents.length) {
|
|
1208
|
+
const hint = tableOfContents[stringSize];
|
|
1209
|
+
if (hint[1] === 0) {
|
|
1210
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1211
|
+
return false;
|
|
1212
|
+
}
|
|
1213
|
+
for (let index = hint[0] - 1; index < hint[1]; index++) {
|
|
1214
|
+
if (entries[index][1] === target) {
|
|
1215
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1216
|
+
return true;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1220
|
+
return false;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1224
|
+
return false;
|
|
1225
|
+
};
|
|
1226
|
+
|
|
1227
|
+
function AssertionGreaterEqual(instruction, instance, depth, template, evaluator) {
|
|
1228
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1229
|
+
if (typeof target !== 'number') return true;
|
|
1230
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1231
|
+
const __result = target >= instruction[5];
|
|
1232
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1233
|
+
return __result;
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
function AssertionLessEqual(instruction, instance, depth, template, evaluator) {
|
|
1237
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1238
|
+
if (typeof target !== 'number') return true;
|
|
1239
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1240
|
+
const __result = target <= instruction[5];
|
|
1241
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1242
|
+
return __result;
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
function AssertionGreater(instruction, instance, depth, template, evaluator) {
|
|
1246
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1247
|
+
if (typeof target !== 'number') return true;
|
|
1248
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1249
|
+
const __result = target > instruction[5];
|
|
1250
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1251
|
+
return __result;
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
function AssertionLess(instruction, instance, depth, template, evaluator) {
|
|
1255
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1256
|
+
if (typeof target !== 'number') return true;
|
|
1257
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1258
|
+
const __result = target < instruction[5];
|
|
1259
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1260
|
+
return __result;
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
function AssertionUnique(instruction, instance, depth, template, evaluator) {
|
|
1264
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1265
|
+
if (!Array.isArray(target)) return true;
|
|
1266
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1267
|
+
const __result = isUnique(target);
|
|
1268
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1269
|
+
return __result;
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
function AssertionDivisible(instruction, instance, depth, template, evaluator) {
|
|
1273
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1274
|
+
if (typeof target !== 'number') return true;
|
|
1275
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1276
|
+
const __result = isDivisibleBy(target, instruction[5]);
|
|
1277
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1278
|
+
return __result;
|
|
1279
|
+
};
|
|
1280
|
+
|
|
1281
|
+
function AssertionStringType(instruction, instance, depth, template, evaluator) {
|
|
1282
|
+
const target = evaluator.propertyTarget !== undefined
|
|
1283
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
1284
|
+
if (typeof target !== 'string') return true;
|
|
1285
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1286
|
+
const __result = URI_REGEX.test(target);
|
|
1287
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1288
|
+
return __result;
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1291
|
+
function AssertionPropertyType(instruction, instance, depth, template, evaluator) {
|
|
1292
|
+
if (!isObject(instance)) return true;
|
|
1293
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1294
|
+
if (target === undefined) return true;
|
|
1295
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1296
|
+
const expected = instruction[5];
|
|
1297
|
+
const actual = jsonTypeOf(target);
|
|
1298
|
+
const __result = actual === expected || (expected === Type.Integer && isIntegral(target));
|
|
1299
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1300
|
+
return __result;
|
|
1301
|
+
};
|
|
1302
|
+
|
|
1303
|
+
function AssertionPropertyTypeEvaluate(instruction, instance, depth, template, evaluator) {
|
|
1304
|
+
if (!isObject(instance)) return true;
|
|
1305
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1306
|
+
if (target === undefined) return true;
|
|
1307
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1308
|
+
const expected = instruction[5];
|
|
1309
|
+
const actual = jsonTypeOf(target);
|
|
1310
|
+
const result = actual === expected || (expected === Type.Integer && isIntegral(target));
|
|
1311
|
+
if (result && evaluator.trackMode) {
|
|
1312
|
+
const location = instruction[2];
|
|
1313
|
+
evaluator.markEvaluated(target, instance, location.length > 0 ? location[location.length - 1] : undefined);
|
|
1314
|
+
}
|
|
1315
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, result);
|
|
1316
|
+
return result;
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
function AssertionPropertyTypeStrict(instruction, instance, depth, template, evaluator) {
|
|
1320
|
+
if (!isObject(instance)) return true;
|
|
1321
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1322
|
+
if (target === undefined) return true;
|
|
1323
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1324
|
+
const __result = effectiveTypeStrictReal(target) === instruction[5];
|
|
1325
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1326
|
+
return __result;
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
function AssertionPropertyTypeStrictEvaluate(instruction, instance, depth, template, evaluator) {
|
|
1330
|
+
if (!isObject(instance)) return true;
|
|
1331
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1332
|
+
if (target === undefined) return true;
|
|
1333
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1334
|
+
const result = effectiveTypeStrictReal(target) === instruction[5];
|
|
1335
|
+
if (result && evaluator.trackMode) {
|
|
1336
|
+
const location = instruction[2];
|
|
1337
|
+
evaluator.markEvaluated(target, instance, location.length > 0 ? location[location.length - 1] : undefined);
|
|
1338
|
+
}
|
|
1339
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, result);
|
|
1340
|
+
return result;
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
function AssertionPropertyTypeStrictAny(instruction, instance, depth, template, evaluator) {
|
|
1344
|
+
if (!isObject(instance)) return true;
|
|
1345
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1346
|
+
if (target === undefined) return true;
|
|
1347
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1348
|
+
const __result = typeSetTest(instruction[5], effectiveTypeStrictReal(target));
|
|
1349
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1350
|
+
return __result;
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
function AssertionPropertyTypeStrictAnyEvaluate(instruction, instance, depth, template, evaluator) {
|
|
1354
|
+
if (!isObject(instance)) return true;
|
|
1355
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1356
|
+
if (target === undefined) return true;
|
|
1357
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1358
|
+
const result = typeSetTest(instruction[5], effectiveTypeStrictReal(target));
|
|
1359
|
+
if (result && evaluator.trackMode) {
|
|
1360
|
+
const location = instruction[2];
|
|
1361
|
+
evaluator.markEvaluated(target, instance, location.length > 0 ? location[location.length - 1] : undefined);
|
|
1362
|
+
}
|
|
1363
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, result);
|
|
1364
|
+
return result;
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
function AssertionArrayPrefix(instruction, instance, depth, template, evaluator) {
|
|
1368
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1369
|
+
if (!Array.isArray(target)) return true;
|
|
1370
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1371
|
+
if (target.length === 0) {
|
|
1372
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1373
|
+
return true;
|
|
1374
|
+
}
|
|
1375
|
+
const children = instruction[6];
|
|
1376
|
+
const prefixes = children.length - 1;
|
|
1377
|
+
const pointer = target.length === prefixes ? prefixes : Math.min(target.length, prefixes) - 1;
|
|
1378
|
+
const entry = children[pointer];
|
|
1379
|
+
const entryChildren = entry[6];
|
|
1380
|
+
if (entryChildren) {
|
|
1381
|
+
for (let index = 0; index < entryChildren.length; index++) {
|
|
1382
|
+
if (!evaluateInstruction(entryChildren[index], target, depth + 1, template, evaluator)) {
|
|
1383
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1384
|
+
return false;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1389
|
+
return true;
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
function AssertionArrayPrefixEvaluate(instruction, instance, depth, template, evaluator) {
|
|
1393
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1394
|
+
if (!Array.isArray(target)) return true;
|
|
1395
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1396
|
+
if (target.length === 0) {
|
|
1397
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1398
|
+
return true;
|
|
1399
|
+
}
|
|
1400
|
+
const children = instruction[6];
|
|
1401
|
+
const prefixes = children.length - 1;
|
|
1402
|
+
const pointer = target.length === prefixes ? prefixes : Math.min(target.length, prefixes) - 1;
|
|
1403
|
+
const entry = children[pointer];
|
|
1404
|
+
const entryChildren = entry[6];
|
|
1405
|
+
if (entryChildren) {
|
|
1406
|
+
for (let index = 0; index < entryChildren.length; index++) {
|
|
1407
|
+
if (!evaluateInstruction(entryChildren[index], target, depth + 1, template, evaluator)) {
|
|
1408
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
if (evaluator.trackMode) {
|
|
1414
|
+
if (target.length === prefixes) {
|
|
1415
|
+
evaluator.markEvaluated(target);
|
|
1416
|
+
} else {
|
|
1417
|
+
for (let cursor = 0; cursor <= pointer; cursor++) {
|
|
1418
|
+
evaluator.markEvaluated(target[cursor], target, cursor);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1423
|
+
return true;
|
|
1424
|
+
};
|
|
1425
|
+
|
|
1426
|
+
function AnnotationEmit(instruction, instance, depth, template, evaluator) {
|
|
1427
|
+
if (evaluator.callbackMode) evaluator.callbackAnnotation(instruction);
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
function AnnotationToParent(instruction, instance, depth, template, evaluator) {
|
|
1431
|
+
if (evaluator.callbackMode) evaluator.callbackAnnotation(instruction);
|
|
1432
|
+
return true;
|
|
1433
|
+
}
|
|
1434
|
+
function AnnotationBasenameToParent(instruction, instance, depth, template, evaluator) {
|
|
1435
|
+
if (evaluator.callbackMode) evaluator.callbackAnnotation(instruction);
|
|
1436
|
+
return true;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
function Evaluate(instruction, instance, depth, template, evaluator) {
|
|
1440
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1441
|
+
if (evaluator.trackMode) {
|
|
1442
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1443
|
+
evaluator.markEvaluated(target);
|
|
1444
|
+
}
|
|
1445
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1446
|
+
return true;
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
function LogicalNot(instruction, instance, depth, template, evaluator) {
|
|
1450
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1451
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1452
|
+
const children = instruction[6];
|
|
1453
|
+
if (children) {
|
|
1454
|
+
for (let index = 0; index < children.length; index++) {
|
|
1455
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1456
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1457
|
+
return true;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1462
|
+
return false;
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1465
|
+
function LogicalNotEvaluate(instruction, instance, depth, template, evaluator) {
|
|
1466
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1467
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1468
|
+
const children = instruction[6];
|
|
1469
|
+
let result = false;
|
|
1470
|
+
if (children) {
|
|
1471
|
+
for (let index = 0; index < children.length; index++) {
|
|
1472
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1473
|
+
result = true;
|
|
1474
|
+
break;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
if (evaluator.trackMode) evaluator.unevaluate();
|
|
1479
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, result);
|
|
1480
|
+
return result;
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
function LogicalOr(instruction, instance, depth, template, evaluator) {
|
|
1484
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1485
|
+
const children = instruction[6];
|
|
1486
|
+
if (!children || children.length === 0) {
|
|
1487
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1488
|
+
return true;
|
|
1489
|
+
}
|
|
1490
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1491
|
+
const exhaustive = instruction[5];
|
|
1492
|
+
let result = false;
|
|
1493
|
+
if (exhaustive) {
|
|
1494
|
+
for (let index = 0; index < children.length; index++) {
|
|
1495
|
+
if (evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1496
|
+
result = true;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
} else {
|
|
1500
|
+
for (let index = 0; index < children.length; index++) {
|
|
1501
|
+
if (evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1502
|
+
result = true;
|
|
1503
|
+
break;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, result);
|
|
1508
|
+
return result;
|
|
1509
|
+
};
|
|
1510
|
+
|
|
1511
|
+
function LogicalAnd(instruction, instance, depth, template, evaluator) {
|
|
1512
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1513
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1514
|
+
const children = instruction[6];
|
|
1515
|
+
if (children) {
|
|
1516
|
+
for (let index = 0; index < children.length; index++) {
|
|
1517
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1518
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1519
|
+
return false;
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1524
|
+
return true;
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
function LogicalXor(instruction, instance, depth, template, evaluator) {
|
|
1528
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1529
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1530
|
+
const exhaustive = instruction[5];
|
|
1531
|
+
const children = instruction[6];
|
|
1532
|
+
let result = true;
|
|
1533
|
+
let hasMatched = false;
|
|
1534
|
+
if (children) {
|
|
1535
|
+
for (let index = 0; index < children.length; index++) {
|
|
1536
|
+
if (evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1537
|
+
if (hasMatched) {
|
|
1538
|
+
result = false;
|
|
1539
|
+
if (!exhaustive) break;
|
|
1540
|
+
} else {
|
|
1541
|
+
hasMatched = true;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
const __result = result && hasMatched;
|
|
1547
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
1548
|
+
return __result;
|
|
1549
|
+
};
|
|
1550
|
+
|
|
1551
|
+
function LogicalCondition(instruction, instance, depth, template, evaluator) {
|
|
1552
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1553
|
+
const value = instruction[5];
|
|
1554
|
+
const thenStart = value[0];
|
|
1555
|
+
const elseStart = value[1];
|
|
1556
|
+
const children = instruction[6];
|
|
1557
|
+
const childrenSize = children ? children.length : 0;
|
|
1558
|
+
|
|
1559
|
+
let conditionEnd = childrenSize;
|
|
1560
|
+
if (thenStart > 0) conditionEnd = thenStart;
|
|
1561
|
+
else if (elseStart > 0) conditionEnd = elseStart;
|
|
1562
|
+
|
|
1563
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1564
|
+
|
|
1565
|
+
let conditionResult = true;
|
|
1566
|
+
for (let cursor = 0; cursor < conditionEnd; cursor++) {
|
|
1567
|
+
if (!evaluateInstruction(children[cursor], target, depth + 1, template, evaluator)) {
|
|
1568
|
+
conditionResult = false;
|
|
1569
|
+
break;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
const consequenceStart = conditionResult ? thenStart : elseStart;
|
|
1574
|
+
const consequenceEnd = (conditionResult && elseStart > 0) ? elseStart : childrenSize;
|
|
1575
|
+
|
|
1576
|
+
if (consequenceStart > 0) {
|
|
1577
|
+
if (evaluator.trackMode || evaluator.callbackMode) {
|
|
1578
|
+
evaluator.popPath(instruction[1].length);
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
let result = true;
|
|
1582
|
+
for (let cursor = consequenceStart; cursor < consequenceEnd; cursor++) {
|
|
1583
|
+
if (!evaluateInstruction(children[cursor], target, depth + 1, template, evaluator)) {
|
|
1584
|
+
result = false;
|
|
1585
|
+
break;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
if (evaluator.trackMode || evaluator.callbackMode) {
|
|
1590
|
+
evaluator.pushPath(instruction[1]);
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, result);
|
|
1594
|
+
return result;
|
|
1595
|
+
}
|
|
1596
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1597
|
+
return true;
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
function LogicalWhenType(instruction, instance, depth, template, evaluator) {
|
|
1601
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1602
|
+
if (jsonTypeOf(target) !== instruction[5]) return true;
|
|
1603
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1604
|
+
const children = instruction[6];
|
|
1605
|
+
if (children) {
|
|
1606
|
+
for (let index = 0; index < children.length; index++) {
|
|
1607
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1608
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1609
|
+
return false;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1614
|
+
return true;
|
|
1615
|
+
};
|
|
1616
|
+
|
|
1617
|
+
function LogicalWhenDefines(instruction, instance, depth, template, evaluator) {
|
|
1618
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1619
|
+
if (!isObject(target)) return true;
|
|
1620
|
+
if (!Object.hasOwn(target, instruction[5])) return true;
|
|
1621
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1622
|
+
const children = instruction[6];
|
|
1623
|
+
if (children) {
|
|
1624
|
+
for (let index = 0; index < children.length; index++) {
|
|
1625
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1626
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1627
|
+
return false;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1632
|
+
return true;
|
|
1633
|
+
};
|
|
1634
|
+
|
|
1635
|
+
function LogicalWhenArraySizeGreater(instruction, instance, depth, template, evaluator) {
|
|
1636
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1637
|
+
if (!Array.isArray(target) || target.length <= instruction[5]) return true;
|
|
1638
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1639
|
+
const children = instruction[6];
|
|
1640
|
+
if (children) {
|
|
1641
|
+
for (let index = 0; index < children.length; index++) {
|
|
1642
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
1643
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1649
|
+
return true;
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
function LoopPropertiesUnevaluated(instruction, instance, depth, template, evaluator) {
|
|
1653
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1654
|
+
if (!isObject(target)) return true;
|
|
1655
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1656
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target)) {
|
|
1657
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1658
|
+
return true;
|
|
1659
|
+
}
|
|
1660
|
+
const children = instruction[6];
|
|
1661
|
+
for (const key in target) {
|
|
1662
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target[key], target, key)) continue;
|
|
1663
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1664
|
+
if (children) {
|
|
1665
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1666
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1667
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1668
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1669
|
+
return false;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1674
|
+
}
|
|
1675
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
1676
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1677
|
+
return true;
|
|
1678
|
+
};
|
|
1679
|
+
|
|
1680
|
+
function LoopPropertiesUnevaluatedExcept(instruction, instance, depth, template, evaluator) {
|
|
1681
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1682
|
+
if (!isObject(target)) return true;
|
|
1683
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1684
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target)) {
|
|
1685
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1686
|
+
return true;
|
|
1687
|
+
}
|
|
1688
|
+
const filter = instruction[5];
|
|
1689
|
+
const filterStrings = filter[0];
|
|
1690
|
+
const filterPrefixes = filter[1];
|
|
1691
|
+
const filterRegexes = filter[2];
|
|
1692
|
+
const children = instruction[6];
|
|
1693
|
+
for (const key in target) {
|
|
1694
|
+
if (filterStrings.has(key)) continue;
|
|
1695
|
+
let matched = false;
|
|
1696
|
+
for (let index = 0; index < filterPrefixes.length; index++) {
|
|
1697
|
+
if (key.startsWith(filterPrefixes[index])) { matched = true; break; }
|
|
1698
|
+
}
|
|
1699
|
+
if (matched) continue;
|
|
1700
|
+
for (let index = 0; index < filterRegexes.length; index++) {
|
|
1701
|
+
filterRegexes[index].lastIndex = 0;
|
|
1702
|
+
if (filterRegexes[index].test(key)) { matched = true; break; }
|
|
1703
|
+
}
|
|
1704
|
+
if (matched) continue;
|
|
1705
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target[key], target, key)) continue;
|
|
1706
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1707
|
+
if (children) {
|
|
1708
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1709
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1710
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1711
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1712
|
+
return false;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1717
|
+
}
|
|
1718
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
1719
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1720
|
+
return true;
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1723
|
+
function LoopPropertiesMatch(instruction, instance, depth, template, evaluator) {
|
|
1724
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1725
|
+
if (!isObject(target)) return true;
|
|
1726
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1727
|
+
const children = instruction[6];
|
|
1728
|
+
for (const key in target) {
|
|
1729
|
+
const index = instruction[5][key];
|
|
1730
|
+
if (index === undefined) continue;
|
|
1731
|
+
const subinstruction = children[index];
|
|
1732
|
+
const subchildren = subinstruction[6];
|
|
1733
|
+
if (subchildren) {
|
|
1734
|
+
for (let childIndex = 0; childIndex < subchildren.length; childIndex++) {
|
|
1735
|
+
if (!evaluateInstruction(subchildren[childIndex], target, depth + 1, template, evaluator)) {
|
|
1736
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1737
|
+
return false;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1743
|
+
return true;
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
function LoopPropertiesMatchClosed(instruction, instance, depth, template, evaluator) {
|
|
1747
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1748
|
+
if (!isObject(target)) return true;
|
|
1749
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1750
|
+
const children = instruction[6];
|
|
1751
|
+
for (const key in target) {
|
|
1752
|
+
const index = instruction[5][key];
|
|
1753
|
+
if (index === undefined) {
|
|
1754
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1755
|
+
return false;
|
|
1756
|
+
}
|
|
1757
|
+
const subinstruction = children[index];
|
|
1758
|
+
const subchildren = subinstruction[6];
|
|
1759
|
+
if (subchildren) {
|
|
1760
|
+
for (let childIndex = 0; childIndex < subchildren.length; childIndex++) {
|
|
1761
|
+
if (!evaluateInstruction(subchildren[childIndex], target, depth + 1, template, evaluator)) {
|
|
1762
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1769
|
+
return true;
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
function LoopProperties(instruction, instance, depth, template, evaluator) {
|
|
1773
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1774
|
+
if (!isObject(target)) return true;
|
|
1775
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1776
|
+
const children = instruction[6];
|
|
1777
|
+
for (const key in target) {
|
|
1778
|
+
evaluator.propertyParent = target;
|
|
1779
|
+
evaluator.propertyKey = key;
|
|
1780
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1781
|
+
if (children) {
|
|
1782
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1783
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1784
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1785
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1786
|
+
return false;
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1791
|
+
}
|
|
1792
|
+
evaluator.propertyParent = undefined;
|
|
1793
|
+
evaluator.propertyKey = undefined;
|
|
1794
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1795
|
+
return true;
|
|
1796
|
+
};
|
|
1797
|
+
|
|
1798
|
+
function LoopPropertiesEvaluate(instruction, instance, depth, template, evaluator) {
|
|
1799
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1800
|
+
if (!isObject(target)) return true;
|
|
1801
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1802
|
+
const children = instruction[6];
|
|
1803
|
+
for (const key in target) {
|
|
1804
|
+
evaluator.propertyParent = target;
|
|
1805
|
+
evaluator.propertyKey = key;
|
|
1806
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1807
|
+
if (children) {
|
|
1808
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1809
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1810
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1811
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1812
|
+
return false;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1817
|
+
}
|
|
1818
|
+
evaluator.propertyParent = undefined;
|
|
1819
|
+
evaluator.propertyKey = undefined;
|
|
1820
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
1821
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1822
|
+
return true;
|
|
1823
|
+
};
|
|
1824
|
+
|
|
1825
|
+
function LoopPropertiesRegex(instruction, instance, depth, template, evaluator) {
|
|
1826
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1827
|
+
if (!isObject(target)) return true;
|
|
1828
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1829
|
+
const regex = instruction[5];
|
|
1830
|
+
const children = instruction[6];
|
|
1831
|
+
for (const key in target) {
|
|
1832
|
+
regex.lastIndex = 0;
|
|
1833
|
+
if (!regex.test(key)) continue;
|
|
1834
|
+
evaluator.propertyParent = target;
|
|
1835
|
+
evaluator.propertyKey = key;
|
|
1836
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1837
|
+
if (children) {
|
|
1838
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1839
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1840
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1841
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1842
|
+
return false;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1847
|
+
}
|
|
1848
|
+
evaluator.propertyParent = undefined;
|
|
1849
|
+
evaluator.propertyKey = undefined;
|
|
1850
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1851
|
+
return true;
|
|
1852
|
+
};
|
|
1853
|
+
|
|
1854
|
+
function LoopPropertiesRegexClosed(instruction, instance, depth, template, evaluator) {
|
|
1855
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1856
|
+
if (!isObject(target)) return true;
|
|
1857
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1858
|
+
const regex = instruction[5];
|
|
1859
|
+
const children = instruction[6];
|
|
1860
|
+
for (const key in target) {
|
|
1861
|
+
regex.lastIndex = 0;
|
|
1862
|
+
if (!regex.test(key)) {
|
|
1863
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1864
|
+
return false;
|
|
1865
|
+
}
|
|
1866
|
+
evaluator.propertyParent = target;
|
|
1867
|
+
evaluator.propertyKey = key;
|
|
1868
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1869
|
+
if (children) {
|
|
1870
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1871
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1872
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1873
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1874
|
+
return false;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1879
|
+
}
|
|
1880
|
+
evaluator.propertyParent = undefined;
|
|
1881
|
+
evaluator.propertyKey = undefined;
|
|
1882
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1883
|
+
return true;
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
function LoopPropertiesStartsWith(instruction, instance, depth, template, evaluator) {
|
|
1887
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1888
|
+
if (!isObject(target)) return true;
|
|
1889
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1890
|
+
const prefix = instruction[5];
|
|
1891
|
+
const children = instruction[6];
|
|
1892
|
+
for (const key in target) {
|
|
1893
|
+
if (!key.startsWith(prefix)) continue;
|
|
1894
|
+
evaluator.propertyParent = target;
|
|
1895
|
+
evaluator.propertyKey = key;
|
|
1896
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1897
|
+
if (children) {
|
|
1898
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1899
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1900
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1901
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1902
|
+
return false;
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1907
|
+
}
|
|
1908
|
+
evaluator.propertyParent = undefined;
|
|
1909
|
+
evaluator.propertyKey = undefined;
|
|
1910
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1911
|
+
return true;
|
|
1912
|
+
};
|
|
1913
|
+
|
|
1914
|
+
function LoopPropertiesExcept(instruction, instance, depth, template, evaluator) {
|
|
1915
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1916
|
+
if (!isObject(target)) return true;
|
|
1917
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1918
|
+
const filter = instruction[5];
|
|
1919
|
+
const filterStrings = filter[0];
|
|
1920
|
+
const filterPrefixes = filter[1];
|
|
1921
|
+
const filterRegexes = filter[2];
|
|
1922
|
+
const children = instruction[6];
|
|
1923
|
+
for (const key in target) {
|
|
1924
|
+
if (filterStrings.has(key)) continue;
|
|
1925
|
+
let matched = false;
|
|
1926
|
+
for (let index = 0; index < filterPrefixes.length; index++) {
|
|
1927
|
+
if (key.startsWith(filterPrefixes[index])) { matched = true; break; }
|
|
1928
|
+
}
|
|
1929
|
+
if (matched) continue;
|
|
1930
|
+
for (let index = 0; index < filterRegexes.length; index++) {
|
|
1931
|
+
filterRegexes[index].lastIndex = 0;
|
|
1932
|
+
if (filterRegexes[index].test(key)) { matched = true; break; }
|
|
1933
|
+
}
|
|
1934
|
+
if (matched) continue;
|
|
1935
|
+
evaluator.propertyParent = target;
|
|
1936
|
+
evaluator.propertyKey = key;
|
|
1937
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
1938
|
+
if (children) {
|
|
1939
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
1940
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
1941
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1942
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1943
|
+
return false;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
1948
|
+
}
|
|
1949
|
+
evaluator.propertyParent = undefined;
|
|
1950
|
+
evaluator.propertyKey = undefined;
|
|
1951
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1952
|
+
return true;
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
function LoopPropertiesType(instruction, instance, depth, template, evaluator) {
|
|
1956
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1957
|
+
if (!isObject(target)) return true;
|
|
1958
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1959
|
+
const expected = instruction[5];
|
|
1960
|
+
for (const key in target) {
|
|
1961
|
+
const actual = jsonTypeOf(target[key]);
|
|
1962
|
+
if (actual !== expected && !(expected === Type.Integer && isIntegral(target[key]))) {
|
|
1963
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1964
|
+
return false;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1968
|
+
return true;
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
function LoopPropertiesTypeEvaluate(instruction, instance, depth, template, evaluator) {
|
|
1972
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1973
|
+
if (!isObject(target)) return true;
|
|
1974
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1975
|
+
const expected = instruction[5];
|
|
1976
|
+
for (const key in target) {
|
|
1977
|
+
const actual = jsonTypeOf(target[key]);
|
|
1978
|
+
if (actual !== expected && !(expected === Type.Integer && isIntegral(target[key]))) {
|
|
1979
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1980
|
+
return false;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
1984
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
1985
|
+
return true;
|
|
1986
|
+
};
|
|
1987
|
+
|
|
1988
|
+
function LoopPropertiesExactlyTypeStrict(instruction, instance, depth, template, evaluator) {
|
|
1989
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
1990
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
1991
|
+
if (!isObject(target)) {
|
|
1992
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
1993
|
+
return false;
|
|
1994
|
+
}
|
|
1995
|
+
const value = instruction[5];
|
|
1996
|
+
let count = 0;
|
|
1997
|
+
for (const key in target) {
|
|
1998
|
+
count++;
|
|
1999
|
+
if (effectiveTypeStrictReal(target[key]) !== value[0]) {
|
|
2000
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2001
|
+
return false;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
const __result = count === value[1].length;
|
|
2005
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, __result);
|
|
2006
|
+
return __result;
|
|
2007
|
+
};
|
|
2008
|
+
|
|
2009
|
+
function LoopPropertiesExactlyTypeStrictHash(instruction, instance, depth, template, evaluator) {
|
|
2010
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2011
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2012
|
+
if (!isObject(target)) {
|
|
2013
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2014
|
+
return false;
|
|
2015
|
+
}
|
|
2016
|
+
const value = instruction[5];
|
|
2017
|
+
const entries = value[1][0];
|
|
2018
|
+
const expectedCount = entries.length;
|
|
2019
|
+
let count = 0;
|
|
2020
|
+
for (const key in target) {
|
|
2021
|
+
count++;
|
|
2022
|
+
if (effectiveTypeStrictReal(target[key]) !== value[0]) {
|
|
2023
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2024
|
+
return false;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
if (count !== expectedCount) {
|
|
2028
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2029
|
+
return false;
|
|
2030
|
+
}
|
|
2031
|
+
for (let index = 0; index < expectedCount; index++) {
|
|
2032
|
+
if (!Object.hasOwn(target, entries[index][1])) {
|
|
2033
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2034
|
+
return false;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2038
|
+
return true;
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
function LoopPropertiesTypeStrict(instruction, instance, depth, template, evaluator) {
|
|
2042
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2043
|
+
if (!isObject(target)) return true;
|
|
2044
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2045
|
+
const expected = instruction[5];
|
|
2046
|
+
for (const key in target) {
|
|
2047
|
+
if (effectiveTypeStrictReal(target[key]) !== expected) {
|
|
2048
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2049
|
+
return false;
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2053
|
+
return true;
|
|
2054
|
+
};
|
|
2055
|
+
|
|
2056
|
+
function LoopPropertiesTypeStrictEvaluate(instruction, instance, depth, template, evaluator) {
|
|
2057
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2058
|
+
if (!isObject(target)) return true;
|
|
2059
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2060
|
+
const expected = instruction[5];
|
|
2061
|
+
for (const key in target) {
|
|
2062
|
+
if (effectiveTypeStrictReal(target[key]) !== expected) {
|
|
2063
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2064
|
+
return false;
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
2068
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2069
|
+
return true;
|
|
2070
|
+
};
|
|
2071
|
+
|
|
2072
|
+
function LoopPropertiesTypeStrictAny(instruction, instance, depth, template, evaluator) {
|
|
2073
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2074
|
+
if (!isObject(target)) return true;
|
|
2075
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2076
|
+
const bitmask = instruction[5];
|
|
2077
|
+
for (const key in target) {
|
|
2078
|
+
if (!typeSetTest(bitmask, effectiveTypeStrictReal(target[key]))) {
|
|
2079
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2080
|
+
return false;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2084
|
+
return true;
|
|
2085
|
+
};
|
|
2086
|
+
|
|
2087
|
+
function LoopPropertiesTypeStrictAnyEvaluate(instruction, instance, depth, template, evaluator) {
|
|
2088
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2089
|
+
if (!isObject(target)) return true;
|
|
2090
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2091
|
+
const bitmask = instruction[5];
|
|
2092
|
+
for (const key in target) {
|
|
2093
|
+
if (!typeSetTest(bitmask, effectiveTypeStrictReal(target[key]))) {
|
|
2094
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2095
|
+
return false;
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
2099
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2100
|
+
return true;
|
|
2101
|
+
};
|
|
2102
|
+
|
|
2103
|
+
function LoopKeys(instruction, instance, depth, template, evaluator) {
|
|
2104
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2105
|
+
if (!isObject(target)) return true;
|
|
2106
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2107
|
+
const children = instruction[6];
|
|
2108
|
+
for (const key in target) {
|
|
2109
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(key);
|
|
2110
|
+
const previousPropertyTarget = evaluator.propertyTarget;
|
|
2111
|
+
evaluator.propertyTarget = key;
|
|
2112
|
+
if (children) {
|
|
2113
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2114
|
+
if (!evaluateInstruction(children[childIndex], null, depth + 1, template, evaluator)) {
|
|
2115
|
+
evaluator.propertyTarget = previousPropertyTarget;
|
|
2116
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2117
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2118
|
+
return false;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
evaluator.propertyTarget = previousPropertyTarget;
|
|
2123
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2124
|
+
}
|
|
2125
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2126
|
+
return true;
|
|
2127
|
+
};
|
|
2128
|
+
|
|
2129
|
+
function LoopItems(instruction, instance, depth, template, evaluator) {
|
|
2130
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2131
|
+
if (!Array.isArray(target)) return true;
|
|
2132
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2133
|
+
const children = instruction[6];
|
|
2134
|
+
for (let index = 0; index < target.length; index++) {
|
|
2135
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(index);
|
|
2136
|
+
if (children) {
|
|
2137
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2138
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) {
|
|
2139
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2140
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2141
|
+
return false;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2146
|
+
}
|
|
2147
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2148
|
+
return true;
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2151
|
+
function LoopItemsFrom(instruction, instance, depth, template, evaluator) {
|
|
2152
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2153
|
+
const startIndex = instruction[5];
|
|
2154
|
+
if (!Array.isArray(target) || startIndex >= target.length) return true;
|
|
2155
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2156
|
+
const children = instruction[6];
|
|
2157
|
+
for (let index = startIndex; index < target.length; index++) {
|
|
2158
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(index);
|
|
2159
|
+
if (children) {
|
|
2160
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2161
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) {
|
|
2162
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2163
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2164
|
+
return false;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2169
|
+
}
|
|
2170
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2171
|
+
return true;
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
function LoopItemsUnevaluated(instruction, instance, depth, template, evaluator) {
|
|
2175
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2176
|
+
if (!Array.isArray(target)) return true;
|
|
2177
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2178
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target)) {
|
|
2179
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2180
|
+
return true;
|
|
2181
|
+
}
|
|
2182
|
+
const children = instruction[6];
|
|
2183
|
+
for (let index = 0; index < target.length; index++) {
|
|
2184
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target[index], target, index)) continue;
|
|
2185
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(index);
|
|
2186
|
+
if (children) {
|
|
2187
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2188
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) {
|
|
2189
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2190
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2191
|
+
return false;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2196
|
+
}
|
|
2197
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
2198
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2199
|
+
return true;
|
|
2200
|
+
};
|
|
2201
|
+
|
|
2202
|
+
function LoopItemsType(instruction, instance, depth, template, evaluator) {
|
|
2203
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2204
|
+
if (!Array.isArray(target)) return true;
|
|
2205
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2206
|
+
const expected = instruction[5];
|
|
2207
|
+
for (let index = 0; index < target.length; index++) {
|
|
2208
|
+
const actual = jsonTypeOf(target[index]);
|
|
2209
|
+
if (actual !== expected && !(expected === Type.Integer && isIntegral(target[index]))) {
|
|
2210
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2211
|
+
return false;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2215
|
+
return true;
|
|
2216
|
+
};
|
|
2217
|
+
|
|
2218
|
+
function LoopItemsTypeStrict(instruction, instance, depth, template, evaluator) {
|
|
2219
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2220
|
+
if (!Array.isArray(target)) return true;
|
|
2221
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2222
|
+
const expected = instruction[5];
|
|
2223
|
+
for (let index = 0; index < target.length; index++) {
|
|
2224
|
+
if (effectiveTypeStrictReal(target[index]) !== expected) {
|
|
2225
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2226
|
+
return false;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2230
|
+
return true;
|
|
2231
|
+
};
|
|
2232
|
+
|
|
2233
|
+
function LoopItemsTypeStrictAny(instruction, instance, depth, template, evaluator) {
|
|
2234
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2235
|
+
if (!Array.isArray(target)) return true;
|
|
2236
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2237
|
+
const bitmask = instruction[5];
|
|
2238
|
+
for (let index = 0; index < target.length; index++) {
|
|
2239
|
+
if (!typeSetTest(bitmask, effectiveTypeStrictReal(target[index]))) {
|
|
2240
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2241
|
+
return false;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2245
|
+
return true;
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2248
|
+
function LoopItemsPropertiesExactlyTypeStrictHash(instruction, instance, depth, template, evaluator) {
|
|
2249
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2250
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2251
|
+
if (!Array.isArray(target)) {
|
|
2252
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2253
|
+
return false;
|
|
2254
|
+
}
|
|
2255
|
+
const expectedType = instruction[5][0];
|
|
2256
|
+
const entries = instruction[5][1][0];
|
|
2257
|
+
const expectedCount = entries.length;
|
|
2258
|
+
for (let index = 0; index < target.length; index++) {
|
|
2259
|
+
const item = target[index];
|
|
2260
|
+
if (!isObject(item)) {
|
|
2261
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2262
|
+
return false;
|
|
2263
|
+
}
|
|
2264
|
+
let count = 0;
|
|
2265
|
+
for (const key in item) {
|
|
2266
|
+
count++;
|
|
2267
|
+
if (effectiveTypeStrictReal(item[key]) !== expectedType) {
|
|
2268
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2269
|
+
return false;
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
if (count !== expectedCount) {
|
|
2273
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2274
|
+
return false;
|
|
2275
|
+
}
|
|
2276
|
+
for (let entry = 0; entry < expectedCount; entry++) {
|
|
2277
|
+
if (!Object.hasOwn(item, entries[entry][1])) {
|
|
2278
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2279
|
+
return false;
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2284
|
+
return true;
|
|
2285
|
+
};
|
|
2286
|
+
function LoopContains(instruction, instance, depth, template, evaluator) {
|
|
2287
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2288
|
+
if (!Array.isArray(target)) return true;
|
|
2289
|
+
const range = instruction[5];
|
|
2290
|
+
const minimum = range[0];
|
|
2291
|
+
const maximum = range[1];
|
|
2292
|
+
const isExhaustive = range[2];
|
|
2293
|
+
if (minimum === 0 && target.length === 0) return true;
|
|
2294
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2295
|
+
|
|
2296
|
+
const children = instruction[6];
|
|
2297
|
+
let result = false;
|
|
2298
|
+
let matchCount = 0;
|
|
2299
|
+
for (let index = 0; index < target.length; index++) {
|
|
2300
|
+
if (evaluator.callbackMode) evaluator.pushInstanceToken(index);
|
|
2301
|
+
let subresult = true;
|
|
2302
|
+
if (children) {
|
|
2303
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2304
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) {
|
|
2305
|
+
subresult = false;
|
|
2306
|
+
break;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
if (evaluator.callbackMode) evaluator.popInstanceToken();
|
|
2311
|
+
if (subresult) {
|
|
2312
|
+
matchCount++;
|
|
2313
|
+
if (maximum !== null && matchCount > maximum) {
|
|
2314
|
+
result = false;
|
|
2315
|
+
break;
|
|
2316
|
+
}
|
|
2317
|
+
if (matchCount >= minimum) {
|
|
2318
|
+
result = true;
|
|
2319
|
+
if (maximum === null && !isExhaustive) break;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, result);
|
|
2325
|
+
return result;
|
|
2326
|
+
};
|
|
2327
|
+
|
|
2328
|
+
function ControlGroup(instruction, instance, depth, template, evaluator) {
|
|
2329
|
+
const children = instruction[6];
|
|
2330
|
+
if (children) {
|
|
2331
|
+
for (let index = 0; index < children.length; index++) {
|
|
2332
|
+
if (!evaluateInstruction(children[index], instance, depth + 1, template, evaluator)) return false;
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
return true;
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2338
|
+
function ControlGroupWhenDefines(instruction, instance, depth, template, evaluator) {
|
|
2339
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2340
|
+
if (!isObject(target)) return true;
|
|
2341
|
+
if (!Object.hasOwn(target, instruction[5])) return true;
|
|
2342
|
+
const children = instruction[6];
|
|
2343
|
+
if (children) {
|
|
2344
|
+
for (let index = 0; index < children.length; index++) {
|
|
2345
|
+
if (!evaluateInstruction(children[index], instance, depth + 1, template, evaluator)) return false;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return true;
|
|
2349
|
+
};
|
|
2350
|
+
|
|
2351
|
+
function ControlGroupWhenDefinesDirect(instruction, instance, depth, template, evaluator) {
|
|
2352
|
+
if (!isObject(instance)) return true;
|
|
2353
|
+
if (!Object.hasOwn(instance, instruction[5])) return true;
|
|
2354
|
+
const children = instruction[6];
|
|
2355
|
+
if (children) {
|
|
2356
|
+
for (let index = 0; index < children.length; index++) {
|
|
2357
|
+
if (!evaluateInstruction(children[index], instance, depth + 1, template, evaluator)) return false;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
return true;
|
|
2361
|
+
};
|
|
2362
|
+
|
|
2363
|
+
function ControlGroupWhenType(instruction, instance, depth, template, evaluator) {
|
|
2364
|
+
if (jsonTypeOf(instance) !== instruction[5]) return true;
|
|
2365
|
+
const children = instruction[6];
|
|
2366
|
+
if (children) {
|
|
2367
|
+
for (let index = 0; index < children.length; index++) {
|
|
2368
|
+
if (!evaluateInstruction(children[index], instance, depth + 1, template, evaluator)) return false;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
return true;
|
|
2372
|
+
};
|
|
2373
|
+
|
|
2374
|
+
function ControlEvaluate(instruction, instance, depth, template, evaluator) {
|
|
2375
|
+
if (evaluator.trackMode) {
|
|
2376
|
+
const target = resolveInstance(instance, instruction[5]);
|
|
2377
|
+
evaluator.markEvaluated(target, evaluator.propertyParent, evaluator.propertyKey);
|
|
2378
|
+
}
|
|
2379
|
+
return true;
|
|
2380
|
+
};
|
|
2381
|
+
|
|
2382
|
+
function ControlDynamicAnchorJump(instruction, instance, depth, template, evaluator) {
|
|
2383
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2384
|
+
const resolved = resolveInstance(instance, instruction[2]);
|
|
2385
|
+
const anchor = instruction[5];
|
|
2386
|
+
|
|
2387
|
+
if (!evaluator.resources) {
|
|
2388
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2389
|
+
return false;
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
const anchors = template[5];
|
|
2393
|
+
for (let index = 0; index < evaluator.resources.length; index++) {
|
|
2394
|
+
const jumpTarget = anchors.get(evaluator.resources[index] + ':' + anchor);
|
|
2395
|
+
if (jumpTarget !== undefined) {
|
|
2396
|
+
for (let childIndex = 0; childIndex < jumpTarget.length; childIndex++) {
|
|
2397
|
+
if (!evaluateInstruction(jumpTarget[childIndex], resolved, depth + 1, template, evaluator)) {
|
|
2398
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2399
|
+
return false;
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2403
|
+
return true;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2408
|
+
return false;
|
|
2409
|
+
};
|
|
2410
|
+
|
|
2411
|
+
function ControlJump(instruction, instance, depth, template, evaluator) {
|
|
2412
|
+
if (evaluator.callbackMode) evaluator.callbackPush(instruction);
|
|
2413
|
+
const jumpTarget = instruction[5];
|
|
2414
|
+
if (!jumpTarget) {
|
|
2415
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2416
|
+
return true;
|
|
2417
|
+
}
|
|
2418
|
+
const resolved = resolveInstance(instance, instruction[2]);
|
|
2419
|
+
for (let index = 0; index < jumpTarget.length; index++) {
|
|
2420
|
+
if (!evaluateInstruction(jumpTarget[index], resolved, depth + 1, template, evaluator)) {
|
|
2421
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, false);
|
|
2422
|
+
return false;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
if (evaluator.callbackMode) evaluator.callbackPop(instruction, true);
|
|
2426
|
+
return true;
|
|
2427
|
+
};
|
|
2428
|
+
|
|
2429
|
+
const handlers = [
|
|
2430
|
+
AssertionFail, // 0
|
|
2431
|
+
AssertionDefines, // 1
|
|
2432
|
+
AssertionDefinesStrict, // 2
|
|
2433
|
+
AssertionDefinesAll, // 3
|
|
2434
|
+
AssertionDefinesAllStrict, // 4
|
|
2435
|
+
AssertionDefinesExactly, // 5
|
|
2436
|
+
AssertionDefinesExactlyStrict, // 6
|
|
2437
|
+
AssertionDefinesExactlyStrictHash3, // 7
|
|
2438
|
+
AssertionPropertyDependencies, // 8
|
|
2439
|
+
AssertionType, // 9
|
|
2440
|
+
AssertionTypeAny, // 10
|
|
2441
|
+
AssertionTypeStrict, // 11
|
|
2442
|
+
AssertionTypeStrictAny, // 12
|
|
2443
|
+
AssertionTypeStringBounded, // 13
|
|
2444
|
+
AssertionTypeStringUpper, // 14
|
|
2445
|
+
AssertionTypeArrayBounded, // 15
|
|
2446
|
+
AssertionTypeArrayUpper, // 16
|
|
2447
|
+
AssertionTypeObjectBounded, // 17
|
|
2448
|
+
AssertionTypeObjectUpper, // 18
|
|
2449
|
+
AssertionRegex, // 19
|
|
2450
|
+
AssertionStringSizeLess, // 20
|
|
2451
|
+
AssertionStringSizeGreater, // 21
|
|
2452
|
+
AssertionArraySizeLess, // 22
|
|
2453
|
+
AssertionArraySizeGreater, // 23
|
|
2454
|
+
AssertionObjectSizeLess, // 24
|
|
2455
|
+
AssertionObjectSizeGreater, // 25
|
|
2456
|
+
AssertionEqual, // 26
|
|
2457
|
+
AssertionEqualsAny, // 27
|
|
2458
|
+
AssertionEqualsAnyStringHash, // 28
|
|
2459
|
+
AssertionGreaterEqual, // 29
|
|
2460
|
+
AssertionLessEqual, // 30
|
|
2461
|
+
AssertionGreater, // 31
|
|
2462
|
+
AssertionLess, // 32
|
|
2463
|
+
AssertionUnique, // 33
|
|
2464
|
+
AssertionDivisible, // 34
|
|
2465
|
+
AssertionStringType, // 35
|
|
2466
|
+
AssertionPropertyType, // 36
|
|
2467
|
+
AssertionPropertyTypeEvaluate, // 37
|
|
2468
|
+
AssertionPropertyTypeStrict, // 38
|
|
2469
|
+
AssertionPropertyTypeStrictEvaluate, // 39
|
|
2470
|
+
AssertionPropertyTypeStrictAny, // 40
|
|
2471
|
+
AssertionPropertyTypeStrictAnyEvaluate, // 41
|
|
2472
|
+
AssertionArrayPrefix, // 42
|
|
2473
|
+
AssertionArrayPrefixEvaluate, // 43
|
|
2474
|
+
AnnotationEmit, // 44
|
|
2475
|
+
AnnotationToParent, // 45
|
|
2476
|
+
AnnotationBasenameToParent, // 46
|
|
2477
|
+
Evaluate, // 47
|
|
2478
|
+
LogicalNot, // 48
|
|
2479
|
+
LogicalNotEvaluate, // 49
|
|
2480
|
+
LogicalOr, // 50
|
|
2481
|
+
LogicalAnd, // 51
|
|
2482
|
+
LogicalXor, // 52
|
|
2483
|
+
LogicalCondition, // 53
|
|
2484
|
+
LogicalWhenType, // 54
|
|
2485
|
+
LogicalWhenDefines, // 55
|
|
2486
|
+
LogicalWhenArraySizeGreater, // 56
|
|
2487
|
+
LoopPropertiesUnevaluated, // 57
|
|
2488
|
+
LoopPropertiesUnevaluatedExcept, // 58
|
|
2489
|
+
LoopPropertiesMatch, // 59
|
|
2490
|
+
LoopPropertiesMatchClosed, // 60
|
|
2491
|
+
LoopProperties, // 61
|
|
2492
|
+
LoopPropertiesEvaluate, // 62
|
|
2493
|
+
LoopPropertiesRegex, // 63
|
|
2494
|
+
LoopPropertiesRegexClosed, // 64
|
|
2495
|
+
LoopPropertiesStartsWith, // 65
|
|
2496
|
+
LoopPropertiesExcept, // 66
|
|
2497
|
+
LoopPropertiesType, // 67
|
|
2498
|
+
LoopPropertiesTypeEvaluate, // 68
|
|
2499
|
+
LoopPropertiesExactlyTypeStrict, // 69
|
|
2500
|
+
LoopPropertiesExactlyTypeStrictHash, // 70
|
|
2501
|
+
LoopPropertiesTypeStrict, // 71
|
|
2502
|
+
LoopPropertiesTypeStrictEvaluate, // 72
|
|
2503
|
+
LoopPropertiesTypeStrictAny, // 73
|
|
2504
|
+
LoopPropertiesTypeStrictAnyEvaluate, // 74
|
|
2505
|
+
LoopKeys, // 75
|
|
2506
|
+
LoopItems, // 76
|
|
2507
|
+
LoopItemsFrom, // 77
|
|
2508
|
+
LoopItemsUnevaluated, // 78
|
|
2509
|
+
LoopItemsType, // 79
|
|
2510
|
+
LoopItemsTypeStrict, // 80
|
|
2511
|
+
LoopItemsTypeStrictAny, // 81
|
|
2512
|
+
LoopItemsPropertiesExactlyTypeStrictHash, // 82
|
|
2513
|
+
LoopItemsPropertiesExactlyTypeStrictHash, // 83
|
|
2514
|
+
LoopContains, // 84
|
|
2515
|
+
ControlGroup, // 85
|
|
2516
|
+
ControlGroupWhenDefines, // 86
|
|
2517
|
+
ControlGroupWhenDefinesDirect, // 87
|
|
2518
|
+
ControlGroupWhenType, // 88
|
|
2519
|
+
ControlEvaluate, // 89
|
|
2520
|
+
ControlDynamicAnchorJump, // 90
|
|
2521
|
+
ControlJump // 91
|
|
2522
|
+
];
|
|
2523
|
+
|
|
2524
|
+
function AssertionTypeArrayBounded_fast(instruction, instance, depth, template, evaluator) {
|
|
2525
|
+
const relInstance = instruction[2];
|
|
2526
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2527
|
+
if (!Array.isArray(target)) return false;
|
|
2528
|
+
const range = instruction[5];
|
|
2529
|
+
if (target.length < range[0]) return false;
|
|
2530
|
+
if (range[1] !== null && target.length > range[1]) return false;
|
|
2531
|
+
return true;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
function LoopItemsTypeStrictAny_fast(instruction, instance, depth, template, evaluator) {
|
|
2535
|
+
const relInstance = instruction[2];
|
|
2536
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2537
|
+
if (!Array.isArray(target)) return true;
|
|
2538
|
+
const bitmask = instruction[5];
|
|
2539
|
+
for (let index = 0; index < target.length; index++) {
|
|
2540
|
+
if (!typeSetTest(bitmask, effectiveTypeStrictReal(target[index]))) return false;
|
|
2541
|
+
}
|
|
2542
|
+
return true;
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
function AssertionPropertyTypeStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
2546
|
+
if (!isObject(instance)) return true;
|
|
2547
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2548
|
+
if (target === undefined) return true;
|
|
2549
|
+
return effectiveTypeStrictReal(target) === instruction[5];
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
function AssertionTypeStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
2553
|
+
const relInstance = instruction[2];
|
|
2554
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2555
|
+
return effectiveTypeStrictReal(target) === instruction[5];
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
function AssertionDefinesAllStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
2559
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2560
|
+
if (!isObject(target)) return false;
|
|
2561
|
+
const strings = instruction[5];
|
|
2562
|
+
for (let index = 0; index < strings.length; index++) {
|
|
2563
|
+
if (!Object.hasOwn(target, strings[index])) return false;
|
|
2564
|
+
}
|
|
2565
|
+
return true;
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
function AssertionEqual_fast(instruction, instance, depth, template, evaluator) {
|
|
2569
|
+
if (evaluator.propertyTarget !== undefined) {
|
|
2570
|
+
const value = instruction[5];
|
|
2571
|
+
return typeof value === 'string' && value === evaluator.propertyTarget;
|
|
2572
|
+
}
|
|
2573
|
+
return jsonEqual(resolveInstance(instance, instruction[2]), instruction[5]);
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
function LoopPropertiesMatch_fast(instruction, instance, depth, template, evaluator) {
|
|
2577
|
+
const relInstance = instruction[2];
|
|
2578
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2579
|
+
if (!isObject(target)) return true;
|
|
2580
|
+
const children = instruction[6];
|
|
2581
|
+
for (const key in target) {
|
|
2582
|
+
const index = instruction[5][key];
|
|
2583
|
+
if (index === undefined) continue;
|
|
2584
|
+
const subinstruction = children[index];
|
|
2585
|
+
const subchildren = subinstruction[6];
|
|
2586
|
+
if (subchildren) {
|
|
2587
|
+
for (let childIndex = 0; childIndex < subchildren.length; childIndex++) {
|
|
2588
|
+
if (!evaluateInstruction(subchildren[childIndex], target, depth + 1, template, evaluator)) return false;
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
return true;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
function LogicalOr_fast(instruction, instance, depth, template, evaluator) {
|
|
2596
|
+
const children = instruction[6];
|
|
2597
|
+
if (!children || children.length === 0) return true;
|
|
2598
|
+
const relInstance = instruction[2];
|
|
2599
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2600
|
+
const exhaustive = instruction[5];
|
|
2601
|
+
let result = false;
|
|
2602
|
+
if (exhaustive) {
|
|
2603
|
+
for (let index = 0; index < children.length; index++) {
|
|
2604
|
+
if (evaluateInstruction(children[index], target, depth + 1, template, evaluator)) result = true;
|
|
2605
|
+
}
|
|
2606
|
+
} else {
|
|
2607
|
+
for (let index = 0; index < children.length; index++) {
|
|
2608
|
+
if (evaluateInstruction(children[index], target, depth + 1, template, evaluator)) return true;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
return result;
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
function ControlJump_fast(instruction, instance, depth, template, evaluator) {
|
|
2615
|
+
const jumpTarget = instruction[5];
|
|
2616
|
+
if (!jumpTarget) return true;
|
|
2617
|
+
const relInstance = instruction[2];
|
|
2618
|
+
const resolved = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2619
|
+
for (let index = 0; index < jumpTarget.length; index++) {
|
|
2620
|
+
if (!evaluateInstruction(jumpTarget[index], resolved, depth + 1, template, evaluator)) return false;
|
|
2621
|
+
}
|
|
2622
|
+
return true;
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
function AssertionEqualsAnyStringHash_fast(instruction, instance, depth, template, evaluator) {
|
|
2626
|
+
const target = evaluator.propertyTarget !== undefined
|
|
2627
|
+
? evaluator.propertyTarget
|
|
2628
|
+
: resolveInstance(instance, instruction[2]);
|
|
2629
|
+
if (typeof target !== 'string') return false;
|
|
2630
|
+
const value = instruction[5];
|
|
2631
|
+
const entries = value[0];
|
|
2632
|
+
const tableOfContents = value[1];
|
|
2633
|
+
const stringSize = target.length;
|
|
2634
|
+
if (stringSize < tableOfContents.length) {
|
|
2635
|
+
const hint = tableOfContents[stringSize];
|
|
2636
|
+
if (hint[1] === 0) return false;
|
|
2637
|
+
for (let index = hint[0] - 1; index < hint[1]; index++) {
|
|
2638
|
+
if (entries[index][1] === target) return true;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
return false;
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
function LogicalXor_fast(instruction, instance, depth, template, evaluator) {
|
|
2645
|
+
const relInstance = instruction[2];
|
|
2646
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2647
|
+
const exhaustive = instruction[5];
|
|
2648
|
+
const children = instruction[6];
|
|
2649
|
+
let result = true;
|
|
2650
|
+
let hasMatched = false;
|
|
2651
|
+
if (children) {
|
|
2652
|
+
for (let index = 0; index < children.length; index++) {
|
|
2653
|
+
if (evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
2654
|
+
if (hasMatched) {
|
|
2655
|
+
result = false;
|
|
2656
|
+
if (!exhaustive) break;
|
|
2657
|
+
} else {
|
|
2658
|
+
hasMatched = true;
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
return result && hasMatched;
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
function AssertionDefinesStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
2667
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2668
|
+
return isObject(target) && Object.hasOwn(target, instruction[5]);
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
function LoopItems_fast(instruction, instance, depth, template, evaluator) {
|
|
2672
|
+
const relInstance = instruction[2];
|
|
2673
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2674
|
+
if (!Array.isArray(target)) return true;
|
|
2675
|
+
const children = instruction[6];
|
|
2676
|
+
for (let index = 0; index < target.length; index++) {
|
|
2677
|
+
if (children) {
|
|
2678
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2679
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) return false;
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
return true;
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
function LoopPropertiesMatchClosed_fast(instruction, instance, depth, template, evaluator) {
|
|
2687
|
+
const relInstance = instruction[2];
|
|
2688
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2689
|
+
if (!isObject(target)) return true;
|
|
2690
|
+
const children = instruction[6];
|
|
2691
|
+
for (const key in target) {
|
|
2692
|
+
const index = instruction[5][key];
|
|
2693
|
+
if (index === undefined) return false;
|
|
2694
|
+
const subinstruction = children[index];
|
|
2695
|
+
const subchildren = subinstruction[6];
|
|
2696
|
+
if (subchildren) {
|
|
2697
|
+
for (let childIndex = 0; childIndex < subchildren.length; childIndex++) {
|
|
2698
|
+
if (!evaluateInstruction(subchildren[childIndex], target, depth + 1, template, evaluator)) return false;
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
return true;
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
function LogicalAnd_fast(instruction, instance, depth, template, evaluator) {
|
|
2706
|
+
const relInstance = instruction[2];
|
|
2707
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2708
|
+
const children = instruction[6];
|
|
2709
|
+
if (children) {
|
|
2710
|
+
for (let index = 0; index < children.length; index++) {
|
|
2711
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) return false;
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
return true;
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
function AssertionTypeStringBounded_fast(instruction, instance, depth, template, evaluator) {
|
|
2718
|
+
const relInstance = instruction[2];
|
|
2719
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2720
|
+
if (typeof target !== 'string') return false;
|
|
2721
|
+
const range = instruction[5];
|
|
2722
|
+
const length = unicodeLength(target);
|
|
2723
|
+
if (length < range[0]) return false;
|
|
2724
|
+
return range[1] === null || length <= range[1];
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
function AssertionPropertyDependencies_fast(instruction, instance, depth, template, evaluator) {
|
|
2728
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2729
|
+
if (!isObject(target)) return true;
|
|
2730
|
+
const value = instruction[5];
|
|
2731
|
+
for (const property in value) {
|
|
2732
|
+
if (!Object.hasOwn(target, property)) continue;
|
|
2733
|
+
const dependencies = value[property];
|
|
2734
|
+
for (let index = 0; index < dependencies.length; index++) {
|
|
2735
|
+
if (!Object.hasOwn(target, dependencies[index])) return false;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
return true;
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
function AssertionTypeAny_fast(instruction, instance, depth, template, evaluator) {
|
|
2742
|
+
const relInstance = instruction[2];
|
|
2743
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2744
|
+
const bitmask = instruction[5];
|
|
2745
|
+
const typeIndex = jsonTypeOf(target);
|
|
2746
|
+
if (typeSetTest(bitmask, typeIndex)) return true;
|
|
2747
|
+
return typeSetTest(bitmask, Type.Integer) && isIntegral(target);
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
function LogicalCondition_fast(instruction, instance, depth, template, evaluator) {
|
|
2751
|
+
const value = instruction[5];
|
|
2752
|
+
const thenStart = value[0];
|
|
2753
|
+
const elseStart = value[1];
|
|
2754
|
+
const children = instruction[6];
|
|
2755
|
+
const childrenSize = children ? children.length : 0;
|
|
2756
|
+
let conditionEnd = childrenSize;
|
|
2757
|
+
if (thenStart > 0) conditionEnd = thenStart;
|
|
2758
|
+
else if (elseStart > 0) conditionEnd = elseStart;
|
|
2759
|
+
const relInstance = instruction[2];
|
|
2760
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2761
|
+
let conditionResult = true;
|
|
2762
|
+
for (let cursor = 0; cursor < conditionEnd; cursor++) {
|
|
2763
|
+
if (!evaluateInstruction(children[cursor], target, depth + 1, template, evaluator)) {
|
|
2764
|
+
conditionResult = false;
|
|
2765
|
+
break;
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
const consequenceStart = conditionResult ? thenStart : elseStart;
|
|
2769
|
+
const consequenceEnd = (conditionResult && elseStart > 0) ? elseStart : childrenSize;
|
|
2770
|
+
if (consequenceStart > 0) {
|
|
2771
|
+
if (evaluator.trackMode) {
|
|
2772
|
+
evaluator.popPath(instruction[1].length);
|
|
2773
|
+
}
|
|
2774
|
+
let result = true;
|
|
2775
|
+
for (let cursor = consequenceStart; cursor < consequenceEnd; cursor++) {
|
|
2776
|
+
if (!evaluateInstruction(children[cursor], target, depth + 1, template, evaluator)) {
|
|
2777
|
+
result = false;
|
|
2778
|
+
break;
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
if (evaluator.trackMode) {
|
|
2782
|
+
evaluator.pushPath(instruction[1]);
|
|
2783
|
+
}
|
|
2784
|
+
return result;
|
|
2785
|
+
}
|
|
2786
|
+
return true;
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
function LoopPropertiesExcept_fast(instruction, instance, depth, template, evaluator) {
|
|
2790
|
+
const relInstance = instruction[2];
|
|
2791
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2792
|
+
if (!isObject(target)) return true;
|
|
2793
|
+
const filter = instruction[5];
|
|
2794
|
+
const filterStrings = filter[0];
|
|
2795
|
+
const filterPrefixes = filter[1];
|
|
2796
|
+
const filterRegexes = filter[2];
|
|
2797
|
+
const children = instruction[6];
|
|
2798
|
+
for (const key in target) {
|
|
2799
|
+
if (filterStrings.has(key)) continue;
|
|
2800
|
+
let matched = false;
|
|
2801
|
+
for (let index = 0; index < filterPrefixes.length; index++) {
|
|
2802
|
+
if (key.startsWith(filterPrefixes[index])) { matched = true; break; }
|
|
2803
|
+
}
|
|
2804
|
+
if (matched) continue;
|
|
2805
|
+
for (let index = 0; index < filterRegexes.length; index++) {
|
|
2806
|
+
filterRegexes[index].lastIndex = 0;
|
|
2807
|
+
if (filterRegexes[index].test(key)) { matched = true; break; }
|
|
2808
|
+
}
|
|
2809
|
+
if (matched) continue;
|
|
2810
|
+
evaluator.propertyParent = target;
|
|
2811
|
+
evaluator.propertyKey = key;
|
|
2812
|
+
if (children) {
|
|
2813
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2814
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
2815
|
+
evaluator.propertyParent = undefined;
|
|
2816
|
+
evaluator.propertyKey = undefined;
|
|
2817
|
+
return false;
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
evaluator.propertyParent = undefined;
|
|
2823
|
+
evaluator.propertyKey = undefined;
|
|
2824
|
+
return true;
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
function AssertionRegex_fast(instruction, instance, depth, template, evaluator) {
|
|
2828
|
+
const target = evaluator.propertyTarget !== undefined
|
|
2829
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
2830
|
+
if (typeof target !== 'string') return true;
|
|
2831
|
+
return instruction[5].test(target);
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
function LoopProperties_fast(instruction, instance, depth, template, evaluator) {
|
|
2835
|
+
const relInstance = instruction[2];
|
|
2836
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2837
|
+
if (!isObject(target)) return true;
|
|
2838
|
+
const children = instruction[6];
|
|
2839
|
+
for (const key in target) {
|
|
2840
|
+
evaluator.propertyParent = target;
|
|
2841
|
+
evaluator.propertyKey = key;
|
|
2842
|
+
if (children) {
|
|
2843
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2844
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
2845
|
+
evaluator.propertyParent = undefined;
|
|
2846
|
+
evaluator.propertyKey = undefined;
|
|
2847
|
+
return false;
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
evaluator.propertyParent = undefined;
|
|
2853
|
+
evaluator.propertyKey = undefined;
|
|
2854
|
+
return true;
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
function AssertionDefines_fast(instruction, instance, depth, template, evaluator) {
|
|
2858
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2859
|
+
if (!isObject(target)) return true;
|
|
2860
|
+
return Object.hasOwn(target, instruction[5]);
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
function LogicalWhenType_fast(instruction, instance, depth, template, evaluator) {
|
|
2864
|
+
const relInstance = instruction[2];
|
|
2865
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2866
|
+
if (jsonTypeOf(target) !== instruction[5]) return true;
|
|
2867
|
+
const children = instruction[6];
|
|
2868
|
+
if (children) {
|
|
2869
|
+
for (let index = 0; index < children.length; index++) {
|
|
2870
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) return false;
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
return true;
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
function LogicalWhenDefines_fast(instruction, instance, depth, template, evaluator) {
|
|
2877
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2878
|
+
if (!isObject(target)) return true;
|
|
2879
|
+
if (!Object.hasOwn(target, instruction[5])) return true;
|
|
2880
|
+
const children = instruction[6];
|
|
2881
|
+
if (children) {
|
|
2882
|
+
for (let index = 0; index < children.length; index++) {
|
|
2883
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) return false;
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
return true;
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
function AssertionFail_fast() { return false; }
|
|
2890
|
+
|
|
2891
|
+
function LoopContains_fast(instruction, instance, depth, template, evaluator) {
|
|
2892
|
+
const relInstance = instruction[2];
|
|
2893
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2894
|
+
if (!Array.isArray(target)) return true;
|
|
2895
|
+
const range = instruction[5];
|
|
2896
|
+
const minimum = range[0];
|
|
2897
|
+
const maximum = range[1];
|
|
2898
|
+
const isExhaustive = range[2];
|
|
2899
|
+
if (minimum === 0 && target.length === 0) return true;
|
|
2900
|
+
const children = instruction[6];
|
|
2901
|
+
let matchCount = 0;
|
|
2902
|
+
for (let index = 0; index < target.length; index++) {
|
|
2903
|
+
let subresult = true;
|
|
2904
|
+
if (children) {
|
|
2905
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
2906
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) {
|
|
2907
|
+
subresult = false;
|
|
2908
|
+
break;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
if (subresult) {
|
|
2913
|
+
matchCount++;
|
|
2914
|
+
if (maximum !== null && matchCount > maximum) return false;
|
|
2915
|
+
if (matchCount >= minimum && maximum === null && !isExhaustive) return true;
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
return matchCount >= minimum;
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2921
|
+
function LogicalNot_fast(instruction, instance, depth, template, evaluator) {
|
|
2922
|
+
const relInstance = instruction[2];
|
|
2923
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2924
|
+
const children = instruction[6];
|
|
2925
|
+
if (children) {
|
|
2926
|
+
for (let index = 0; index < children.length; index++) {
|
|
2927
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) return true;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
return false;
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
function LoopItemsType_fast(instruction, instance, depth, template, evaluator) {
|
|
2934
|
+
const relInstance = instruction[2];
|
|
2935
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2936
|
+
if (!Array.isArray(target)) return true;
|
|
2937
|
+
const expected = instruction[5];
|
|
2938
|
+
for (let index = 0; index < target.length; index++) {
|
|
2939
|
+
const actual = jsonTypeOf(target[index]);
|
|
2940
|
+
if (actual !== expected && !(expected === Type.Integer && isIntegral(target[index]))) return false;
|
|
2941
|
+
}
|
|
2942
|
+
return true;
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
function LoopItemsTypeStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
2946
|
+
const relInstance = instruction[2];
|
|
2947
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
2948
|
+
if (!Array.isArray(target)) return true;
|
|
2949
|
+
const expected = instruction[5];
|
|
2950
|
+
for (let index = 0; index < target.length; index++) {
|
|
2951
|
+
if (effectiveTypeStrictReal(target[index]) !== expected) return false;
|
|
2952
|
+
}
|
|
2953
|
+
return true;
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
function AssertionEqualsAny_fast(instruction, instance, depth, template, evaluator) {
|
|
2957
|
+
const value = instruction[5];
|
|
2958
|
+
const target = evaluator.propertyTarget !== undefined
|
|
2959
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
2960
|
+
if (value.primitive) return value.set.has(target);
|
|
2961
|
+
const values = Array.isArray(value) ? value : value.values;
|
|
2962
|
+
for (let index = 0; index < values.length; index++) {
|
|
2963
|
+
if (jsonEqual(target, values[index])) return true;
|
|
2964
|
+
}
|
|
2965
|
+
return false;
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
function AssertionDefinesAll_fast(instruction, instance, depth, template, evaluator) {
|
|
2969
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2970
|
+
if (!isObject(target)) return true;
|
|
2971
|
+
const strings = instruction[5];
|
|
2972
|
+
for (let index = 0; index < strings.length; index++) {
|
|
2973
|
+
if (!Object.hasOwn(target, strings[index])) return false;
|
|
2974
|
+
}
|
|
2975
|
+
return true;
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
function AssertionDefinesExactly_fast(instruction, instance, depth, template, evaluator) {
|
|
2979
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2980
|
+
if (!isObject(target)) return true;
|
|
2981
|
+
let targetSize = 0;
|
|
2982
|
+
for (const key in target) targetSize++;
|
|
2983
|
+
const strings = instruction[5];
|
|
2984
|
+
if (targetSize !== strings.length) return false;
|
|
2985
|
+
for (let index = 0; index < strings.length; index++) {
|
|
2986
|
+
if (!Object.hasOwn(target, strings[index])) return false;
|
|
2987
|
+
}
|
|
2988
|
+
return true;
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
function AssertionDefinesExactlyStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
2992
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
2993
|
+
if (!isObject(target)) return false;
|
|
2994
|
+
let targetSize = 0;
|
|
2995
|
+
for (const key in target) targetSize++;
|
|
2996
|
+
const strings = instruction[5];
|
|
2997
|
+
if (targetSize !== strings.length) return false;
|
|
2998
|
+
for (let index = 0; index < strings.length; index++) {
|
|
2999
|
+
if (!Object.hasOwn(target, strings[index])) return false;
|
|
3000
|
+
}
|
|
3001
|
+
return true;
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
function AssertionDefinesExactlyStrictHash3_fast(instruction, instance, depth, template, evaluator) {
|
|
3005
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3006
|
+
if (!isObject(target)) return false;
|
|
3007
|
+
const entries = instruction[5][0];
|
|
3008
|
+
let count = 0;
|
|
3009
|
+
for (const key in target) count++;
|
|
3010
|
+
if (count !== 3) return false;
|
|
3011
|
+
return Object.hasOwn(target, entries[0][1]) &&
|
|
3012
|
+
Object.hasOwn(target, entries[1][1]) &&
|
|
3013
|
+
Object.hasOwn(target, entries[2][1]);
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
function AssertionType_fast(instruction, instance, depth, template, evaluator) {
|
|
3017
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3018
|
+
const expected = instruction[5];
|
|
3019
|
+
const actual = jsonTypeOf(target);
|
|
3020
|
+
if (actual === expected) return true;
|
|
3021
|
+
return expected === Type.Integer && isIntegral(target);
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
function AssertionTypeStrictAny_fast(instruction, instance, depth, template, evaluator) {
|
|
3025
|
+
const relInstance = instruction[2];
|
|
3026
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3027
|
+
return typeSetTest(instruction[5], effectiveTypeStrictReal(target));
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
function AssertionTypeStringUpper_fast(instruction, instance, depth, template, evaluator) {
|
|
3031
|
+
const relInstance = instruction[2];
|
|
3032
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3033
|
+
return typeof target === 'string' && unicodeLength(target) <= instruction[5];
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
function AssertionTypeArrayUpper_fast(instruction, instance, depth, template, evaluator) {
|
|
3037
|
+
const relInstance = instruction[2];
|
|
3038
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3039
|
+
return Array.isArray(target) && target.length <= instruction[5];
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
function AssertionTypeObjectBounded_fast(instruction, instance, depth, template, evaluator) {
|
|
3043
|
+
const relInstance = instruction[2];
|
|
3044
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3045
|
+
if (!isObject(target)) return false;
|
|
3046
|
+
const range = instruction[5];
|
|
3047
|
+
const size = objectSize(target);
|
|
3048
|
+
if (size < range[0]) return false;
|
|
3049
|
+
return range[1] === null || size <= range[1];
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
function AssertionTypeObjectUpper_fast(instruction, instance, depth, template, evaluator) {
|
|
3053
|
+
const relInstance = instruction[2];
|
|
3054
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3055
|
+
if (!isObject(target)) return false;
|
|
3056
|
+
return objectSize(target) <= instruction[5];
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
function AssertionStringSizeLess_fast(instruction, instance, depth, template, evaluator) {
|
|
3060
|
+
const target = evaluator.propertyTarget !== undefined
|
|
3061
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
3062
|
+
if (typeof target !== 'string') return true;
|
|
3063
|
+
return unicodeLength(target) < instruction[5];
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
function AssertionStringSizeGreater_fast(instruction, instance, depth, template, evaluator) {
|
|
3067
|
+
const target = evaluator.propertyTarget !== undefined
|
|
3068
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
3069
|
+
if (typeof target !== 'string') return true;
|
|
3070
|
+
return unicodeLength(target) > instruction[5];
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
function AssertionArraySizeLess_fast(instruction, instance, depth, template, evaluator) {
|
|
3074
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3075
|
+
if (!Array.isArray(target)) return true;
|
|
3076
|
+
return target.length < instruction[5];
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
function AssertionArraySizeGreater_fast(instruction, instance, depth, template, evaluator) {
|
|
3080
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3081
|
+
if (!Array.isArray(target)) return true;
|
|
3082
|
+
return target.length > instruction[5];
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
function AssertionObjectSizeLess_fast(instruction, instance, depth, template, evaluator) {
|
|
3086
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3087
|
+
if (!isObject(target)) return true;
|
|
3088
|
+
return objectSize(target) < instruction[5];
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
function AssertionObjectSizeGreater_fast(instruction, instance, depth, template, evaluator) {
|
|
3092
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3093
|
+
if (!isObject(target)) return true;
|
|
3094
|
+
return objectSize(target) > instruction[5];
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
function AssertionGreaterEqual_fast(instruction, instance, depth, template, evaluator) {
|
|
3098
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3099
|
+
if (typeof target !== 'number') return true;
|
|
3100
|
+
return target >= instruction[5];
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
function AssertionLessEqual_fast(instruction, instance, depth, template, evaluator) {
|
|
3104
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3105
|
+
if (typeof target !== 'number') return true;
|
|
3106
|
+
return target <= instruction[5];
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
function AssertionGreater_fast(instruction, instance, depth, template, evaluator) {
|
|
3110
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3111
|
+
if (typeof target !== 'number') return true;
|
|
3112
|
+
return target > instruction[5];
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
function AssertionLess_fast(instruction, instance, depth, template, evaluator) {
|
|
3116
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3117
|
+
if (typeof target !== 'number') return true;
|
|
3118
|
+
return target < instruction[5];
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
function AssertionUnique_fast(instruction, instance, depth, template, evaluator) {
|
|
3122
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3123
|
+
if (!Array.isArray(target)) return true;
|
|
3124
|
+
return isUnique(target);
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
function AssertionDivisible_fast(instruction, instance, depth, template, evaluator) {
|
|
3128
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3129
|
+
if (typeof target !== 'number') return true;
|
|
3130
|
+
return isDivisibleBy(target, instruction[5]);
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
function AssertionStringType_fast(instruction, instance, depth, template, evaluator) {
|
|
3134
|
+
const target = evaluator.propertyTarget !== undefined
|
|
3135
|
+
? evaluator.propertyTarget : resolveInstance(instance, instruction[2]);
|
|
3136
|
+
if (typeof target !== 'string') return true;
|
|
3137
|
+
return URI_REGEX.test(target);
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
function AssertionPropertyType_fast(instruction, instance, depth, template, evaluator) {
|
|
3141
|
+
if (!isObject(instance)) return true;
|
|
3142
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3143
|
+
if (target === undefined) return true;
|
|
3144
|
+
const expected = instruction[5];
|
|
3145
|
+
const actual = jsonTypeOf(target);
|
|
3146
|
+
return actual === expected || (expected === Type.Integer && isIntegral(target));
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
function AssertionPropertyTypeEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3150
|
+
if (!isObject(instance)) return true;
|
|
3151
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3152
|
+
if (target === undefined) return true;
|
|
3153
|
+
const expected = instruction[5];
|
|
3154
|
+
const actual = jsonTypeOf(target);
|
|
3155
|
+
const result = actual === expected || (expected === Type.Integer && isIntegral(target));
|
|
3156
|
+
if (result && evaluator.trackMode) {
|
|
3157
|
+
const location = instruction[2];
|
|
3158
|
+
evaluator.markEvaluated(target, instance, location.length > 0 ? location[location.length - 1] : undefined);
|
|
3159
|
+
}
|
|
3160
|
+
return result;
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
function AssertionPropertyTypeStrictEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3164
|
+
if (!isObject(instance)) return true;
|
|
3165
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3166
|
+
if (target === undefined) return true;
|
|
3167
|
+
const result = effectiveTypeStrictReal(target) === instruction[5];
|
|
3168
|
+
if (result && evaluator.trackMode) {
|
|
3169
|
+
const location = instruction[2];
|
|
3170
|
+
evaluator.markEvaluated(target, instance, location.length > 0 ? location[location.length - 1] : undefined);
|
|
3171
|
+
}
|
|
3172
|
+
return result;
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
function AssertionPropertyTypeStrictAny_fast(instruction, instance, depth, template, evaluator) {
|
|
3176
|
+
if (!isObject(instance)) return true;
|
|
3177
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3178
|
+
if (target === undefined) return true;
|
|
3179
|
+
return typeSetTest(instruction[5], effectiveTypeStrictReal(target));
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3182
|
+
function AssertionPropertyTypeStrictAnyEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3183
|
+
if (!isObject(instance)) return true;
|
|
3184
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3185
|
+
if (target === undefined) return true;
|
|
3186
|
+
const result = typeSetTest(instruction[5], effectiveTypeStrictReal(target));
|
|
3187
|
+
if (result && evaluator.trackMode) {
|
|
3188
|
+
const location = instruction[2];
|
|
3189
|
+
evaluator.markEvaluated(target, instance, location.length > 0 ? location[location.length - 1] : undefined);
|
|
3190
|
+
}
|
|
3191
|
+
return result;
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
function AssertionArrayPrefix_fast(instruction, instance, depth, template, evaluator) {
|
|
3195
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3196
|
+
if (!Array.isArray(target)) return true;
|
|
3197
|
+
if (target.length === 0) return true;
|
|
3198
|
+
const children = instruction[6];
|
|
3199
|
+
const prefixes = children.length - 1;
|
|
3200
|
+
const pointer = target.length === prefixes ? prefixes : Math.min(target.length, prefixes) - 1;
|
|
3201
|
+
const entry = children[pointer];
|
|
3202
|
+
const entryChildren = entry[6];
|
|
3203
|
+
if (entryChildren) {
|
|
3204
|
+
for (let index = 0; index < entryChildren.length; index++) {
|
|
3205
|
+
if (!evaluateInstruction(entryChildren[index], target, depth + 1, template, evaluator)) return false;
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
return true;
|
|
3209
|
+
}
|
|
3210
|
+
|
|
3211
|
+
function AssertionArrayPrefixEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3212
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3213
|
+
if (!Array.isArray(target)) return true;
|
|
3214
|
+
if (target.length === 0) return true;
|
|
3215
|
+
const children = instruction[6];
|
|
3216
|
+
const prefixes = children.length - 1;
|
|
3217
|
+
const pointer = target.length === prefixes ? prefixes : Math.min(target.length, prefixes) - 1;
|
|
3218
|
+
const entry = children[pointer];
|
|
3219
|
+
const entryChildren = entry[6];
|
|
3220
|
+
if (entryChildren) {
|
|
3221
|
+
for (let index = 0; index < entryChildren.length; index++) {
|
|
3222
|
+
if (!evaluateInstruction(entryChildren[index], target, depth + 1, template, evaluator)) return false;
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
if (evaluator.trackMode) {
|
|
3226
|
+
if (target.length === prefixes) {
|
|
3227
|
+
evaluator.markEvaluated(target);
|
|
3228
|
+
} else {
|
|
3229
|
+
for (let cursor = 0; cursor <= pointer; cursor++) {
|
|
3230
|
+
evaluator.markEvaluated(target[cursor], target, cursor);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
return true;
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
function AnnotationEmit_fast() { return true; }
|
|
3238
|
+
function AnnotationToParent_fast() { return true; }
|
|
3239
|
+
function AnnotationBasenameToParent_fast() { return true; }
|
|
3240
|
+
|
|
3241
|
+
function Evaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3242
|
+
if (evaluator.trackMode) {
|
|
3243
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3244
|
+
evaluator.markEvaluated(target);
|
|
3245
|
+
}
|
|
3246
|
+
return true;
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
function LogicalNotEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3250
|
+
const relInstance = instruction[2];
|
|
3251
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3252
|
+
const children = instruction[6];
|
|
3253
|
+
let result = false;
|
|
3254
|
+
if (children) {
|
|
3255
|
+
for (let index = 0; index < children.length; index++) {
|
|
3256
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) {
|
|
3257
|
+
result = true;
|
|
3258
|
+
break;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
if (evaluator.trackMode) evaluator.unevaluate();
|
|
3263
|
+
return result;
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
function LogicalWhenArraySizeGreater_fast(instruction, instance, depth, template, evaluator) {
|
|
3267
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3268
|
+
if (!Array.isArray(target) || target.length <= instruction[5]) return true;
|
|
3269
|
+
const children = instruction[6];
|
|
3270
|
+
if (children) {
|
|
3271
|
+
for (let index = 0; index < children.length; index++) {
|
|
3272
|
+
if (!evaluateInstruction(children[index], target, depth + 1, template, evaluator)) return false;
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
return true;
|
|
3276
|
+
}
|
|
3277
|
+
|
|
3278
|
+
function LoopPropertiesUnevaluated_fast(instruction, instance, depth, template, evaluator) {
|
|
3279
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3280
|
+
if (!isObject(target)) return true;
|
|
3281
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target)) return true;
|
|
3282
|
+
const children = instruction[6];
|
|
3283
|
+
for (const key in target) {
|
|
3284
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target[key], target, key)) continue;
|
|
3285
|
+
if (children) {
|
|
3286
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3287
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) return false;
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
3292
|
+
return true;
|
|
3293
|
+
}
|
|
3294
|
+
|
|
3295
|
+
function LoopPropertiesUnevaluatedExcept_fast(instruction, instance, depth, template, evaluator) {
|
|
3296
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3297
|
+
if (!isObject(target)) return true;
|
|
3298
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target)) return true;
|
|
3299
|
+
const filter = instruction[5];
|
|
3300
|
+
const filterStrings = filter[0];
|
|
3301
|
+
const filterPrefixes = filter[1];
|
|
3302
|
+
const filterRegexes = filter[2];
|
|
3303
|
+
const children = instruction[6];
|
|
3304
|
+
for (const key in target) {
|
|
3305
|
+
if (filterStrings.has(key)) continue;
|
|
3306
|
+
let matched = false;
|
|
3307
|
+
for (let index = 0; index < filterPrefixes.length; index++) {
|
|
3308
|
+
if (key.startsWith(filterPrefixes[index])) { matched = true; break; }
|
|
3309
|
+
}
|
|
3310
|
+
if (matched) continue;
|
|
3311
|
+
for (let index = 0; index < filterRegexes.length; index++) {
|
|
3312
|
+
filterRegexes[index].lastIndex = 0;
|
|
3313
|
+
if (filterRegexes[index].test(key)) { matched = true; break; }
|
|
3314
|
+
}
|
|
3315
|
+
if (matched) continue;
|
|
3316
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target[key], target, key)) continue;
|
|
3317
|
+
if (children) {
|
|
3318
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3319
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) return false;
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
3324
|
+
return true;
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
function LoopPropertiesEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3328
|
+
const relInstance = instruction[2];
|
|
3329
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3330
|
+
if (!isObject(target)) return true;
|
|
3331
|
+
const children = instruction[6];
|
|
3332
|
+
for (const key in target) {
|
|
3333
|
+
evaluator.propertyParent = target;
|
|
3334
|
+
evaluator.propertyKey = key;
|
|
3335
|
+
if (children) {
|
|
3336
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3337
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
3338
|
+
evaluator.propertyParent = undefined;
|
|
3339
|
+
evaluator.propertyKey = undefined;
|
|
3340
|
+
return false;
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
evaluator.propertyParent = undefined;
|
|
3346
|
+
evaluator.propertyKey = undefined;
|
|
3347
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
3348
|
+
return true;
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
function LoopPropertiesRegex_fast(instruction, instance, depth, template, evaluator) {
|
|
3352
|
+
const relInstance = instruction[2];
|
|
3353
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3354
|
+
if (!isObject(target)) return true;
|
|
3355
|
+
const regex = instruction[5];
|
|
3356
|
+
const children = instruction[6];
|
|
3357
|
+
for (const key in target) {
|
|
3358
|
+
regex.lastIndex = 0;
|
|
3359
|
+
if (!regex.test(key)) continue;
|
|
3360
|
+
evaluator.propertyParent = target;
|
|
3361
|
+
evaluator.propertyKey = key;
|
|
3362
|
+
if (children) {
|
|
3363
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3364
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
3365
|
+
evaluator.propertyParent = undefined;
|
|
3366
|
+
evaluator.propertyKey = undefined;
|
|
3367
|
+
return false;
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
evaluator.propertyParent = undefined;
|
|
3373
|
+
evaluator.propertyKey = undefined;
|
|
3374
|
+
return true;
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
function LoopPropertiesRegexClosed_fast(instruction, instance, depth, template, evaluator) {
|
|
3378
|
+
const relInstance = instruction[2];
|
|
3379
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3380
|
+
if (!isObject(target)) return true;
|
|
3381
|
+
const regex = instruction[5];
|
|
3382
|
+
const children = instruction[6];
|
|
3383
|
+
for (const key in target) {
|
|
3384
|
+
regex.lastIndex = 0;
|
|
3385
|
+
if (!regex.test(key)) return false;
|
|
3386
|
+
evaluator.propertyParent = target;
|
|
3387
|
+
evaluator.propertyKey = key;
|
|
3388
|
+
if (children) {
|
|
3389
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3390
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
3391
|
+
evaluator.propertyParent = undefined;
|
|
3392
|
+
evaluator.propertyKey = undefined;
|
|
3393
|
+
return false;
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
evaluator.propertyParent = undefined;
|
|
3399
|
+
evaluator.propertyKey = undefined;
|
|
3400
|
+
return true;
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
function LoopPropertiesStartsWith_fast(instruction, instance, depth, template, evaluator) {
|
|
3404
|
+
const relInstance = instruction[2];
|
|
3405
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3406
|
+
if (!isObject(target)) return true;
|
|
3407
|
+
const prefix = instruction[5];
|
|
3408
|
+
const children = instruction[6];
|
|
3409
|
+
for (const key in target) {
|
|
3410
|
+
if (!key.startsWith(prefix)) continue;
|
|
3411
|
+
evaluator.propertyParent = target;
|
|
3412
|
+
evaluator.propertyKey = key;
|
|
3413
|
+
if (children) {
|
|
3414
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3415
|
+
if (!evaluateInstruction(children[childIndex], target[key], depth + 1, template, evaluator)) {
|
|
3416
|
+
evaluator.propertyParent = undefined;
|
|
3417
|
+
evaluator.propertyKey = undefined;
|
|
3418
|
+
return false;
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
evaluator.propertyParent = undefined;
|
|
3424
|
+
evaluator.propertyKey = undefined;
|
|
3425
|
+
return true;
|
|
3426
|
+
}
|
|
3427
|
+
|
|
3428
|
+
function LoopPropertiesType_fast(instruction, instance, depth, template, evaluator) {
|
|
3429
|
+
const relInstance = instruction[2];
|
|
3430
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3431
|
+
if (!isObject(target)) return true;
|
|
3432
|
+
const expected = instruction[5];
|
|
3433
|
+
for (const key in target) {
|
|
3434
|
+
const actual = jsonTypeOf(target[key]);
|
|
3435
|
+
if (actual !== expected && !(expected === Type.Integer && isIntegral(target[key]))) return false;
|
|
3436
|
+
}
|
|
3437
|
+
return true;
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
function LoopPropertiesTypeEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3441
|
+
const relInstance = instruction[2];
|
|
3442
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3443
|
+
if (!isObject(target)) return true;
|
|
3444
|
+
const expected = instruction[5];
|
|
3445
|
+
for (const key in target) {
|
|
3446
|
+
const actual = jsonTypeOf(target[key]);
|
|
3447
|
+
if (actual !== expected && !(expected === Type.Integer && isIntegral(target[key]))) return false;
|
|
3448
|
+
}
|
|
3449
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
3450
|
+
return true;
|
|
3451
|
+
}
|
|
3452
|
+
|
|
3453
|
+
function LoopPropertiesExactlyTypeStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
3454
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3455
|
+
if (!isObject(target)) return false;
|
|
3456
|
+
const value = instruction[5];
|
|
3457
|
+
let count = 0;
|
|
3458
|
+
for (const key in target) {
|
|
3459
|
+
count++;
|
|
3460
|
+
if (effectiveTypeStrictReal(target[key]) !== value[0]) return false;
|
|
3461
|
+
}
|
|
3462
|
+
return count === value[1].length;
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
function LoopPropertiesExactlyTypeStrictHash_fast(instruction, instance, depth, template, evaluator) {
|
|
3466
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3467
|
+
if (!isObject(target)) return false;
|
|
3468
|
+
const value = instruction[5];
|
|
3469
|
+
const entries = value[1][0];
|
|
3470
|
+
const expectedCount = entries.length;
|
|
3471
|
+
let count = 0;
|
|
3472
|
+
for (const key in target) {
|
|
3473
|
+
count++;
|
|
3474
|
+
if (effectiveTypeStrictReal(target[key]) !== value[0]) return false;
|
|
3475
|
+
}
|
|
3476
|
+
if (count !== expectedCount) return false;
|
|
3477
|
+
for (let index = 0; index < expectedCount; index++) {
|
|
3478
|
+
if (!Object.hasOwn(target, entries[index][1])) return false;
|
|
3479
|
+
}
|
|
3480
|
+
return true;
|
|
3481
|
+
}
|
|
3482
|
+
|
|
3483
|
+
function LoopPropertiesTypeStrict_fast(instruction, instance, depth, template, evaluator) {
|
|
3484
|
+
const relInstance = instruction[2];
|
|
3485
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3486
|
+
if (!isObject(target)) return true;
|
|
3487
|
+
const expected = instruction[5];
|
|
3488
|
+
for (const key in target) {
|
|
3489
|
+
if (effectiveTypeStrictReal(target[key]) !== expected) return false;
|
|
3490
|
+
}
|
|
3491
|
+
return true;
|
|
3492
|
+
}
|
|
3493
|
+
|
|
3494
|
+
function LoopPropertiesTypeStrictEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3495
|
+
const relInstance = instruction[2];
|
|
3496
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3497
|
+
if (!isObject(target)) return true;
|
|
3498
|
+
const expected = instruction[5];
|
|
3499
|
+
for (const key in target) {
|
|
3500
|
+
if (effectiveTypeStrictReal(target[key]) !== expected) return false;
|
|
3501
|
+
}
|
|
3502
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
3503
|
+
return true;
|
|
3504
|
+
}
|
|
3505
|
+
|
|
3506
|
+
function LoopPropertiesTypeStrictAny_fast(instruction, instance, depth, template, evaluator) {
|
|
3507
|
+
const relInstance = instruction[2];
|
|
3508
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3509
|
+
if (!isObject(target)) return true;
|
|
3510
|
+
const bitmask = instruction[5];
|
|
3511
|
+
for (const key in target) {
|
|
3512
|
+
if (!typeSetTest(bitmask, effectiveTypeStrictReal(target[key]))) return false;
|
|
3513
|
+
}
|
|
3514
|
+
return true;
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
function LoopPropertiesTypeStrictAnyEvaluate_fast(instruction, instance, depth, template, evaluator) {
|
|
3518
|
+
const relInstance = instruction[2];
|
|
3519
|
+
const target = relInstance.length === 0 ? instance : resolveInstance(instance, relInstance);
|
|
3520
|
+
if (!isObject(target)) return true;
|
|
3521
|
+
const bitmask = instruction[5];
|
|
3522
|
+
for (const key in target) {
|
|
3523
|
+
if (!typeSetTest(bitmask, effectiveTypeStrictReal(target[key]))) return false;
|
|
3524
|
+
}
|
|
3525
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
3526
|
+
return true;
|
|
3527
|
+
}
|
|
3528
|
+
|
|
3529
|
+
function LoopKeys_fast(instruction, instance, depth, template, evaluator) {
|
|
3530
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3531
|
+
if (!isObject(target)) return true;
|
|
3532
|
+
const children = instruction[6];
|
|
3533
|
+
for (const key in target) {
|
|
3534
|
+
const previousPropertyTarget = evaluator.propertyTarget;
|
|
3535
|
+
evaluator.propertyTarget = key;
|
|
3536
|
+
if (children) {
|
|
3537
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3538
|
+
if (!evaluateInstruction(children[childIndex], null, depth + 1, template, evaluator)) {
|
|
3539
|
+
evaluator.propertyTarget = previousPropertyTarget;
|
|
3540
|
+
return false;
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
evaluator.propertyTarget = previousPropertyTarget;
|
|
3545
|
+
}
|
|
3546
|
+
return true;
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
function LoopItemsFrom_fast(instruction, instance, depth, template, evaluator) {
|
|
3550
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3551
|
+
const startIndex = instruction[5];
|
|
3552
|
+
if (!Array.isArray(target) || startIndex >= target.length) return true;
|
|
3553
|
+
const children = instruction[6];
|
|
3554
|
+
for (let index = startIndex; index < target.length; index++) {
|
|
3555
|
+
if (children) {
|
|
3556
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3557
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) return false;
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
return true;
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
function LoopItemsUnevaluated_fast(instruction, instance, depth, template, evaluator) {
|
|
3565
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3566
|
+
if (!Array.isArray(target)) return true;
|
|
3567
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target)) return true;
|
|
3568
|
+
const children = instruction[6];
|
|
3569
|
+
for (let index = 0; index < target.length; index++) {
|
|
3570
|
+
if (evaluator.trackMode && evaluator.isEvaluated(target[index], target, index)) continue;
|
|
3571
|
+
if (children) {
|
|
3572
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
3573
|
+
if (!evaluateInstruction(children[childIndex], target[index], depth + 1, template, evaluator)) return false;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
if (evaluator.trackMode) evaluator.markEvaluated(target);
|
|
3578
|
+
return true;
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
function LoopItemsPropertiesExactlyTypeStrictHash_fast(instruction, instance, depth, template, evaluator) {
|
|
3582
|
+
const target = resolveInstance(instance, instruction[2]);
|
|
3583
|
+
if (!Array.isArray(target)) return false;
|
|
3584
|
+
const expectedType = instruction[5][0];
|
|
3585
|
+
const entries = instruction[5][1][0];
|
|
3586
|
+
const expectedCount = entries.length;
|
|
3587
|
+
for (let index = 0; index < target.length; index++) {
|
|
3588
|
+
const item = target[index];
|
|
3589
|
+
if (!isObject(item)) return false;
|
|
3590
|
+
let count = 0;
|
|
3591
|
+
for (const key in item) {
|
|
3592
|
+
count++;
|
|
3593
|
+
if (effectiveTypeStrictReal(item[key]) !== expectedType) return false;
|
|
3594
|
+
}
|
|
3595
|
+
if (count !== expectedCount) return false;
|
|
3596
|
+
for (let entry = 0; entry < expectedCount; entry++) {
|
|
3597
|
+
if (!Object.hasOwn(item, entries[entry][1])) return false;
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
return true;
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3603
|
+
function ControlDynamicAnchorJump_fast(instruction, instance, depth, template, evaluator) {
|
|
3604
|
+
const resolved = resolveInstance(instance, instruction[2]);
|
|
3605
|
+
const anchor = instruction[5];
|
|
3606
|
+
if (!evaluator.resources) return false;
|
|
3607
|
+
const anchors = template[5];
|
|
3608
|
+
for (let index = 0; index < evaluator.resources.length; index++) {
|
|
3609
|
+
const jumpTarget = anchors.get(evaluator.resources[index] + ':' + anchor);
|
|
3610
|
+
if (jumpTarget !== undefined) {
|
|
3611
|
+
for (let childIndex = 0; childIndex < jumpTarget.length; childIndex++) {
|
|
3612
|
+
if (!evaluateInstruction(jumpTarget[childIndex], resolved, depth + 1, template, evaluator)) return false;
|
|
3613
|
+
}
|
|
3614
|
+
return true;
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
return false;
|
|
3618
|
+
}
|
|
3619
|
+
|
|
3620
|
+
const fastHandlers = handlers.slice();
|
|
3621
|
+
fastHandlers[15] = AssertionTypeArrayBounded_fast;
|
|
3622
|
+
fastHandlers[81] = LoopItemsTypeStrictAny_fast;
|
|
3623
|
+
fastHandlers[38] = AssertionPropertyTypeStrict_fast;
|
|
3624
|
+
fastHandlers[11] = AssertionTypeStrict_fast;
|
|
3625
|
+
fastHandlers[4] = AssertionDefinesAllStrict_fast;
|
|
3626
|
+
fastHandlers[26] = AssertionEqual_fast;
|
|
3627
|
+
fastHandlers[59] = LoopPropertiesMatch_fast;
|
|
3628
|
+
fastHandlers[50] = LogicalOr_fast;
|
|
3629
|
+
fastHandlers[91] = ControlJump_fast;
|
|
3630
|
+
fastHandlers[28] = AssertionEqualsAnyStringHash_fast;
|
|
3631
|
+
fastHandlers[52] = LogicalXor_fast;
|
|
3632
|
+
fastHandlers[2] = AssertionDefinesStrict_fast;
|
|
3633
|
+
fastHandlers[76] = LoopItems_fast;
|
|
3634
|
+
fastHandlers[60] = LoopPropertiesMatchClosed_fast;
|
|
3635
|
+
fastHandlers[13] = AssertionTypeStringBounded_fast;
|
|
3636
|
+
fastHandlers[51] = LogicalAnd_fast;
|
|
3637
|
+
fastHandlers[8] = AssertionPropertyDependencies_fast;
|
|
3638
|
+
fastHandlers[10] = AssertionTypeAny_fast;
|
|
3639
|
+
fastHandlers[53] = LogicalCondition_fast;
|
|
3640
|
+
fastHandlers[66] = LoopPropertiesExcept_fast;
|
|
3641
|
+
fastHandlers[19] = AssertionRegex_fast;
|
|
3642
|
+
fastHandlers[61] = LoopProperties_fast;
|
|
3643
|
+
fastHandlers[1] = AssertionDefines_fast;
|
|
3644
|
+
fastHandlers[54] = LogicalWhenType_fast;
|
|
3645
|
+
fastHandlers[55] = LogicalWhenDefines_fast;
|
|
3646
|
+
fastHandlers[0] = AssertionFail_fast;
|
|
3647
|
+
fastHandlers[84] = LoopContains_fast;
|
|
3648
|
+
fastHandlers[48] = LogicalNot_fast;
|
|
3649
|
+
fastHandlers[79] = LoopItemsType_fast;
|
|
3650
|
+
fastHandlers[80] = LoopItemsTypeStrict_fast;
|
|
3651
|
+
fastHandlers[27] = AssertionEqualsAny_fast;
|
|
3652
|
+
fastHandlers[3] = AssertionDefinesAll_fast;
|
|
3653
|
+
fastHandlers[5] = AssertionDefinesExactly_fast;
|
|
3654
|
+
fastHandlers[6] = AssertionDefinesExactlyStrict_fast;
|
|
3655
|
+
fastHandlers[7] = AssertionDefinesExactlyStrictHash3_fast;
|
|
3656
|
+
fastHandlers[9] = AssertionType_fast;
|
|
3657
|
+
fastHandlers[12] = AssertionTypeStrictAny_fast;
|
|
3658
|
+
fastHandlers[14] = AssertionTypeStringUpper_fast;
|
|
3659
|
+
fastHandlers[16] = AssertionTypeArrayUpper_fast;
|
|
3660
|
+
fastHandlers[17] = AssertionTypeObjectBounded_fast;
|
|
3661
|
+
fastHandlers[18] = AssertionTypeObjectUpper_fast;
|
|
3662
|
+
fastHandlers[20] = AssertionStringSizeLess_fast;
|
|
3663
|
+
fastHandlers[21] = AssertionStringSizeGreater_fast;
|
|
3664
|
+
fastHandlers[22] = AssertionArraySizeLess_fast;
|
|
3665
|
+
fastHandlers[23] = AssertionArraySizeGreater_fast;
|
|
3666
|
+
fastHandlers[24] = AssertionObjectSizeLess_fast;
|
|
3667
|
+
fastHandlers[25] = AssertionObjectSizeGreater_fast;
|
|
3668
|
+
fastHandlers[29] = AssertionGreaterEqual_fast;
|
|
3669
|
+
fastHandlers[30] = AssertionLessEqual_fast;
|
|
3670
|
+
fastHandlers[31] = AssertionGreater_fast;
|
|
3671
|
+
fastHandlers[32] = AssertionLess_fast;
|
|
3672
|
+
fastHandlers[33] = AssertionUnique_fast;
|
|
3673
|
+
fastHandlers[34] = AssertionDivisible_fast;
|
|
3674
|
+
fastHandlers[35] = AssertionStringType_fast;
|
|
3675
|
+
fastHandlers[36] = AssertionPropertyType_fast;
|
|
3676
|
+
fastHandlers[37] = AssertionPropertyTypeEvaluate_fast;
|
|
3677
|
+
fastHandlers[39] = AssertionPropertyTypeStrictEvaluate_fast;
|
|
3678
|
+
fastHandlers[40] = AssertionPropertyTypeStrictAny_fast;
|
|
3679
|
+
fastHandlers[41] = AssertionPropertyTypeStrictAnyEvaluate_fast;
|
|
3680
|
+
fastHandlers[42] = AssertionArrayPrefix_fast;
|
|
3681
|
+
fastHandlers[43] = AssertionArrayPrefixEvaluate_fast;
|
|
3682
|
+
fastHandlers[44] = AnnotationEmit_fast;
|
|
3683
|
+
fastHandlers[45] = AnnotationToParent_fast;
|
|
3684
|
+
fastHandlers[46] = AnnotationBasenameToParent_fast;
|
|
3685
|
+
fastHandlers[47] = Evaluate_fast;
|
|
3686
|
+
fastHandlers[49] = LogicalNotEvaluate_fast;
|
|
3687
|
+
fastHandlers[56] = LogicalWhenArraySizeGreater_fast;
|
|
3688
|
+
fastHandlers[57] = LoopPropertiesUnevaluated_fast;
|
|
3689
|
+
fastHandlers[58] = LoopPropertiesUnevaluatedExcept_fast;
|
|
3690
|
+
fastHandlers[62] = LoopPropertiesEvaluate_fast;
|
|
3691
|
+
fastHandlers[63] = LoopPropertiesRegex_fast;
|
|
3692
|
+
fastHandlers[64] = LoopPropertiesRegexClosed_fast;
|
|
3693
|
+
fastHandlers[65] = LoopPropertiesStartsWith_fast;
|
|
3694
|
+
fastHandlers[67] = LoopPropertiesType_fast;
|
|
3695
|
+
fastHandlers[68] = LoopPropertiesTypeEvaluate_fast;
|
|
3696
|
+
fastHandlers[69] = LoopPropertiesExactlyTypeStrict_fast;
|
|
3697
|
+
fastHandlers[70] = LoopPropertiesExactlyTypeStrictHash_fast;
|
|
3698
|
+
fastHandlers[71] = LoopPropertiesTypeStrict_fast;
|
|
3699
|
+
fastHandlers[72] = LoopPropertiesTypeStrictEvaluate_fast;
|
|
3700
|
+
fastHandlers[73] = LoopPropertiesTypeStrictAny_fast;
|
|
3701
|
+
fastHandlers[74] = LoopPropertiesTypeStrictAnyEvaluate_fast;
|
|
3702
|
+
fastHandlers[75] = LoopKeys_fast;
|
|
3703
|
+
fastHandlers[77] = LoopItemsFrom_fast;
|
|
3704
|
+
fastHandlers[78] = LoopItemsUnevaluated_fast;
|
|
3705
|
+
fastHandlers[82] = LoopItemsPropertiesExactlyTypeStrictHash_fast;
|
|
3706
|
+
fastHandlers[83] = LoopItemsPropertiesExactlyTypeStrictHash_fast;
|
|
3707
|
+
fastHandlers[90] = ControlDynamicAnchorJump_fast;
|
|
3708
|
+
|
|
3709
|
+
export { Blaze };
|