Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: jni/JniJsValue.cpp

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jni/JniJsValue.h ('k') | jni/JniLogSystem.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 }
};
« no previous file with comments | « jni/JniJsValue.h ('k') | jni/JniLogSystem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld