Index: include/AdblockPlus/JsEngine.h |
diff --git a/include/AdblockPlus/JsEngine.h b/include/AdblockPlus/JsEngine.h |
index bf68c378d56e4e0dcc295e488c4502950dfce7a0..c3408c8c603bd331e0859e1dd63f6cea3a217e81 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. |
Eric
2016/01/26 14:48:58
Better wording in the comment would call this a "r
sergei
2016/01/27 15:06:07
It seems your terminology is slightly different fr
Eric
2016/01/27 17:21:01
"Resource wrapper" is more common.
|
+ */ |
+ class ScopedV8Isolate |
Eric
2016/01/26 14:48:58
Call it "V8Isolate". Every class is scoped; there'
sergei
2016/01/27 15:06:08
I would not object to call it V8Isolate if it were
|
+ { |
+ public: |
+ ScopedV8Isolate(); |
+ ~ScopedV8Isolate(); |
Eric
2016/01/26 14:48:58
Since you're inlining the definition of "GetIsolat
sergei
2016/01/27 15:06:09
Constructor and destructor are enough complicated
Eric
2016/01/27 17:21:01
That's reasonable.
|
+ v8::Isolate* GetIsolate() |
+ { |
+ return isolate; |
+ } |
+ protected: |
+ v8::Isolate* isolate; |
Eric
2016/01/26 14:48:57
This member should be private; the "protected" dec
sergei
2016/01/27 15:06:09
Done.
|
+ private: |
+ ScopedV8Isolate(const ScopedV8Isolate&); |
+ ScopedV8Isolate& operator=(const ScopedV8Isolate&); |
+ }; |
+ |
+ /** |
+ * Shared smart pointer to ScopedV8Isolate instance; |
+ */ |
+ typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; |
Eric
2016/01/26 14:48:58
There's no need for this typedef, and 'shared_ptr'
sergei
2016/01/27 15:06:08
Now it's used in several places in JsEngine and on
Eric
2016/01/27 17:21:01
It does not need to be used in any of those places
sergei
2016/01/28 14:02:50
Sorry, what can be used? Are you saying that std::
Eric
2016/01/28 16:42:41
Of course not.
I'm going to post a review. It wil
|
+ |
+ /** |
* 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()); |
Eric
2016/01/26 14:48:57
Having an argument for the isolate in the construc
sergei
2016/01/27 15:06:07
It sounds like "having a clean testable architectu
Eric
2016/01/27 17:21:01
It's not clean, in my opinion. It's creating an un
sergei
2016/01/28 14:02:50
Answered in BaseJsTest (https://codereview.adblock
|
/** |
* 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() |
Eric
2016/01/26 14:48:58
Note: returns a raw pointer, not a smart one, even
sergei
2016/01/27 15:06:09
By fact we need raw v8::Isolate for internal purpo
|
+ { |
+ return isolate->GetIsolate(); |
+ } |
+ |
private: |
- JsEngine(); |
+ explicit JsEngine(const ScopedV8IsolatePtr& isolate); |
+ |
+ /// Isolate must be disposed only after disposing of all objects which are |
+ /// using it. |
+ ScopedV8IsolatePtr isolate; |
FileSystemPtr fileSystem; |
WebRequestPtr webRequest; |
LogSystemPtr logSystem; |
- v8::Isolate* isolate; |
std::unique_ptr<v8::Persistent<v8::Context>> context; |
EventMap eventCallbacks; |
JsValuePtr globalJsObject; |