Index: jni/JniJsValue.cpp |
diff --git a/jni/JniJsValue.cpp b/jni/JniJsValue.cpp |
index a3f6e04d377e6da39210df4ae4d83e8ea9b4a4f4..1fd101dbccab1d585d5a2fe755a383d0de0db95f 100644 |
--- a/jni/JniJsValue.cpp |
+++ b/jni/JniJsValue.cpp |
@@ -109,11 +109,6 @@ static jboolean JNICALL JniAsBoolean(JNIEnv* env, jclass clazz, jlong ptr) |
CATCH_THROW_AND_RETURN(env, JNI_FALSE) |
} |
-static jboolean JNICALL JniIsValid(JNIEnv* env, jclass clazz, jlong ptr) |
-{ |
- return JniGetJsValue(ptr) ? JNI_TRUE : JNI_FALSE; |
-} |
- |
static jobject JNICALL JniAsList(JNIEnv* env, jclass clazz, jlong ptr) |
{ |
try |
@@ -125,14 +120,28 @@ static jobject JNICALL JniAsList(JNIEnv* env, jclass clazz, jlong ptr) |
CATCH_THROW_AND_RETURN(env, 0) |
} |
+static jobject JNICALL JniGetProperty(JNIEnv* env, jclass clazz, jlong ptr, jstring name) |
+{ |
+ try |
+ { |
+ return NewJniJsValue(env, JniGetJsValue(ptr)->GetProperty(JniJavaToStdString(env, name))); |
+ } |
+ CATCH_THROW_AND_RETURN(env, 0) |
+} |
+ |
static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
{ |
delete JniLongToTypePtr<AdblockPlus::JsValuePtr>(ptr); |
} |
-jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValuePtr& jsValue) |
+jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValuePtr& jsValue, jclass jsValueClass) |
{ |
- jclass clazz = env->FindClass(PKG("JsValue")); |
+ if (!jsValue.get()) |
+ { |
+ return 0; |
+ } |
+ |
+ jclass clazz = jsValueClass ? jsValueClass : env->FindClass(PKG("JsValue")); |
jmethodID ctor = env->GetMethodID(clazz, "<init>", "(J)V"); |
jlong ptr = JniPtrToLong(new AdblockPlus::JsValuePtr(jsValue)); |
return env->NewObject(clazz, ctor, ptr); |
@@ -162,7 +171,6 @@ jobject JniJsValueListToArrayList(JNIEnv* env, AdblockPlus::JsValueList& list) |
// TODO: List of functions that lack JNI bindings |
//std::vector<std::string> GetOwnPropertyNames() const; |
-//JsValuePtr GetProperty(const std::string& name) const; |
//void SetProperty(const std::string& name, const std::string& val); |
//void SetProperty(const std::string& name, int64_t val); |
//void SetProperty(const std::string& name, bool val); |
@@ -185,7 +193,7 @@ static JNINativeMethod methods[] = |
{ (char*)"asLong", (char*)"(J)J", (void*)JniAsLong }, |
{ (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, |
{ (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, |
- { (char*)"isValid", (char*)"(J)Z", (void*)JniIsValid }, |
+ { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniGetProperty }, |
{ (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
}; |