validateContextExistence method
void
validateContextExistence(})
Checks whether the given name
exists in the programContext
. If not,
throws an exception with details and possible recovery suggestions.
Implementation
void validateContextExistence(String name, Node node, Context programContext,
{bool isObject = false}) {
// Check all contexts in the stack from innermost to outermost
for (var ctx in _contextStack.reversed) {
if (ctx.hasContext(name)) {
return;
}
}
final available = currentContext.getContextMap().keys.join(", ");
throw JSException(
node.line ?? 1,
'${isObject ? "Object" : "Variable"} "$name" is not defined in the current context',
detailedError:
'Code: ${_interpreter.getCode(node)}\nAvailable ${isObject ? "objects" : "variables"}: $available',
recovery:
'Check if you have declared the ${isObject ? "object" : "variable"} correctly (including case sensitivity).',
);
}