| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of the Adblock Plus, | 2 * This file is part of the Adblock Plus, |
| 3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include <math.h> | 18 #include <math.h> |
| 19 #include <android/log.h> | 19 #include <android/log.h> |
| 20 #include <jni.h> | 20 #include <jni.h> |
| 21 #include <v8.h> | 21 #include <v8.h> |
| 22 | 22 |
| 23 jobject NewBoolean(JNIEnv *pEnv, jboolean value) | 23 jobject NewBoolean(JNIEnv *pEnv, jboolean value) |
| 24 { | 24 { |
| 25 static jclass cls = pEnv->FindClass("java/lang/Boolean"); | 25 static jclass cls = reinterpret_cast<jclass>(pEnv->NewGlobalRef(pEnv->FindClas
s("java/lang/Boolean"))); |
| 26 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(Z)V"); | 26 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(Z)V"); |
| 27 return pEnv->NewObject(cls, cid, value); | 27 return pEnv->NewObject(cls, cid, value); |
| 28 } | 28 } |
| 29 | 29 |
| 30 jobject NewInt(JNIEnv *pEnv, jint value) | 30 jobject NewInt(JNIEnv *pEnv, jint value) |
| 31 { | 31 { |
| 32 static jclass cls = pEnv->FindClass("java/lang/Integer"); | 32 static jclass cls = reinterpret_cast<jclass>(pEnv->NewGlobalRef(pEnv->FindClas
s("java/lang/Integer"))); |
| 33 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(I)V"); | 33 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(I)V"); |
| 34 return pEnv->NewObject(cls, cid, value); | 34 return pEnv->NewObject(cls, cid, value); |
| 35 } | 35 } |
| 36 | 36 |
| 37 jobject NewLong(JNIEnv *pEnv, jlong value) | 37 jobject NewLong(JNIEnv *pEnv, jlong value) |
| 38 { | 38 { |
| 39 static jclass cls = pEnv->FindClass("java/lang/Long"); | 39 static jclass cls = reinterpret_cast<jclass>(pEnv->NewGlobalRef(pEnv->FindClas
s("java/lang/Long"))); |
| 40 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(J)V"); | 40 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(J)V"); |
| 41 return pEnv->NewObject(cls, cid, value); | 41 return pEnv->NewObject(cls, cid, value); |
| 42 } | 42 } |
| 43 | 43 |
| 44 jobject NewDouble(JNIEnv *pEnv, jdouble value) | 44 jobject NewDouble(JNIEnv *pEnv, jdouble value) |
| 45 { | 45 { |
| 46 static jclass cls = pEnv->FindClass("java/lang/Double"); | 46 static jclass cls = reinterpret_cast<jclass>(pEnv->NewGlobalRef(pEnv->FindClas
s("java/lang/Double"))); |
| 47 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(D)V"); | 47 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(D)V"); |
| 48 return pEnv->NewObject(cls, cid, value); | 48 return pEnv->NewObject(cls, cid, value); |
| 49 } | 49 } |
| 50 | 50 |
| 51 jstring NewString(JNIEnv *pEnv, v8::Handle<v8::String> str) | 51 jstring NewString(JNIEnv *pEnv, v8::Handle<v8::String> str) |
| 52 { | 52 { |
| 53 return pEnv->NewStringUTF(*v8::String::Utf8Value(str)); | 53 return pEnv->NewStringUTF(*v8::String::Utf8Value(str)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 jobject NewDate(JNIEnv *pEnv, v8::Handle<v8::Date> date) | 56 jobject NewDate(JNIEnv *pEnv, v8::Handle<v8::Date> date) |
| 57 { | 57 { |
| 58 static jclass cls = pEnv->FindClass("java/lang/Double"); | 58 static jclass cls = reinterpret_cast<jclass>(pEnv->NewGlobalRef(pEnv->FindClas
s("java/lang/Double"))); |
| 59 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(J)V"); | 59 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "(J)V"); |
| 60 jlong value = floor(date->NumberValue()); | 60 jlong value = floor(date->NumberValue()); |
| 61 return pEnv->NewObject(cls, cid, value); | 61 return pEnv->NewObject(cls, cid, value); |
| 62 } | 62 } |
| 63 | 63 |
| 64 jobject wrapJSObject(JNIEnv *pEnv, v8::Handle<v8::Value> value) | 64 jobject wrapJSObject(JNIEnv *pEnv, v8::Handle<v8::Value> value) |
| 65 { | 65 { |
| 66 v8::HandleScope handle_scope; | 66 v8::HandleScope handle_scope; |
| 67 | 67 |
| 68 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) return NULL; | 68 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) return NULL; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 pEnv->DeleteLocalRef(item); | 150 pEnv->DeleteLocalRef(item); |
| 151 } | 151 } |
| 152 | 152 |
| 153 result = items; | 153 result = items; |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 return try_catch.HasCaught() ? v8::Handle<v8::Value>() : handle_scope.Close(re
sult); | 157 return try_catch.HasCaught() ? v8::Handle<v8::Value>() : handle_scope.Close(re
sult); |
| 158 // return ThrowIf(try_catch) ? v8::Handle<v8::Value>() : handle_scope.Close(res
ult); | 158 // return ThrowIf(try_catch) ? v8::Handle<v8::Value>() : handle_scope.Close(res
ult); |
| 159 } | 159 } |
| LEFT | RIGHT |