コード例 #1
0
ファイル: Server.cpp プロジェクト: steilman/samp.js
void Server::Init(Local<Context> ctx){
	isolate = ctx->GetIsolate();
	context.Reset(ctx->GetIsolate(), ctx);


	ifstream serverFile("js/samp.js/Server.js", std::ios::in);
	if (!serverFile){
		sjs::logger::error("Missing required file Server.js");
		SAMPJS::Shutdown();
	}
	std::string serverSource((std::istreambuf_iterator<char>(serverFile)), std::istreambuf_iterator<char>());
	SAMPJS::ExecuteCode(ctx, "Server.js", serverSource);

	SAMPJS::ExecuteCode(ctx, "$server", "var $server = new Server();");

	JS_Object global(ctx->Global());

	global.Set("CallNative", Server::JS_CallNative);

	JS_Object server(global.getObject("$server"));

	JS_Object memory(server.getObject("memory"));

	memory.Set("current", Server::JS_CurrentMemory);
	memory.Set("peak", Server::JS_PeakMemory);
	
	server.Set("Debug", Utils::JS_Debug);

	
}
コード例 #2
0
void Proxy::bindProxy(Local<Object> exports, Local<Context> context)
{
    Isolate* isolate = context->GetIsolate();
    Local<String> javaClass = NEW_SYMBOL(isolate, "__javaClass__");
    javaClassSymbol.Reset(isolate, javaClass);
    constructorSymbol.Reset(isolate, NEW_SYMBOL(isolate, "constructor"));
    inheritSymbol.Reset(isolate, NEW_SYMBOL(isolate, "inherit"));
    propertiesSymbol.Reset(isolate, NEW_SYMBOL(isolate, "_properties"));
    lengthSymbol.Reset(isolate, NEW_SYMBOL(isolate, "length"));
    sourceUrlSymbol.Reset(isolate, NEW_SYMBOL(isolate, "sourceUrl"));

    Local<FunctionTemplate> proxyTemplate = FunctionTemplate::New(isolate);
    Local<String> proxySymbol = NEW_SYMBOL(isolate, "Proxy");
    proxyTemplate->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
    proxyTemplate->SetClassName(proxySymbol);
    proxyTemplate->Inherit(EventEmitter::constructorTemplate.Get(isolate));

    proxyTemplate->Set(javaClass, External::New(isolate, JNIUtil::krollProxyClass),
                       static_cast<PropertyAttribute>(DontDelete | DontEnum));

    SetProtoMethod(isolate, proxyTemplate, "_hasListenersForEventType", hasListenersForEventType);
    SetProtoMethod(isolate, proxyTemplate, "onPropertiesChanged", proxyOnPropertiesChanged);
    SetProtoMethod(isolate, proxyTemplate, "_onEventFired", onEventFired);

    baseProxyTemplate.Reset(isolate, proxyTemplate);

    exports->Set(proxySymbol, proxyTemplate->GetFunction(context).ToLocalChecked());
}
コード例 #3
0
ファイル: main.cpp プロジェクト: gitter-badger/open-intent
void InitAll(Local<Object> exports) {
    //intent::log::Logger::initialize(intent::log::Logger::SeverityLevel::TRACE);

    intentjs::SerializableChatbot::Init(exports->GetIsolate());
    NODE_SET_METHOD(exports, "createSerializableChatbotFromJsonModel", CreateSerializableChatbotFromJsonModel);
    NODE_SET_METHOD(exports, "createSerializableChatbotFromOIML", CreateSerializableChatbotFromOIML);
}
コード例 #4
0
/* static */
void V8Runtime::bootstrap(Local<Context> context)
{
	Isolate* isolate = context->GetIsolate();
	EventEmitter::initTemplate(context);

	Local<Object> kroll = Object::New(isolate);
	krollGlobalObject.Reset(isolate, kroll);
	Local<Array> mc = Array::New(isolate);
	moduleContexts.Reset(isolate, mc);

	KrollBindings::initFunctions(kroll, context);

	SetMethod(isolate, kroll, "log", krollLog);
	// Move this into the EventEmitter::initTemplate call?
	Local<FunctionTemplate> eect = Local<FunctionTemplate>::New(isolate, EventEmitter::constructorTemplate);
	{
		v8::TryCatch tryCatch(isolate);
		Local<Function> eventEmitterConstructor;
		MaybeLocal<Function> maybeEventEmitterConstructor = eect->GetFunction(context);
		if (!maybeEventEmitterConstructor.ToLocal(&eventEmitterConstructor)) {
			titanium::V8Util::fatalException(isolate, tryCatch);
			return;
		}
		kroll->Set(NEW_SYMBOL(isolate, "EventEmitter"), eventEmitterConstructor);
	}

	kroll->Set(NEW_SYMBOL(isolate, "runtime"), STRING_NEW(isolate, "v8"));
	kroll->Set(NEW_SYMBOL(isolate, "DBG"), v8::Boolean::New(isolate, V8Runtime::DBG));
	kroll->Set(NEW_SYMBOL(isolate, "moduleContexts"), mc);

	LOG_TIMER(TAG, "Executing kroll.js");

	TryCatch tryCatch(isolate);
	Local<Value> result = V8Util::executeString(isolate, KrollBindings::getMainSource(isolate), STRING_NEW(isolate, "ti:/kroll.js"));

	if (tryCatch.HasCaught()) {
		V8Util::reportException(isolate, tryCatch, true);
	}
	if (!result->IsFunction()) {
		LOGF(TAG, "kroll.js result is not a function");
		V8Util::reportException(isolate, tryCatch, true);
	}

	// Add a reference to the global object
	Local<Object> global = context->Global();

	// Expose the global object as a property on itself
	// (Allows you to set stuff on `global` from anywhere in JavaScript.)
	global->Set(NEW_SYMBOL(isolate, "global"), global);

	Local<Function> mainFunction = result.As<Function>();
	Local<Value> args[] = { kroll };
	mainFunction->Call(context, global, 1, args);

	if (tryCatch.HasCaught()) {
		V8Util::reportException(isolate, tryCatch, true);
		LOGE(TAG, "Caught exception while bootstrapping Kroll");
	}
}
コード例 #5
0
ファイル: Server.cpp プロジェクト: damospiderman/samp.js
shared_ptr<Server> Server::GetInstance(Local<Context> context){
	sjs::logger::debug("Getting Instance");
	Local<Object> self = Local<Object>::Cast(context->Global()->Get(STRING2JS(context->GetIsolate(), "$sampjs")));
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
	Server* server = static_cast<Server*>(ptr);
	sjs::logger::debug("Casting");
	return make_shared<Server>(*server);
}
コード例 #6
0
void ABPFilterParserWrap::Init(Local<Object> exports) {
  Isolate* isolate = exports->GetIsolate();

  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
  tpl->SetClassName(String::NewFromUtf8(isolate, "ABPFilterParser"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);

  // Prototype
  NODE_SET_PROTOTYPE_METHOD(tpl, "parse", ABPFilterParserWrap::Parse);
  NODE_SET_PROTOTYPE_METHOD(tpl, "matches", ABPFilterParserWrap::Matches);
  NODE_SET_PROTOTYPE_METHOD(tpl, "serialize", ABPFilterParserWrap::Serialize);
  NODE_SET_PROTOTYPE_METHOD(tpl, "deserialize",
    ABPFilterParserWrap::Deserialize);
  NODE_SET_PROTOTYPE_METHOD(tpl, "cleanup", ABPFilterParserWrap::Cleanup);

  Local<Object> filterOptions = Object::New(isolate);
  filterOptions->Set(String::NewFromUtf8(isolate, "noFilterOption"),
    Int32::New(isolate, 0));
  filterOptions->Set(String::NewFromUtf8(isolate, "script"),
    Int32::New(isolate, 01));
  filterOptions->Set(String::NewFromUtf8(isolate, "image"),
    Int32::New(isolate, 02));
  filterOptions->Set(String::NewFromUtf8(isolate, "stylesheet"),
    Int32::New(isolate, 04));
  filterOptions->Set(String::NewFromUtf8(isolate, "object"),
    Int32::New(isolate, 010));
  filterOptions->Set(String::NewFromUtf8(isolate, "xmlHttpRequest"),
    Int32::New(isolate, 020));
  filterOptions->Set(String::NewFromUtf8(isolate, "objectSubrequest"),
    Int32::New(isolate, 040));
  filterOptions->Set(String::NewFromUtf8(isolate, "subdocument"),
    Int32::New(isolate, 0100));
  filterOptions->Set(String::NewFromUtf8(isolate, "document"),
    Int32::New(isolate, 0200));
  filterOptions->Set(String::NewFromUtf8(isolate, "other"),
    Int32::New(isolate, 0400));
  filterOptions->Set(String::NewFromUtf8(isolate, "xbl"),
    Int32::New(isolate, 01000));
  filterOptions->Set(String::NewFromUtf8(isolate, "collapse"),
    Int32::New(isolate, 02000));
  filterOptions->Set(String::NewFromUtf8(isolate, "doNotTrack"),
    Int32::New(isolate, 04000));
  filterOptions->Set(String::NewFromUtf8(isolate, "elemHide"),
    Int32::New(isolate, 010000));
  filterOptions->Set(String::NewFromUtf8(isolate, "thirdParty"),
    Int32::New(isolate, 020000));
  filterOptions->Set(String::NewFromUtf8(isolate, "notThirdParty"),
    Int32::New(isolate, 040000));

  constructor.Reset(isolate, tpl->GetFunction());
  exports->Set(String::NewFromUtf8(isolate, "ABPFilterParser"),
               tpl->GetFunction());
  exports->Set(String::NewFromUtf8(isolate, "FilterOptions"), filterOptions);
}
コード例 #7
0
ファイル: Bus.cpp プロジェクト: mexxik/node-gst
void Bus::Initialize(Local<Object> exports) {
    Isolate* isolate = exports->GetIsolate();

    Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
    tpl->InstanceTemplate()->SetInternalFieldCount(1);
    tpl->SetClassName(String::NewFromUtf8(isolate, "Bus"));

    NODE_SET_PROTOTYPE_METHOD(tpl, "watch", Watch);

    constructor.Reset(isolate, tpl->GetFunction());
    exports->Set(String::NewFromUtf8(isolate, "Bus"), tpl->GetFunction());
}
コード例 #8
0
void init( Local<Object> exports )
/********************************/
{
    uv_mutex_init(&api_mutex);
#if v012
    Isolate *isolate = Isolate::GetCurrent();
#else
    Isolate *isolate = exports->GetIsolate();
#endif
    StmtObject::Init( isolate );
    Connection::Init( isolate );
    NODE_SET_METHOD( exports, "createConnection", Connection::NewInstance );
}
コード例 #9
0
ファイル: EModuleHelper.cpp プロジェクト: ItsClemi/node-odbc
void EModuleHelper::InitializeModule( Local< Object > target )
{
	Isolate* isolate = target->GetIsolate( );
	HandleScope scope( isolate );

	NODE_SET_METHOD( target, "setWriteStreamInitializer", EModuleHelper::SetWriteStreamInitializer );
	NODE_SET_METHOD( target, "setReadStreamInitializer", EModuleHelper::SetReadStreamInitializer );
	NODE_SET_METHOD( target, "setPromiseInitializer", EModuleHelper::SetPromiseInitializer );

	NODE_SET_METHOD( target, "setLogHandler", EModuleHelper::SetLogHandler );

	NODE_SET_METHOD( target, "processNextChunk", EModuleHelper::ProcessNextChunk );
	NODE_SET_METHOD( target, "requestNextChunk", EModuleHelper::RequestNextChunk );
}
コード例 #10
0
ファイル: SAMPJS.cpp プロジェクト: damospiderman/samp.js
Local<Value> SAMPJS::ExecuteCode(Local<Context> context, string name, string code,int offset){
	Isolate *isolate = context->GetIsolate();
	Locker v8Locker(isolate);
	Isolate::Scope isolate_scope(isolate);
	HandleScope hs(isolate);
	EscapableHandleScope handle_scope(isolate);
	Local<Context> ctx = Local<Context>::New(isolate, context);
	Context::Scope context_scope(ctx);

	auto scriptname = String::NewFromUtf8(isolate, name.c_str());
	ScriptOrigin origin(scriptname, Integer::New(isolate,offset));

	
/*	if (strict){
		code = "\"use strict\"\r\n" + code;
	} */

	auto source = String::NewFromUtf8(isolate, code.c_str());


	TryCatch try_catch;
	
	
	auto script = v8::Script::Compile(source, &origin);



	if (script.IsEmpty()){
		isolate->CancelTerminateExecution();
		Utils::PrintException(&try_catch);
	}
	else {
		try_catch.Reset();
		Local<Value> result = script->Run();
		if (try_catch.HasCaught()){
			isolate->CancelTerminateExecution();
			Utils::PrintException(&try_catch);
			Local<Value> ret;
			return ret;
		}

		return handle_scope.Escape(result);
	}

	return Local<Value>();
}
コード例 #11
0
ファイル: addon.cpp プロジェクト: iamapinan/node-lws
void Main(Local<Object> exports)
{
    Isolate *isolate = exports->GetIsolate();
    Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, constructor);
    tpl->InstanceTemplate()->SetInternalFieldCount(1);

    NODE_SET_PROTOTYPE_METHOD(tpl, "on", on);
    NODE_SET_PROTOTYPE_METHOD(tpl, "send", send);
    NODE_SET_PROTOTYPE_METHOD(tpl, "setUserData", setUserData);
    NODE_SET_PROTOTYPE_METHOD(tpl, "getUserData", getUserData);
    NODE_SET_PROTOTYPE_METHOD(tpl, "getFd", getFd);

    exports->Set(String::NewFromUtf8(isolate, "Server"), tpl->GetFunction());

    Local<ObjectTemplate> socketTemplate = ObjectTemplate::New(isolate);
    socketTemplate->SetInternalFieldCount(2);
    persistentSocket.Reset(isolate, socketTemplate->NewInstance());
}
コード例 #12
0
ファイル: MySQL.cpp プロジェクト: steilman/samp.js
void MySQL::Init(Local<Context> ctx){
	num_conns = 0;

	isolate = ctx->GetIsolate();

	V8CONTEXT(isolate, ctx);
	context.Reset(isolate, ctx);

	ifstream mysqlFile("js/samp.js/MySQL.js", std::ios::in);
	if (!mysqlFile){
		sjs::logger::error("Missing required file MySQL.js");
		SAMPJS::Shutdown();
	}
	std::string mysqlSource((std::istreambuf_iterator<char>(mysqlFile)), std::istreambuf_iterator<char>());
	SAMPJS::ExecuteCode(ctx, "MySQL.js", mysqlSource);

	ifstream mysqlcFile("js/samp.js/MySQLConnection.js", std::ios::in);
	if (!mysqlcFile){
		sjs::logger::error("Missing required file MySQLConnection.js");
		SAMPJS::Shutdown();
	}
	std::string mysqlcSource((std::istreambuf_iterator<char>(mysqlcFile)), std::istreambuf_iterator<char>());
	SAMPJS::ExecuteCode(ctx, "MySQLConnection.js", mysqlcSource);

	SAMPJS::ExecuteCode(ctx, "$mysql", "var $mysql = new MySQL();");

	JS_Object global(ctx->Global());

	JS_Object mysql(global.getObject("$mysql"));

	auto mysql_tmpl = ObjectTemplate::New(isolate);
	mysql_tmpl->SetInternalFieldCount(1);
	auto mysqli = mysql_tmpl->NewInstance();
	mysqli->SetInternalField(0, External::New(isolate, this));

	JS_Object mysqlo(mysqli);

	mysqlo.Set("createConnection", JS_New);
	mysqlo.Set("escape", JS_Escape);

	mysql.Set("internal", mysqlo.get());

}
コード例 #13
0
ファイル: V8Runtime.cpp プロジェクト: ingo/titanium_mobile
/* static */
void V8Runtime::bootstrap(Local<Context> context)
{
	Isolate* isolate = context->GetIsolate();
	EventEmitter::initTemplate(context);

	Local<Object> global = Object::New(isolate);
	krollGlobalObject.Reset(isolate, global);
	Local<Array> mc = Array::New(isolate);
	moduleContexts.Reset(isolate, mc);

	KrollBindings::initFunctions(global, context);

	SetMethod(isolate, global, "log", krollLog);
	// Move this into the EventEmitter::initTemplate call?
	Local<FunctionTemplate> eect = Local<FunctionTemplate>::New(isolate, EventEmitter::constructorTemplate);
	global->Set(NEW_SYMBOL(isolate, "EventEmitter"), eect->GetFunction());

	global->Set(NEW_SYMBOL(isolate, "runtime"), STRING_NEW(isolate, "v8"));
	global->Set(NEW_SYMBOL(isolate, "DBG"), v8::Boolean::New(isolate, V8Runtime::DBG));
	global->Set(NEW_SYMBOL(isolate, "moduleContexts"), mc);

	LOG_TIMER(TAG, "Executing kroll.js");

	TryCatch tryCatch(isolate);
	Local<Value> result = V8Util::executeString(isolate, KrollBindings::getMainSource(isolate), STRING_NEW(isolate, "ti:/kroll.js"));

	if (tryCatch.HasCaught()) {
		V8Util::reportException(isolate, tryCatch, true);
	}
	if (!result->IsFunction()) {
		LOGF(TAG, "kroll.js result is not a function");
		V8Util::reportException(isolate, tryCatch, true);
	}

	Local<Function> mainFunction = result.As<Function>();
	Local<Value> args[] = { global };
	mainFunction->Call(context, context->Global(), 1, args);

	if (tryCatch.HasCaught()) {
		V8Util::reportException(isolate, tryCatch, true);
		LOGE(TAG, "Caught exception while bootstrapping Kroll");
	}
}
コード例 #14
0
ファイル: messagedlg.cpp プロジェクト: hgh086/iupNode
void IMessageDlg::Init(Local<Object> exports) {
	Isolate* isolate = exports->GetIsolate();
		
	// Prepare constructor template
	Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
	tpl->SetClassName(String::NewFromUtf8(isolate, "IMessageDlg"));
	tpl->InstanceTemplate()->SetInternalFieldCount(1);

	// Prototype
	NODE_SET_PROTOTYPE_METHOD(tpl, "init", _init);
	NODE_SET_PROTOTYPE_METHOD(tpl, "popup", _popup);
	NODE_SET_PROTOTYPE_METHOD(tpl, "getValue", _getValue);
	NODE_SET_PROTOTYPE_METHOD(tpl, "destroy", _destroy);
	
	NODE_SET_METHOD(tpl, "extend", extend);

	constructor.Reset(isolate, tpl->GetFunction());
	exports->Set(String::NewFromUtf8(isolate, "IMessageDlg"),tpl->GetFunction());
}
コード例 #15
0
ファイル: id_pool.cpp プロジェクト: d3lio/JSproj
    void IdPool::Init(Local<Object> exports)
    {
        Isolate* isolate = exports->GetIsolate();

        // Prepare constructor template
        Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
        tpl->SetClassName(String::NewFromUtf8(isolate, "IdPool"));
        tpl->InstanceTemplate()->SetInternalFieldCount(4);

        // Prototype
        NODE_SET_PROTOTYPE_METHOD(tpl, "reserve", reserve);
        NODE_SET_PROTOTYPE_METHOD(tpl, "release", release);
        NODE_SET_PROTOTYPE_METHOD(tpl, "clear", clear);
        NODE_SET_PROTOTYPE_METHOD(tpl, "has", has);
        NODE_SET_PROTOTYPE_METHOD(tpl, "size", size);
        NODE_SET_PROTOTYPE_METHOD(tpl, "length", length);

        constructor.Reset(isolate, tpl->GetFunction());
        exports->Set(String::NewFromUtf8(isolate, "IdPool"), tpl->GetFunction());
    }
コード例 #16
0
void APIModule::Initialize(Local<Object> target, Local<Context> context)
{
	Isolate* isolate = context->GetIsolate();
	HandleScope scope(isolate);
	Local<FunctionTemplate> constructor = FunctionTemplate::New(isolate);
	constructor->SetClassName(NEW_SYMBOL(isolate, "API"));
	constructorTemplate.Reset(isolate, constructor);

	// Hook methods to the API prototype, notice these aren't hooked to API
	// itself, instead we return a singleton of an API instance and export it
	// as Ti.API
	// Not sure why we then hook apiName as instance proprty, since
	// the difference is made moot by the singleton!
	SetProtoMethod(isolate, constructor, "debug", logDebug);
	SetProtoMethod(isolate, constructor, "info", logInfo);
	SetProtoMethod(isolate, constructor, "warn", logWarn);
	SetProtoMethod(isolate, constructor, "error", logError);
	SetProtoMethod(isolate, constructor, "trace", logTrace);
	SetProtoMethod(isolate, constructor, "notice", logNotice);
	SetProtoMethod(isolate, constructor, "critical", logCritical);
	SetProtoMethod(isolate, constructor, "fatal", logFatal);
	SetProtoMethod(isolate, constructor, "log", log);
	SetProtoMethod(isolate, constructor, "getApiName", APIModule::getApiName);

	// Add an "apiName" property to instances, which delegates to APIModule::getter_apiName
	// TODO Use a constant here?
	Local<ObjectTemplate> instanceTemplate = constructor->InstanceTemplate();
	instanceTemplate->SetAccessor(NEW_SYMBOL(isolate, "apiName"), APIModule::getter_apiName);

	// Expose a method for terminating the application for the debugger.
	// Debugger will send an evaluation request calling this method
	// when it wants the application to terminate immediately.
	if (V8Runtime::debuggerEnabled) {
		SetProtoMethod(isolate, constructor, "terminate", terminate);
		SetProtoMethod(isolate, constructor, "debugBreak", debugBreak);
	}
	// Make API extend from KrollModule
	constructor->Inherit(KrollModule::getProxyTemplate(isolate));
	// export an instance of API as "API" (basically make a static singleton)
	target->Set(NEW_SYMBOL(isolate, "API"), constructor->GetFunction(context).ToLocalChecked()->NewInstance(context).ToLocalChecked());
}
コード例 #17
0
ファイル: addon.cpp プロジェクト: cuongquay/uWebSockets
void Main(Local<Object> exports) {
    Isolate *isolate = exports->GetIsolate();
    Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, ::Server);
    tpl->InstanceTemplate()->SetInternalFieldCount(4);

    NODE_SET_PROTOTYPE_METHOD(tpl, "onConnection", onConnection);
    NODE_SET_PROTOTYPE_METHOD(tpl, "onMessage", onMessage);
    NODE_SET_PROTOTYPE_METHOD(tpl, "onDisconnection", onDisconnection);
    NODE_SET_PROTOTYPE_METHOD(tpl, "close", close);
    NODE_SET_PROTOTYPE_METHOD(tpl, "broadcast", broadcast);
    NODE_SET_PROTOTYPE_METHOD(tpl, "upgrade", upgrade);
    NODE_SET_PROTOTYPE_METHOD(tpl, "transfer", transfer);

    NODE_SET_PROTOTYPE_METHOD(tpl, "setData", setData);
    NODE_SET_PROTOTYPE_METHOD(tpl, "getData", getData);
    NODE_SET_PROTOTYPE_METHOD(tpl, "send", send);
    NODE_SET_PROTOTYPE_METHOD(tpl, "getAddress", getAddress);

    exports->Set(String::NewFromUtf8(isolate, "Server"), tpl->GetFunction());

    Local<ObjectTemplate> ticketTemplate = ObjectTemplate::New(isolate);
    ticketTemplate->SetInternalFieldCount(2);
    persistentTicket.Reset(isolate, ticketTemplate->NewInstance());
}
コード例 #18
0
void init(Local<Object> exports) {
  FMTuner::Init(exports->GetIsolate(), exports);
}
コード例 #19
0
ファイル: Delegates.cpp プロジェクト: Galvarezss/Unreal.js
	Local<Object> Initialize(Local<Context> context)
	{
		isolate_ = context->GetIsolate();
		context_.Reset(isolate_, context);

		auto out = Object::New(isolate_);

		auto add = [](const FunctionCallbackInfo<Value>& info) {
			for (;;)
			{
				auto payload = reinterpret_cast<FJavascriptDelegate*>(Local<External>::Cast(info.Data())->Value());
				if (info.Length() == 1)
				{
					auto func = Local<Function>::Cast(info[0]);
					if (!func.IsEmpty())
					{
						payload->Add(func);
						break;
					}
				}

				UE_LOG(Javascript, Log, TEXT("Invalid argument for delegate"));
				break;
			}
		};

		auto remove = [](const FunctionCallbackInfo<Value>& info) {
			for (;;)
			{
				auto payload = reinterpret_cast<FJavascriptDelegate*>(Local<External>::Cast(info.Data())->Value());
				if (info.Length() == 1)
				{
					auto func = Local<Function>::Cast(info[0]);
					if (!func.IsEmpty())
					{
						payload->Remove(func);
						break;
					}
				}

				UE_LOG(Javascript, Log, TEXT("Invalid argument for delegate"));
				break;
			}
		};

		auto clear = [](const FunctionCallbackInfo<Value>& info) {
			auto payload = reinterpret_cast<FJavascriptDelegate*>(Local<External>::Cast(info.Data())->Value());
			payload->Clear();			
		};

		auto toJSON = [](const FunctionCallbackInfo<Value>& info) {
			auto payload = reinterpret_cast<FJavascriptDelegate*>(Local<External>::Cast(info.Data())->Value());

			uint32_t Index = 0;			
			auto arr = Array::New(info.GetIsolate(), payload->DelegateObjects.Num());
			const bool bIsMulticastDelegate = payload->Property->IsA(UMulticastDelegateProperty::StaticClass());

			for (auto DelegateObject : payload->DelegateObjects)
			{
				auto JavascriptFunction = payload->functions.Find(DelegateObject->UniqueId);
				if (JavascriptFunction)
				{
					auto function = Local<Function>::New(info.GetIsolate(), *JavascriptFunction);
					if (!bIsMulticastDelegate)
					{
						info.GetReturnValue().Set(function);
						return;
					}
					
					arr->Set(Index++, function);
				}
			}

			if (!bIsMulticastDelegate)
			{
				info.GetReturnValue().Set(Null(info.GetIsolate()));
			}
			else
			{
				info.GetReturnValue().Set(arr);
			}			
		};

		auto data = External::New(isolate_, this);

		out->Set(V8_KeywordString(isolate_, "Add"), Function::New(isolate_, add, data));
		out->Set(V8_KeywordString(isolate_, "Remove"), Function::New(isolate_, remove, data));
		out->Set(V8_KeywordString(isolate_, "Clear"), Function::New(isolate_, clear, data));
		out->Set(V8_KeywordString(isolate_, "toJSON"), Function::New(isolate_, toJSON, data));

		WrappedObject.Reset(isolate_, out);

		return out;
	}