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

Unified Diff: include/AdblockPlus/JsEngine.h

Issue 29527588: Issue 5570 - Make V8 isolate injectable into JsEngine (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created Aug. 25, 2017, 3:08 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/AdblockPlus/Platform.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/JsEngine.h
diff --git a/include/AdblockPlus/JsEngine.h b/include/AdblockPlus/JsEngine.h
index 7446b19d842bb4cd5bc681ed3f0bc43fec0e5896..d45e731d2eb89106607b7498658ae0476bb1ab35 100644
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -53,23 +53,18 @@ namespace AdblockPlus
typedef std::shared_ptr<JsEngine> JsEnginePtr;
/**
- * Scope based isolate manager. Creates a new isolate instance on
- * constructing and disposes it on destructing.
+ * Provides with isolate. The main aim of this iterface is to delegate a
+ * proper initialization and deinitialization of v8::Isolate to an embedder.
*/
- class ScopedV8Isolate
+ struct IV8IsolateProvider
{
- public:
- ScopedV8Isolate();
- ~ScopedV8Isolate();
- v8::Isolate* Get()
- {
- return isolate;
- }
- private:
- ScopedV8Isolate(const ScopedV8Isolate&);
- ScopedV8Isolate& operator=(const ScopedV8Isolate&);
+ virtual ~IV8IsolateProvider() {}
- v8::Isolate* isolate;
+ /**
+ * Returns v8::Isolate. All subsequent calls of this method should return
+ * the same pointer to v8::Isolate as the first call.
+ */
+ virtual v8::Isolate* Get() = 0;
};
/**
@@ -112,9 +107,11 @@ namespace AdblockPlus
* @param appInfo Information about the app.
* @param platform AdblockPlus platform providing with necessary
* dependencies.
+ * @param isolate A provider of v8::Isolate, if the value is nullptr then
+ * a default implementation is used.
* @return New `JsEngine` instance.
*/
- static JsEnginePtr New(const AppInfo& appInfo, Platform& platform);
+ static JsEnginePtr New(const AppInfo& appInfo, Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate = nullptr);
/**
* Registers the callback function for an event.
* @param eventName Event name. Note that this can be any string - it's a
@@ -255,7 +252,7 @@ namespace AdblockPlus
*/
v8::Isolate* GetIsolate()
{
- return isolate.Get();
+ return isolate->Get();
}
/**
@@ -274,14 +271,14 @@ namespace AdblockPlus
private:
void CallTimerTask(const JsWeakValuesID& timerParamsID);
- explicit JsEngine(Platform& platform);
+ explicit JsEngine(Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate);
JsValue GetGlobalObject();
+ Platform& platform;
/// Isolate must be disposed only after disposing of all objects which are
/// using it.
- ScopedV8Isolate isolate;
- Platform& platform;
+ std::unique_ptr<IV8IsolateProvider> isolate;
std::unique_ptr<v8::Global<v8::Context>> context;
EventMap eventCallbacks;
« no previous file with comments | « no previous file | include/AdblockPlus/Platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld