Index: include/AdblockPlus/JsEngine.h |
diff --git a/include/AdblockPlus/JsEngine.h b/include/AdblockPlus/JsEngine.h |
index bf68c378d56e4e0dcc295e488c4502950dfce7a0..8d0b5dbe438b03335b45219aa42688df5b8ac2d1 100644 |
--- a/include/AdblockPlus/JsEngine.h |
+++ b/include/AdblockPlus/JsEngine.h |
@@ -49,6 +49,31 @@ namespace AdblockPlus |
typedef std::shared_ptr<JsEngine> JsEnginePtr; |
/** |
+ * Scope based isolate manager. Creates a new isolate instance on |
+ * constructing and disposes it on destructing. |
+ */ |
+ class ScopedV8Isolate |
+ { |
+ public: |
+ ScopedV8Isolate(); |
+ ~ScopedV8Isolate(); |
+ v8::Isolate* Get() |
+ { |
+ return isolate; |
+ } |
+ private: |
+ ScopedV8Isolate(const ScopedV8Isolate&); |
+ ScopedV8Isolate& operator=(const ScopedV8Isolate&); |
+ |
+ v8::Isolate* isolate; |
+ }; |
+ |
+ /** |
+ * Shared smart pointer to ScopedV8Isolate instance; |
+ */ |
+ typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; |
+ |
+ /** |
* JavaScript engine used by `FilterEngine`, wraps v8. |
*/ |
class JsEngine : public std::enable_shared_from_this<JsEngine> |
@@ -72,7 +97,7 @@ namespace AdblockPlus |
* @param appInfo Information about the app. |
* @return New `JsEngine` instance. |
*/ |
- static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); |
+ static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr()); |
/** |
* Registers the callback function for an event. |
@@ -215,13 +240,24 @@ namespace AdblockPlus |
*/ |
void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr value); |
+ /** |
+ * Returns a pointer to associated v8::Isolate. |
+ */ |
+ v8::Isolate* GetIsolate() |
+ { |
+ return isolate->Get(); |
+ } |
+ |
private: |
- JsEngine(); |
+ explicit JsEngine(const ScopedV8IsolatePtr& isolate); |
+ |
+ /// Isolate must be disposed only after disposing of all objects which are |
+ /// using it. |
+ ScopedV8IsolatePtr isolate; |
Eric
2016/01/27 17:21:02
You should be able to declare this member 'const'.
sergei
2016/01/28 14:02:50
I don't think that it would be better here. I woul
Eric
2016/01/28 16:42:41
I've said before that this member should _not_ be
sergei
2016/01/29 11:31:14
I have just explained my point of view regarding u
Eric
2016/02/09 14:59:14
I am seriously beginning to think you don't actual
|
FileSystemPtr fileSystem; |
WebRequestPtr webRequest; |
LogSystemPtr logSystem; |
- v8::Isolate* isolate; |
std::unique_ptr<v8::Persistent<v8::Context>> context; |
EventMap eventCallbacks; |
JsValuePtr globalJsObject; |