From 6bb054caa8adca3eea4c601f006b8128e44ec938 Mon Sep 17 00:00:00 2001
From: Gunnar Beutner <gunnar@beutner.name>
Date: Thu, 15 Jan 2015 12:52:23 +0100
Subject: [PATCH] Implement the Function#callv helper function

refs #8169
---
 lib/base/scriptfunction-script.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/base/scriptfunction-script.cpp b/lib/base/scriptfunction-script.cpp
index 1ba64d666..02e501ed9 100644
--- a/lib/base/scriptfunction-script.cpp
+++ b/lib/base/scriptfunction-script.cpp
@@ -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;