| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 { | 140 { |
| 141 return JniGetJsValuePtr(ptr)->AsBool() ? JNI_TRUE : JNI_FALSE; | 141 return JniGetJsValuePtr(ptr)->AsBool() ? JNI_TRUE : JNI_FALSE; |
| 142 } | 142 } |
| 143 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | 143 CATCH_THROW_AND_RETURN(env, JNI_FALSE) |
| 144 } | 144 } |
| 145 | 145 |
| 146 static jobject JNICALL JniAsList(JNIEnv* env, jclass clazz, jlong ptr) | 146 static jobject JNICALL JniAsList(JNIEnv* env, jclass clazz, jlong ptr) |
| 147 { | 147 { |
| 148 try | 148 try |
| 149 { | 149 { |
| 150 AdblockPlus::JsValueList list = JniGetJsValuePtr(ptr)->AsList(); | 150 return JniJsValueListToArrayList(env, JniGetJsValuePtr(ptr)->AsList()); |
| 151 | |
| 152 return JniJsValueListToArrayList(env, list); | |
| 153 } | 151 } |
| 154 CATCH_THROW_AND_RETURN(env, 0) | 152 CATCH_THROW_AND_RETURN(env, 0) |
| 155 } | 153 } |
| 156 | 154 |
| 157 static jobject JNICALL JniGetProperty(JNIEnv* env, jclass clazz, jlong ptr, jstr
ing name) | 155 static jobject JNICALL JniGetProperty(JNIEnv* env, jclass clazz, jlong ptr, jstr
ing name) |
| 158 { | 156 { |
| 159 try | 157 try |
| 160 { | 158 { |
| 161 return NewJniJsValue(env, JniGetJsValuePtr(ptr)->GetProperty(JniJavaToStdStr
ing(env, name))); | 159 return NewJniJsValue(env, JniGetJsValuePtr(ptr)->GetProperty(JniJavaToStdStr
ing(env, name))); |
| 162 } | 160 } |
| 163 CATCH_THROW_AND_RETURN(env, 0) | 161 CATCH_THROW_AND_RETURN(env, 0) |
| 164 } | 162 } |
| 165 | 163 |
| 166 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | 164 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
| 167 { | 165 { |
| 168 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr); | 166 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr); |
| 169 } | 167 } |
| 170 | 168 |
| 171 jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValue& jsValue, jclass j
sValueClassArg) | 169 jobject NewJniJsValue(JNIEnv* env, AdblockPlus::JsValue&& jsValue, jclass jsValu
eClassArg) |
| 172 { | 170 { |
| 173 return env->NewObject(jsValueClass->Get(), jsValueCtor, new AdblockPlus::JsVal
ue(std::move(jsValue))); | 171 return env->NewObject(jsValueClass->Get(), jsValueCtor, new AdblockPlus::JsVal
ue(std::move(jsValue))); |
| 174 } | 172 } |
| 175 | 173 |
| 176 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr) | 174 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr) |
| 177 { | 175 { |
| 178 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr); | 176 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr); |
| 179 } | 177 } |
| 180 | 178 |
| 181 AdblockPlus::JsValue& JniGetJsValue(jlong ptr) | 179 AdblockPlus::JsValue& JniGetJsValue(jlong ptr) |
| 182 { | 180 { |
| 183 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr); | 181 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr); |
| 184 } | 182 } |
| 185 | 183 |
| 186 jobject JniJsValueListToArrayList(JNIEnv* env, const AdblockPlus::JsValueList& l
ist) | 184 jobject JniJsValueListToArrayList(JNIEnv* env, AdblockPlus::JsValueList&& list) |
| 187 { | 185 { |
| 188 jobject arrayList = NewJniArrayList(env); | 186 jobject arrayList = NewJniArrayList(env); |
| 189 | 187 |
| 190 for (AdblockPlus::JsValueList::const_iterator it = list.begin(), end = list.en
d(); it != end; ++it) | 188 for (AdblockPlus::JsValueList::iterator it = list.begin(), end = list.end(); i
t != end; ++it) |
| 191 { | 189 { |
| 192 JniAddObjectToList(env, arrayList, *JniLocalReference<jobject>(env, NewJniJs
Value(env, *it))); | 190 JniAddObjectToList(env, arrayList, *JniLocalReference<jobject>(env, NewJniJs
Value(env, std::move(*it)))); |
| 193 } | 191 } |
| 194 | 192 |
| 195 return arrayList; | 193 return arrayList; |
| 196 } | 194 } |
| 197 | 195 |
| 198 // TODO: List of functions that lack JNI bindings | 196 // TODO: List of functions that lack JNI bindings |
| 199 //std::vector<std::string> GetOwnPropertyNames() const; | 197 //std::vector<std::string> GetOwnPropertyNames() const; |
| 200 //void SetProperty(const std::string& name, const std::string& val); | 198 //void SetProperty(const std::string& name, const std::string& val); |
| 201 //void SetProperty(const std::string& name, int64_t val); | 199 //void SetProperty(const std::string& name, int64_t val); |
| 202 //void SetProperty(const std::string& name, bool val); | 200 //void SetProperty(const std::string& name, bool val); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 221 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, | 219 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, |
| 222 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, | 220 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, |
| 223 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)
JniGetProperty }, | 221 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)
JniGetProperty }, |
| 224 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 222 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
| 225 }; | 223 }; |
| 226 | 224 |
| 227 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re
gisterNatives(JNIEnv *env, jclass clazz) | 225 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re
gisterNatives(JNIEnv *env, jclass clazz) |
| 228 { | 226 { |
| 229 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 227 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 230 } | 228 } |
| LEFT | RIGHT |