mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
Expression: Decrease frame.Depth
only when calling IncreaseStackDepth()
succeeds
This ensures that `frame.Depth` is only decreased when preceding `frame.IncreaseStackDepth()` callee was successful. This way, `frame.Depth` will have the same depth prior to and after evaluating a frame.
This commit is contained in:
parent
86b63a57ae
commit
31785b48fd
@ -13,6 +13,7 @@
|
|||||||
#include "base/loader.hpp"
|
#include "base/loader.hpp"
|
||||||
#include "base/reference.hpp"
|
#include "base/reference.hpp"
|
||||||
#include "base/namespace.hpp"
|
#include "base/namespace.hpp"
|
||||||
|
#include "base/defer.hpp"
|
||||||
#include <boost/exception_ptr.hpp>
|
#include <boost/exception_ptr.hpp>
|
||||||
#include <boost/exception/errinfo_nested_exception.hpp>
|
#include <boost/exception/errinfo_nested_exception.hpp>
|
||||||
|
|
||||||
@ -46,22 +47,20 @@ ExpressionResult Expression::Evaluate(ScriptFrame& frame, DebugHint *dhint) cons
|
|||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
frame.IncreaseStackDepth();
|
frame.IncreaseStackDepth();
|
||||||
|
|
||||||
|
Defer decreaseStackDepth([&frame]{
|
||||||
|
frame.DecreaseStackDepth();
|
||||||
|
});
|
||||||
|
|
||||||
ExpressionResult result = DoEvaluate(frame, dhint);
|
ExpressionResult result = DoEvaluate(frame, dhint);
|
||||||
frame.DecreaseStackDepth();
|
|
||||||
return result;
|
return result;
|
||||||
} catch (ScriptError& ex) {
|
} catch (ScriptError& ex) {
|
||||||
frame.DecreaseStackDepth();
|
|
||||||
|
|
||||||
ScriptBreakpoint(frame, &ex, GetDebugInfo());
|
ScriptBreakpoint(frame, &ex, GetDebugInfo());
|
||||||
throw;
|
throw;
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
frame.DecreaseStackDepth();
|
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Error while evaluating expression: " + String(ex.what()), GetDebugInfo())
|
BOOST_THROW_EXCEPTION(ScriptError("Error while evaluating expression: " + String(ex.what()), GetDebugInfo())
|
||||||
<< boost::errinfo_nested_exception(boost::current_exception()));
|
<< boost::errinfo_nested_exception(boost::current_exception()));
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.DecreaseStackDepth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Expression::GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const
|
bool Expression::GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user