Index: libadblockplus-android/jni/JniPlatform.cpp |
diff --git a/libadblockplus-android/jni/JniPlatform.cpp b/libadblockplus-android/jni/JniPlatform.cpp |
index 5e067088bca47d2d487fea3fbb728260a6dd696c..e27216536ee3149475190d6d14ccd23c8b0ad6e7 100644 |
--- a/libadblockplus-android/jni/JniPlatform.cpp |
+++ b/libadblockplus-android/jni/JniPlatform.cpp |
@@ -20,6 +20,33 @@ |
#include "JniCallbacks.h" |
#include "JniPlatform.h" |
+/** |
+ * V8IsolateHolder accepts v8:::Isolate ptr in ctor and just returns it in Get(). |
+ * V8IsolateHolder is not taking ownership so it's not releasing isolate ptr. |
+ */ |
+class V8IsolateHolder : public AdblockPlus::IV8IsolateProvider |
+{ |
+ public: |
+ V8IsolateHolder(v8::Isolate* isolate_) : isolate(isolate_) |
+ { |
+ } |
+ |
+ ~V8IsolateHolder() |
sergei
2017/09/26 09:44:13
I would propose to remove the destructor here.
anton
2017/09/26 10:55:06
Acknowledged.
|
+ { |
+ isolate = nullptr; |
+ } |
+ |
+ v8::Isolate* Get() override |
+ { |
+ return isolate; |
+ } |
+ |
+ private: |
+ V8IsolateHolder(const V8IsolateHolder&); |
+ V8IsolateHolder& operator=(const V8IsolateHolder&); |
+ |
+ v8::Isolate* isolate; |
+}; |
static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo& appInfo) |
{ |
@@ -70,13 +97,20 @@ static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
delete JniLongToTypePtr<JniPlatform>(ptr); |
} |
-static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobject jAppInfo) |
+static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobject jAppInfo, jlong v8IsolatePtr) |
{ |
try |
{ |
AdblockPlus::AppInfo appInfo; |
TransformAppInfo(env, jAppInfo, appInfo); |
- GetPlatformRef(ptr).SetUpJsEngine(appInfo); |
+ std::unique_ptr<AdblockPlus::IV8IsolateProvider> isolateProvider = nullptr; |
sergei
2017/09/26 09:44:13
There is no need in initializing it to nullptr.
anton
2017/09/26 10:55:06
Acknowledged.
|
+ if (v8IsolatePtr) |
+ { |
+ isolateProvider = std::unique_ptr<AdblockPlus::IV8IsolateProvider>( |
sergei
2017/09/26 09:44:13
I think it would be shorter
isolateProvider.reset(
anton
2017/09/26 10:55:06
Acknowledged.
anton
2017/09/26 11:04:25
"Error:(104, 87) error: invalid static_cast from t
|
+ new V8IsolateHolder((v8::Isolate*)v8IsolatePtr)); |
+ } |
+ |
+ GetPlatformRef(ptr).SetUpJsEngine(appInfo, std::move(isolateProvider)); |
} |
CATCH_AND_THROW(env) |
} |
@@ -132,7 +166,7 @@ static JNINativeMethod methods[] = |
{ (char*)"ctor", (char*)"(" TYP("LogSystem") TYP("WebRequest") "Ljava/lang/String;)J", (void*)JniCtor }, |
{ (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, |
- { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") ")V", (void*)JniSetUpJsEngine }, |
+ { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") "J)V", (void*)JniSetUpJsEngine }, |
{ (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr }, |
{ (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") ")V", (void*)JniSetUpFilterEngine }, |
{ (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine } |