| Left: | ||
| Right: |
| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * V8IsolateHolder accepts v8:::Isolate ptr in ctor and just returns it in Get() . | 24 * V8IsolateHolder accepts v8:::Isolate ptr in ctor and just returns it in Get() . |
| 25 * V8IsolateHolder is not taking ownership so it's not releasing isolate ptr. | 25 * V8IsolateHolder is not taking ownership so it's not releasing isolate ptr. |
| 26 */ | 26 */ |
| 27 class V8IsolateHolder : public AdblockPlus::IV8IsolateProvider | 27 class V8IsolateHolder : public AdblockPlus::IV8IsolateProvider |
| 28 { | 28 { |
| 29 public: | 29 public: |
| 30 V8IsolateHolder(v8::Isolate* isolate_) : isolate(isolate_) | 30 V8IsolateHolder(v8::Isolate* isolate_) : isolate(isolate_) |
| 31 { | 31 { |
| 32 } | |
| 33 | |
| 34 ~V8IsolateHolder() | |
|
sergei
2017/09/26 09:44:13
I would propose to remove the destructor here.
anton
2017/09/26 10:55:06
Acknowledged.
| |
| 35 { | |
| 36 isolate = nullptr; | |
| 37 } | 32 } |
| 38 | 33 |
| 39 v8::Isolate* Get() override | 34 v8::Isolate* Get() override |
| 40 { | 35 { |
| 41 return isolate; | 36 return isolate; |
| 42 } | 37 } |
| 43 | 38 |
| 44 private: | 39 private: |
| 45 V8IsolateHolder(const V8IsolateHolder&); | 40 V8IsolateHolder(const V8IsolateHolder&); |
| 46 V8IsolateHolder& operator=(const V8IsolateHolder&); | 41 V8IsolateHolder& operator=(const V8IsolateHolder&); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 { | 91 { |
| 97 delete JniLongToTypePtr<JniPlatform>(ptr); | 92 delete JniLongToTypePtr<JniPlatform>(ptr); |
| 98 } | 93 } |
| 99 | 94 |
| 100 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo, jlong v8IsolatePtr) | 95 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo, jlong v8IsolatePtr) |
| 101 { | 96 { |
| 102 try | 97 try |
| 103 { | 98 { |
| 104 AdblockPlus::AppInfo appInfo; | 99 AdblockPlus::AppInfo appInfo; |
| 105 TransformAppInfo(env, jAppInfo, appInfo); | 100 TransformAppInfo(env, jAppInfo, appInfo); |
| 106 std::unique_ptr<AdblockPlus::IV8IsolateProvider> isolateProvider = nullptr; | 101 std::unique_ptr<AdblockPlus::IV8IsolateProvider> isolateProvider; |
|
sergei
2017/09/26 09:44:13
There is no need in initializing it to nullptr.
anton
2017/09/26 10:55:06
Acknowledged.
| |
| 107 if (v8IsolatePtr) | 102 if (v8IsolatePtr) |
| 108 { | 103 { |
| 109 isolateProvider = std::unique_ptr<AdblockPlus::IV8IsolateProvider>( | 104 isolateProvider.reset(new V8IsolateHolder(JniLongToTypePtr<v8::Isolate>(v8 IsolatePtr))); |
|
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
| |
| 110 new V8IsolateHolder((v8::Isolate*)v8IsolatePtr)); | |
| 111 } | 105 } |
| 112 | 106 |
| 113 GetPlatformRef(ptr).SetUpJsEngine(appInfo, std::move(isolateProvider)); | 107 GetPlatformRef(ptr).SetUpJsEngine(appInfo, std::move(isolateProvider)); |
| 114 } | 108 } |
| 115 CATCH_AND_THROW(env) | 109 CATCH_AND_THROW(env) |
| 116 } | 110 } |
| 117 | 111 |
| 118 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr) | 112 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr) |
| 119 { | 113 { |
| 120 try | 114 try |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") "J)V", (void*)JniSetUpJsE ngine }, | 163 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") "J)V", (void*)JniSetUpJsE ngine }, |
| 170 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr }, | 164 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr }, |
| 171 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine }, | 165 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine }, |
| 172 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine } | 166 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine } |
| 173 }; | 167 }; |
| 174 | 168 |
| 175 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz) | 169 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz) |
| 176 { | 170 { |
| 177 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 171 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 178 } | 172 } |
| LEFT | RIGHT |