return *current;
}
-EvaluationContext::EvaluationContext(ExecutorInterface &ei) : parent(current)
+EvaluationContext::EvaluationContext(ExecutorInterface &ei) : parent(current), stackLevel(initializeStackLevel(parent))
{
current = this;
initializeGlobalContext(ei);
}
-EvaluationContext::EvaluationContext() : parent(current)
+EvaluationContext::EvaluationContext() : parent(current), stackLevel(initializeStackLevel(parent))
{
ASSERT(parent);
current = this;
this->data->parent = parent->data;
}
-EvaluationContext::EvaluationContext(std::shared_ptr<Data> data) : parent(current)
+EvaluationContext::EvaluationContext(std::shared_ptr<Data> data) : parent(current), stackLevel(initializeStackLevel(parent))
{
current = this;
globalContext = this->parent->globalContext;
throw EvaluationFailure{} << "getUIElementPosition not implemeneted";
}
+size_t EvaluationContext::getStackLevel() const
+{
+ return stackLevel;
+}
+
+size_t EvaluationContext::initializeStackLevel(EvaluationContext *parent)
+{
+ if (!parent)
+ return 0;
+
+ if (parent->getStackLevel() >= MAX_CALL_STACK_LEVEL)
+ throw EvaluationFailure{} << "Maximum call stack size exceeded";
+
+ return parent->getStackLevel() + 1;
+}
+
std::string ExecutorInterface::getUIElementName(const std::shared_ptr<UIElement> &elem)
{
throw EvaluationFailure{} << "getUIElementName not implemeneted";
*/
const std::string &topBatchPath();
+ size_t getStackLevel() const;
+
private:
void initializeGlobalContext(ExecutorInterface &ei);
+ static size_t initializeStackLevel(EvaluationContext *parent);
std::shared_ptr<Data> data = std::make_shared<Data>();
EvaluationContext *parent = nullptr;
std::shared_ptr<GlobalContext> globalContext;
std::vector<const std::string *> batchPathStack;
+ const size_t stackLevel = 0;
+
+ static constexpr size_t MAX_CALL_STACK_LEVEL = 64;
};
#endif
ASSERT_EQ(expected, 13);
}
+TEST_F(ScriptTest, functionRecursiveCall)
+{
+ TestBatchExecutor exec;
+ EvaluationContext ec{ exec };
+
+ ASSERT_THROW(
+ execute("def myFunc() {\n"
+ " myFunc()\n"
+ " }\n"
+ "myFunc()", ec, false)
+ , EvaluationFailure);
+}
+
int main(int argc, char *argv[])
{
try {