Implement the Function#callv helper function

refs 
This commit is contained in:
Gunnar Beutner 2015-01-15 12:52:23 +01:00
parent 5d8356f6d2
commit 6bb054caa8
1 changed files with 19 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include "base/scriptfunction.hpp"
#include "base/scriptfunctionwrapper.hpp"
#include "base/scriptframe.hpp"
#include "base/objectlock.hpp"
#include "base/exception.hpp"
using namespace icinga;
@ -37,6 +38,23 @@ static Value ScriptFunctionCall(const std::vector<Value>& args)
return self->Invoke(uargs);
}
static Value ScriptFunctionCallV(const Value& thisArg, const Array::Ptr& args)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
ScriptFunction::Ptr self = static_cast<ScriptFunction::Ptr>(vframe->Self);
ScriptFrame uframe(thisArg);
std::vector<Value> uargs;
{
ObjectLock olock(args);
uargs = std::vector<Value>(args->Begin(), args->End());
}
return self->Invoke(uargs);
}
Object::Ptr ScriptFunction::GetPrototype(void)
{
static Dictionary::Ptr prototype;
@ -44,6 +62,7 @@ Object::Ptr ScriptFunction::GetPrototype(void)
if (!prototype) {
prototype = new Dictionary();
prototype->Set("call", new ScriptFunction(WrapScriptFunction(ScriptFunctionCall)));
prototype->Set("callv", new ScriptFunction(WrapScriptFunction(ScriptFunctionCallV)));
}
return prototype;