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

Delta Between Two Patch Sets: libadblockplus-android/jni/JniPlatform.cpp

Issue 29556582: Issue 5643 - Make v8::Isolate injectable into JsEngine (Closed)
Left Patch Set: Created Sept. 26, 2017, 8:54 a.m.
Right Patch Set: Using JniLongToTypePtr for casting Created Sept. 28, 2017, 8:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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
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
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
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 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld