Exemple #1
0
/*
 * if type == -1, change the target of the handle, otherwise allocate a new handle.
 */
guint32
ves_icall_System_GCHandle_GetTargetHandle (MonoObject *obj, guint32 handle, gint32 type)
{
	if (type == -1) {
		mono_gchandle_set_target (handle, obj);
		/* the handle doesn't change */
		return handle;
	}
	switch (type) {
	case HANDLE_WEAK:
		return mono_gchandle_new_weakref (obj, FALSE);
	case HANDLE_WEAK_TRACK:
		return mono_gchandle_new_weakref (obj, TRUE);
	case HANDLE_NORMAL:
		return mono_gchandle_new (obj, FALSE);
	case HANDLE_PINNED:
		return mono_gchandle_new (obj, TRUE);
	default:
		g_assert_not_reached ();
	}
	return 0;
}
Exemple #2
0
NodejsFunc::NodejsFunc(Handle<Function> function)
{
    DBG("NodejsFunc::NodejsFunc");

    static MonoMethod* ctor;
    if (!ctor)
        ctor = mono_class_get_method_from_name(GetNodejsFuncClass(), ".ctor", -1);

    this->Func = new Persistent<Function>;
    NanAssignPersistent(*(this->Func), function);

    MonoObject* thisObj = mono_object_new(mono_domain_get(), GetNodejsFuncClass());
    MonoException* exc = NULL;
    void *thisPtr = this;
    void *args[] = { &thisPtr };
    mono_runtime_invoke(ctor, thisObj, args, (MonoObject**)&exc);
    _this = mono_gchandle_new_weakref(thisObj, FALSE);
}
Exemple #3
0
MonoObject* DOMBase::GetJSWrapper() 
{	
	if (_JSWrapperWPtr != 0)
	{
		//printf ("%s:%d %s() Mono calling C code\n", __FILE__, __LINE__, __FUNCTION__);
		MonoObject* domwrapper = mono_gchandle_get_target(_JSWrapperWPtr);
		if (!domwrapper)
			FatalError("Cannot find the JS Wrapper object through the weak refrence");
		return domwrapper;
	}
	else
	{
		//printf ("%s:%d %s() Mono calling C code\n", __FILE__, __LINE__, __FUNCTION__);	
		MonoObject* wrapperObject = MakeWrapper(this, GetMakeWrapperIndex());
		_JSWrapperWPtr = mono_gchandle_new_weakref(wrapperObject, false);
		return wrapperObject;
	}
}