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

Unified Diff: include/AdblockPlus/JsEngine.h

Issue 6233220328718336: Issue #3593, #1197- fix isolate management (Closed)
Patch Set: fix the crash (hacky) Created Nov. 16, 2015, 4:51 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 | libadblockplus.gyp » ('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 2893752f6738d6d585a0b75c65d67d759d513b92..7ddbeb0f69b0253123767dd31c218b5c0f8c68c4 100644
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -48,6 +48,28 @@ 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* GetIsolate()
+ {
+ return isolate;
+ }
+ protected:
+ v8::Isolate* isolate;
+ };
+
+ /**
+ * Shared smart pointer to ScopedV8Isolate instance;
+ */
+ typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
+
/**
* JavaScript engine used by `FilterEngine`, wraps v8.
*/
@@ -72,7 +94,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 +237,24 @@ namespace AdblockPlus
*/
void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr value);
+ /**
+ * Returns a pointer to associated v8::Isolate.
+ */
+ v8::Isolate* GetIsolate()
+ {
+ 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;
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld