mirror of https://github.com/Icinga/icinga2.git
parent
1cd8a25ab2
commit
8deeb73bb8
|
@ -155,7 +155,6 @@ static Array::Ptr ArrayMap(const Function::Ptr& function)
|
|||
|
||||
ObjectLock olock(self);
|
||||
BOOST_FOREACH(const Value& item, self) {
|
||||
ScriptFrame uframe;
|
||||
std::vector<Value> args;
|
||||
args.push_back(item);
|
||||
result->Add(function->Invoke(args));
|
||||
|
@ -179,7 +178,6 @@ static Value ArrayReduce(const Function::Ptr& function)
|
|||
|
||||
ObjectLock olock(self);
|
||||
for (size_t i = 1; i < self->GetLength(); i++) {
|
||||
ScriptFrame uframe;
|
||||
std::vector<Value> args;
|
||||
args.push_back(result);
|
||||
args.push_back(self->Get(i));
|
||||
|
@ -201,7 +199,6 @@ static Array::Ptr ArrayFilter(const Function::Ptr& function)
|
|||
|
||||
ObjectLock olock(self);
|
||||
BOOST_FOREACH(const Value& item, self) {
|
||||
ScriptFrame uframe;
|
||||
std::vector<Value> args;
|
||||
args.push_back(item);
|
||||
if (function->Invoke(args))
|
||||
|
@ -250,5 +247,4 @@ Object::Ptr Array::GetPrototype(void)
|
|||
}
|
||||
|
||||
return prototype;
|
||||
}
|
||||
|
||||
}
|
|
@ -33,9 +33,8 @@ static Value FunctionCall(const std::vector<Value>& args)
|
|||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||
Function::Ptr self = static_cast<Function::Ptr>(vframe->Self);
|
||||
|
||||
ScriptFrame uframe(args[0]);
|
||||
std::vector<Value> uargs(args.begin() + 1, args.end());
|
||||
return self->Invoke(uargs);
|
||||
return self->Invoke(args[0], uargs);
|
||||
}
|
||||
|
||||
static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
|
||||
|
@ -43,7 +42,6 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
|
|||
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
|
||||
Function::Ptr self = static_cast<Function::Ptr>(vframe->Self);
|
||||
|
||||
ScriptFrame uframe(thisArg);
|
||||
std::vector<Value> uargs;
|
||||
|
||||
{
|
||||
|
@ -51,7 +49,7 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
|
|||
uargs = std::vector<Value>(args->Begin(), args->End());
|
||||
}
|
||||
|
||||
return self->Invoke(uargs);
|
||||
return self->Invoke(thisArg, uargs);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "base/function.hpp"
|
||||
#include "base/primitivetype.hpp"
|
||||
#include "base/dictionary.hpp"
|
||||
#include "base/scriptframe.hpp"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
|
@ -31,6 +32,14 @@ Function::Function(const Callback& function, bool side_effect_free)
|
|||
|
||||
Value Function::Invoke(const std::vector<Value>& arguments)
|
||||
{
|
||||
ScriptFrame frame;
|
||||
return m_Callback(arguments);
|
||||
}
|
||||
|
||||
Value Function::Invoke(const Value& otherThis, const std::vector<Value>& arguments)
|
||||
{
|
||||
ScriptFrame frame;
|
||||
frame.Self = otherThis;
|
||||
return m_Callback(arguments);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
Function(const Callback& function, bool side_effect_free = false);
|
||||
|
||||
Value Invoke(const std::vector<Value>& arguments = std::vector<Value>());
|
||||
Value Invoke(const Value& otherThis, const std::vector<Value>& arguments = std::vector<Value>());
|
||||
bool IsSideEffectFree(void) const;
|
||||
|
||||
static Object::Ptr GetPrototype(void);
|
||||
|
|
|
@ -30,8 +30,6 @@ static void InvokeAttributeHandlerHelper(const Function::Ptr& callback,
|
|||
{
|
||||
std::vector<Value> arguments;
|
||||
arguments.push_back(object);
|
||||
|
||||
ScriptFrame frame;
|
||||
callback->Invoke(arguments);
|
||||
}
|
||||
|
||||
|
|
|
@ -619,10 +619,7 @@ bool ConfigItem::RunWithActivationContext(const Function::Ptr& function)
|
|||
if (!function)
|
||||
BOOST_THROW_EXCEPTION(ScriptError("'function' argument must not be null."));
|
||||
|
||||
{
|
||||
ScriptFrame frame;
|
||||
function->Invoke();
|
||||
}
|
||||
function->Invoke();
|
||||
|
||||
WorkQueue upq(25000, Application::GetConcurrency());
|
||||
upq.SetName("ConfigItem::RunWithActivationContext");
|
||||
|
|
|
@ -89,9 +89,10 @@ public:
|
|||
ScriptFrame vframe;
|
||||
|
||||
if (!self.IsEmpty() || self.IsString())
|
||||
vframe.Self = self;
|
||||
return func->Invoke(self, arguments);
|
||||
else
|
||||
return func->Invoke(arguments);
|
||||
|
||||
return func->Invoke(arguments);
|
||||
}
|
||||
|
||||
static inline Value NewFunction(ScriptFrame& frame, const std::vector<String>& args,
|
||||
|
|
|
@ -223,8 +223,8 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver
|
|||
_1, boost::cref(resolvers), cr, resolvedMacros, useResolvedMacros,
|
||||
recursionLevel + 1)));
|
||||
|
||||
ScriptFrame frame(resolvers_this);
|
||||
return func->Invoke();
|
||||
std::vector<Value> args;
|
||||
return func->Invoke(resolvers_this, args);
|
||||
}
|
||||
|
||||
Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers,
|
||||
|
|
Loading…
Reference in New Issue