Add maxRecursionDepth in GenericEvaluationEngine

This commit is contained in:
fwcd
2020-09-02 18:07:22 +02:00
parent 0ce1b02b2c
commit 6ef0ecb60f

View File

@@ -58,7 +58,7 @@ export class GenericEvaluator implements Evaluator {
name: "Generic", name: "Generic",
priority: 1, priority: 1,
}, },
data: await this.constructObjectFromVariablesReference(reply.variablesReference, {}), data: await this.constructObjectFromVariablesReference(reply.variablesReference),
}, },
} }
} else { } else {
@@ -88,21 +88,24 @@ export class GenericEvaluator implements Evaluator {
} }
} }
private async constructObjectFromVariablesReference(variablesReference: number, knownObjects: { [ref: number]: any; }): Promise<any> { private async constructObjectFromVariablesReference(
variablesReference: number,
knownObjects: { [ref: number]: any; } = {},
recursionDepth: number = 0,
maxRecursionDepth: number = 50,
): Promise<any> {
var result: any = {}; var result: any = {};
knownObjects[variablesReference] = result; knownObjects[variablesReference] = result;
for (const variable of await this.session.getVariables({ variablesReference })) { for (const variable of await this.session.getVariables({ variablesReference })) {
let child: any; let child: any;
if (variable.variablesReference > 0) { if (variable.variablesReference > 0 && variable.variablesReference in knownObjects) {
if (variable.variablesReference in knownObjects) { // If the object is known, we have a (potentially cyclic) reference
// If the object is known, we have a (potentially cyclic) reference child = knownObjects[variable.variablesReference];
child = knownObjects[variable.variablesReference]; } else if (variable.variablesReference > 0 && recursionDepth < maxRecursionDepth) {
} else { // Recurse on a new object
// Recurse on a new object child = await this.constructObjectFromVariablesReference(variable.variablesReference, knownObjects, recursionDepth + 1, maxRecursionDepth);
child = await this.constructObjectFromVariablesReference(variable.variablesReference, knownObjects);
}
} else { } else {
// If there are no childs, just assign the value // If there are no childs, just assign the value
child = variable.value; child = variable.value;