Description- stop sharing of v8::Isolate among tests (test/BaseJsTest.cpp::CreateJsEngine).
- JsValue now holds a weak_ptr<JsEngine> instead of a shared_ptr, so now there is no circular references. ~JsValue is also now guarded by JsContext because we should not try to Dispose underlying value if there is no longer JsEngine.
- add JsEngine::JsEngineNotAvailableException which is thrown when JsEngine is not available.
- Ignore JsEngine::JsEngineNotAvailableException if it's thrown inside Thread::Run.
- IoThread (used in FileSystemJsObject.cpp) and WebRequestJsObject now hold a weak_ptr<JsEngine> instead of shared_ptr. Indirect strong references to JsEngine held by JsValue members are also removed by changes in JsValue. So even if there is a long running IO operation the application is still controlling the lifetime of corresponding instance of JsEngine. Although it's not an issue for current FileSystem, it's vital for tests with LazyWebRequest (FileSystem will likely also have asynchronous interface in a future). LazyWebRequest sleeps for infinity time thus preventing the thread from finishing, so with shared_ptr member the instance of JsEngine is never deleted, weak_ptr allows to free resources. The disadvantage of the solution is that if we must do something else in the callback to stay consistent, there is a possibility that the persistent state will be inconsistent because the callback is not called after finishing of IO operation if there is already no JsEngine.
- add member "JsEnginePtr jsEngine;" with corresponding getter to JsContext and change constructor to accept weak_ptr<JsEngine>. We use JsContext as a scoped object defining when JsEngine can be used by obtaining of certain lock and creating scopes for underlying v8 structures. It seems make sense to include JsEngine into that context and it looks convenient and descriptive in code when JsEngine is actually available only if JsContext is successfully instantiated. If weak_ptr references already destroyed JsEngine then it throws exception JsEngine::JsEngineNotAvailableException.
- move creating of JsContext at the beginning of some methods of JsValue because it avoids additional pairs of release/lock operations.
- add std::shared_ptr<JsEngine> Utils::lockJsEngine(const std::weak_ptr<JsEngine>& jsEngine) which throws JsEngine::JsEngineNotAvailableException if it cannot obtain not nullptr.
- add a couple of tests against regressions involving the leakage of JsEngine.
- move "jsEngine = CreateJsEngine();" into SetUp of the fixture for Prefs tests.
# depends on https://codereview.adblockplus.org/29361582/
Patch Set 1 #
Total comments: 10
Patch Set 2 : address comments #
Total comments: 8
Patch Set 3 : address comments #Patch Set 4 : temporary workaround for race condition #
Total comments: 1
MessagesTotal messages: 9
|