当前位置: 首页>>代码示例>>C++>>正文


C++ JEnv::DeleteLocalRef方法代码示例

本文整理汇总了C++中JEnv::DeleteLocalRef方法的典型用法代码示例。如果您正苦于以下问题:C++ JEnv::DeleteLocalRef方法的具体用法?C++ JEnv::DeleteLocalRef怎么用?C++ JEnv::DeleteLocalRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JEnv的用法示例。


在下文中一共展示了JEnv::DeleteLocalRef方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

JniLocalRef::~JniLocalRef()
{
	if ((m_obj != nullptr) && !m_isWeak)
	{
		JEnv env;
		env.DeleteLocalRef(m_obj);
	}
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:8,代码来源:JniLocalRef.cpp

示例2:

JsArgToArrayConverter::~JsArgToArrayConverter()
{
	if (m_argsLen > 0)
	{
		JEnv env;

		int length = m_storedIndexes.size();
		for (int i = 0; i < length; i++)
		{
			int index = m_storedIndexes[i];
			env.DeleteLocalRef(m_argsAsObject[index]);
		}

		delete[] m_argsAsObject;
	}
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:16,代码来源:JsArgToArrayConverter.cpp

示例3: GetMethodOverrides

//delete the returned local reference after use
jobjectArray NativeScriptRuntime::GetMethodOverrides(JEnv& env, const Local<Object>& implementationObject)
{
	if (implementationObject.IsEmpty())
	{
		return JavaObjectArrayCache::GetJavaStringArray(0);
	}

	vector<jstring> methodNames;
	auto propNames = implementationObject->GetOwnPropertyNames();
	for (int i = 0; i < propNames->Length(); i++)
	{
		auto name = propNames->Get(i).As<String>();
		auto method = implementationObject->Get(name);

		bool methodFound = !method.IsEmpty() && method->IsFunction();

		if (methodFound)
		{
			String::Utf8Value stringValue(name);
			jstring value = env.NewStringUTF(*stringValue);
			methodNames.push_back(value);
		}
	}

	int methodCount = methodNames.size();

	jobjectArray methodOverrides = JavaObjectArrayCache::GetJavaStringArray(methodCount);
	for (int i = 0; i < methodCount; i++)
	{
		env.SetObjectArrayElement(methodOverrides, i, methodNames[i]);
	}

	for (int i = 0; i < methodCount; i++)
	{
		env.DeleteLocalRef(methodNames[i]);
	}

	return methodOverrides;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:40,代码来源:NativeScriptRuntime.cpp

示例4: name

Handle<Object> NativeScriptRuntime::FindClass(const string& className)
{
	Handle<Object> clazz;
	JEnv env;

	jmethodID mid = env.GetStaticMethodID(PlatformClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
	assert(mid != nullptr);
	JniLocalRef name(env.NewStringUTF(className.c_str()));
	jclass c = (jclass)env.CallStaticObjectMethod(PlatformClass, mid, (jstring)name);
	if (env.ExceptionCheck() == JNI_FALSE)
	{
		jint javaObjectID = objectManager->GetOrCreateObjectId(c);
		clazz = objectManager->GetJsObjectByJavaObject(javaObjectID);

		if (clazz.IsEmpty())
		{
			clazz = objectManager->CreateJSWrapper(javaObjectID, "Ljava/lang/Class;", c);
		}

		env.DeleteLocalRef(c);
	}
	return clazz;
}
开发者ID:bootstraponline,项目名称:android-runtime,代码行数:23,代码来源:NativeScriptRuntime.cpp

示例5: handleScope


//.........这里部分代码省略.........
				{
					result = env.GetIntField(targetJavaObject, fieldId);
				}
				fieldResult = handleScope.Escape(Int32::New(isolate, result));
				break;

			}
			case 'J': //long
			{
				jlong result;
				if (isStatic)
				{
					result = env.GetStaticLongField(clazz, fieldId);
				}
				else
				{
					result = env.GetLongField(targetJavaObject, fieldId);
				}
				fieldResult = handleScope.Escape(ArgConverter::ConvertFromJavaLong(isolate, result));
				break;
			}
			case 'F': //float
			{
				jfloat result;
				if (isStatic)
				{
					result = env.GetStaticFloatField(clazz, fieldId);
				}
				else
				{
					result = env.GetFloatField(targetJavaObject, fieldId);
				}
				fieldResult = handleScope.Escape(Number::New(isolate, (double) result));
				break;
			}
			case 'D': //double
			{
				jdouble result;
				if (isStatic)
				{
					result = env.GetStaticDoubleField(clazz, fieldId);
				}
				else
				{
					result = env.GetDoubleField(targetJavaObject, fieldId);
				}
				fieldResult = handleScope.Escape(Number::New(isolate, result));
				break;
			}
			default:
				{
					stringstream ss;
					ss << "(InternalError): in FieldAccessor::GetJavaField: Unknown field type: '" << fieldTypeName[0] << "'";
					throw NativeScriptException(ss.str());
			}
		}
	}
	else
	{
		jobject result;

		if (isStatic)
		{
			result = env.GetStaticObjectField(clazz, fieldId);
		}
		else
		{
			result = env.GetObjectField(targetJavaObject, fieldId);
		}

		if (result != nullptr)
		{

			bool isString = fieldTypeName == "java/lang/String";
			if (isString)
			{
				auto resultV8Value = ArgConverter::jstringToV8String((jstring) result);
				fieldResult = handleScope.Escape(resultV8Value);
			}
			else
			{
				int javaObjectID = objectManager->GetOrCreateObjectId(result);
				auto objectResult = objectManager->GetJsObjectByJavaObject(javaObjectID);

				if (objectResult.IsEmpty())
				{
					objectResult = objectManager->CreateJSWrapper(javaObjectID, fieldTypeName, result);
				}

				fieldResult = handleScope.Escape(objectResult);
			}
			env.DeleteLocalRef(result);
		}
		else
		{
			fieldResult = handleScope.Escape(Null(isolate));
		}
	}
	return fieldResult;
}
开发者ID:Emat12,项目名称:android-runtime,代码行数:101,代码来源:FieldAccessor.cpp

示例6: SetJavaField


//.........这里部分代码省略.........
					env.SetStaticShortField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetShortField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;
			}
			case 'I': //int
			{
				//TODO: validate value is a int before calling
				if (isStatic)
				{
					env.SetStaticIntField(clazz, fieldId, value->Int32Value());
				}
				else
				{
					env.SetIntField(targetJavaObject, fieldId, value->Int32Value());
				}
				break;

			}
			case 'J': //long
			{
				jlong longValue = static_cast<jlong>(ArgConverter::ConvertToJavaLong(value));
				if (isStatic)
				{
					env.SetStaticLongField(clazz, fieldId, longValue);
				}
				else
				{
					env.SetLongField(targetJavaObject, fieldId, longValue);
				}
				break;
			}
			case 'F': //float
			{
				if (isStatic)
				{
					env.SetStaticFloatField(clazz, fieldId, static_cast<jfloat>(value->NumberValue()));
				}
				else
				{
					env.SetFloatField(targetJavaObject, fieldId, static_cast<jfloat>(value->NumberValue()));
				}
				break;
			}
			case 'D': //double
			{
				if (isStatic)
				{
					env.SetStaticDoubleField(clazz, fieldId, value->NumberValue());
				}
				else
				{
					env.SetDoubleField(targetJavaObject, fieldId, value->NumberValue());
				}
				break;
			}
			default:
			{
				// TODO:
				ASSERT_FAIL("Unknown field type");
				break;
			}
		}
	}
	else
	{
		bool isString = fieldTypeName == "java/lang/String";
		jobject result = nullptr;

		if(!value->IsNull()) {
			if (isString)
			{
				//TODO: validate valie is a string;
				result = ConvertToJavaString(value);
			}
			else
			{
				auto objectWithHiddenID = value->ToObject();
				result =objectManager->GetJavaObjectByJsObject(objectWithHiddenID);
			}
		}

		if (isStatic)
		{
			env.SetStaticObjectField(clazz, fieldId, result);
		}
		else
		{
			env.SetObjectField(targetJavaObject, fieldId, result);
		}

		if (isString)
		{
			env.DeleteLocalRef(result);
		}
	}
}
开发者ID:nathanfaucett,项目名称:android-runtime,代码行数:101,代码来源:FieldAccessor.cpp

示例7: handleScope

Local<Value> ArrayElementAccessor::GetArrayElement(const Local<Object>& array, uint32_t index, const string& arraySignature)
{
	JEnv env;

	Isolate* isolate = Isolate::GetCurrent();
	EscapableHandleScope handleScope(isolate);

	jweak arr = objectManager->GetJavaObjectByJsObject(array);

	Local<Value> value;
	jsize startIndex = index;
	const jsize length = 1;

	const string elementSignature = arraySignature.substr(1);
	jboolean isCopy = false;

	if (elementSignature == "Z")
	{
		jbooleanArray boolArr = reinterpret_cast<jbooleanArray>(arr);
		jboolean boolArrValue;
		env.GetBooleanArrayRegion(boolArr, startIndex, length, &boolArrValue);
		value = ConvertToJsValue(env, elementSignature, &boolArrValue);
	}
	else if (elementSignature == "B")
	{
		jbyteArray byteArr = reinterpret_cast<jbyteArray>(arr);
		jbyte byteArrValue;
		env.GetByteArrayRegion(byteArr, startIndex, length, &byteArrValue);
		value = ConvertToJsValue(env, elementSignature, &byteArrValue);
	}
	else if (elementSignature == "C")
	{
		jcharArray charArr = reinterpret_cast<jcharArray>(arr);
		jchar charArrValue;
		env.GetCharArrayRegion(charArr, startIndex, length, &charArrValue);
		JniLocalRef s(env.NewString(&charArrValue, 1));
		const char* singleChar = env.GetStringUTFChars(s, &isCopy);
		value = ConvertToJsValue(env, elementSignature, singleChar);
		env.ReleaseStringUTFChars(s, singleChar);
	}
	else if (elementSignature == "S")
	{
		jshortArray shortArr = reinterpret_cast<jshortArray>(arr);
		jshort shortArrValue;
		env.GetShortArrayRegion(shortArr, startIndex, length, &shortArrValue);
		value = ConvertToJsValue(env, elementSignature, &shortArrValue);
	}
	else if (elementSignature == "I")
	{
		jintArray intArr = reinterpret_cast<jintArray>(arr);
		jint intArrValue;
		env.GetIntArrayRegion(intArr, startIndex, length, &intArrValue);
		value = ConvertToJsValue(env, elementSignature, &intArrValue);
	}
	else if (elementSignature == "J")
	{
		jlongArray longArr = reinterpret_cast<jlongArray>(arr);
		jlong longArrValue;
		env.GetLongArrayRegion(longArr, startIndex, length, &longArrValue);
		value = ConvertToJsValue(env, elementSignature, &longArrValue);
	}
	else if (elementSignature == "F")
	{
		jfloatArray floatArr = reinterpret_cast<jfloatArray>(arr);
		jfloat floatArrValue;
		env.GetFloatArrayRegion(floatArr, startIndex, length, &floatArrValue);
		value = ConvertToJsValue(env, elementSignature, &floatArrValue);
	}
	else if (elementSignature == "D")
	{
		jdoubleArray doubleArr = reinterpret_cast<jdoubleArray>(arr);
		jdouble doubleArrValue;
		env.GetDoubleArrayRegion(doubleArr, startIndex, length, &doubleArrValue);
		value = ConvertToJsValue(env, elementSignature, &doubleArrValue);
	}
	else
	{
		jobject result = env.GetObjectArrayElement(reinterpret_cast<jobjectArray>(arr), index);
		value = ConvertToJsValue(env, elementSignature, &result);
		env.DeleteLocalRef(result);
	}

	return handleScope.Escape(value);
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:84,代码来源:ArrayElementAccessor.cpp

示例8: CallJavaMethod


//.........这里部分代码省略.........
			else if (isSuper)
			{
				result = env.CallNonvirtualDoubleMethodA(callerJavaObject, clazz, mid, javaArgs);
			}
			else
			{
				result = env.CallDoubleMethodA(callerJavaObject, mid, javaArgs);
			}
			args.GetReturnValue().Set(result);
			break;
		}
		case MethodReturnType::String:
		{
			jobject result = nullptr;
			bool exceptionOccurred;

			if (isStatic)
			{
				result = env.CallStaticObjectMethodA(clazz, mid, javaArgs);
			}
			else if (isSuper)
			{
				result = env.CallNonvirtualObjectMethodA(callerJavaObject, clazz, mid, javaArgs);
			}
			else
			{
				result = env.CallObjectMethodA(callerJavaObject, mid, javaArgs);
			}

			if (result != nullptr)
			{
				auto objectResult = ArgConverter::jstringToV8String(static_cast<jstring>(result));
				args.GetReturnValue().Set(objectResult);
				env.DeleteLocalRef(result);
			}
			else
			{
				args.GetReturnValue().Set(Null(isolate));
			}

			break;
		}
		case MethodReturnType::Object:
		{
			jobject result = nullptr;
			bool exceptionOccurred;

			if (isStatic)
			{
				result = env.CallStaticObjectMethodA(clazz, mid, javaArgs);
			}
			else if (isSuper)
			{
				result = env.CallNonvirtualObjectMethodA(callerJavaObject, clazz, mid, javaArgs);
			}
			else
			{
				result = env.CallObjectMethodA(callerJavaObject, mid, javaArgs);
			}

			if (result != nullptr)
			{
				auto isString = env.IsInstanceOf(result, JAVA_LANG_STRING);

				Local<Value> objectResult;
				if (isString)
开发者ID:slavchev,项目名称:android-runtime,代码行数:67,代码来源:NativeScriptRuntime.cpp

示例9: CallJavaMethod


//.........这里部分代码省略.........
		}
		case '[':
		case 'L':
		{
			bool isString = returnType == "Ljava/lang/String;";

			jobject result = nullptr;
			bool exceptionOccurred;

			if (isString)
			{
				if (isStatic)
				{
					result = env.CallStaticObjectMethodA(clazz, mid, javaArgs);
				}
				else if (isSuper)
				{
					result = env.CallNonvirtualObjectMethodA(callerJavaObject, clazz, mid, javaArgs);
				}
				else
				{
					result = env.CallObjectMethodA(callerJavaObject, mid, javaArgs);
				}

				exceptionOccurred = env.ExceptionCheck() == JNI_TRUE;

				if (!exceptionOccurred)
				{
					auto resultV8String = ArgConverter::jstringToV8String((jstring) result);
					args.GetReturnValue().Set(resultV8String);
				}
			}
			else
			{
				if (isStatic)
				{
					result = env.CallStaticObjectMethodA(clazz, mid, javaArgs);
				}
				else if (isSuper)
				{
					result = env.CallNonvirtualObjectMethodA(callerJavaObject, clazz, mid, javaArgs);
				}
				else
				{
					result = env.CallObjectMethodA(callerJavaObject, mid, javaArgs);
				}

				exceptionOccurred = env.ExceptionCheck() == JNI_TRUE;

				if (!exceptionOccurred)
				{
					if (result != nullptr)
					{
						isString = env.IsInstanceOf(result, JAVA_LANG_STRING);

						Handle<Value> objectResult;
						if (isString)
						{
							objectResult = ArgConverter::jstringToV8String((jstring)result);
						}
						else
						{
							jint javaObjectID = objectManager->GetOrCreateObjectId(result);
							objectResult = objectManager->GetJsObjectByJavaObject(javaObjectID);

							if (objectResult.IsEmpty())
							{
								objectResult = objectManager->CreateJSWrapper(javaObjectID, returnType, result);
							}
						}

						args.GetReturnValue().Set(objectResult);
					}
					else
					{
						args.GetReturnValue().Set(Null(isolate));
					}
				}
			}

			if (!exceptionOccurred)
			{
				env.DeleteLocalRef(result);
			}

			break;
		}
		default:
		{
			// TODO:
			ASSERT_FAIL("Unknown return type");
			break;
		}
	}

	if (!ExceptionUtil::GetInstance()->CheckForJavaException(env))
	{
		AdjustAmountOfExternalAllocatedMemory(env, isolate);
	}
}
开发者ID:bootstraponline,项目名称:android-runtime,代码行数:101,代码来源:NativeScriptRuntime.cpp


注:本文中的JEnv::DeleteLocalRef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。