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

Unified Diff: include/AdblockPlus/JsEngine.h

Issue 29424659: Noissue - generalize storing of `JsValue`s in `JsEngine` (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: add empty line Created April 28, 2017, 10:49 a.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 | src/JsEngine.cpp » ('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 10e27ed4a2b94a0a4e03f6487642c716c6b0b887..55f7e04576fff13af1011158d508bc6cac3d91f4 100644
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -89,6 +89,12 @@ namespace AdblockPlus
friend class JsValue;
friend class JsContext;
+ struct JsWeakValuesList
+ {
+ ~JsWeakValuesList();
+ std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> values;
+ };
+ typedef std::list<JsWeakValuesList> JsWeakValuesLists;
public:
/**
* Event callback function.
@@ -107,6 +113,16 @@ namespace AdblockPlus
typedef std::map<std::string, EventCallback> EventMap;
/**
+ * An opaque structure representing ID of stored JsValueList.
+ *
+ */
+ class JsWeakValuesID
+ {
+ friend class JsEngine;
+ JsWeakValuesLists::const_iterator iterator;
+ };
+
+ /**
* Creates a new JavaScript engine instance.
* @param appInfo Information about the app.
* @param timer Implementation of timer.
@@ -204,6 +220,26 @@ namespace AdblockPlus
*/
static JsEnginePtr FromArguments(const v8::Arguments& arguments);
+ /**
+ * Stores `JsValue`s in a way they don't keep a strong reference to
+ * `JsEngine` and which are destroyed when `JsEngine` is destroyed. These
+ * methods should be used when one needs to carry a JsValue in a callback
+ * directly or indirectly passed to `JsEngine`.
+ * The method is thread-safe.
+ * @param `JsValueList` to store.
+ * @return `JsWeakValuesID` of stored values which allows to restore them
+ * later.
+ */
+ JsWeakValuesID StoreJsValues(const JsValueList& values);
+
+ /**
+ * Extracts and removes from `JsEngine` earlier stored `JsValue`s.
+ * The method is thread-safe.
+ * @param id `JsWeakValuesID` of values.
+ * @return `JsValueList` of stored values.
+ */
+ JsValueList TakeJsValues(const JsWeakValuesID& id);
+
/*
* Private functionality required to implement timers.
* @param arguments `v8::Arguments` is the arguments received in C++
@@ -288,13 +324,7 @@ namespace AdblockPlus
}
private:
- struct TimerTask
- {
- ~TimerTask();
- std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> arguments;
- };
- typedef std::list<TimerTask> TimerTasks;
- void CallTimerTask(const TimerTasks::const_iterator& timerTaskIterator);
+ void CallTimerTask(const JsWeakValuesID& timerParamsID);
explicit JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer);
@@ -312,7 +342,8 @@ namespace AdblockPlus
std::mutex eventCallbacksMutex;
mutable std::mutex isConnectionAllowedMutex;
IsConnectionAllowedCallback isConnectionAllowed;
- TimerTasks timerTasks;
+ JsWeakValuesLists jsWeakValuesLists;
+ std::mutex jsWeakValuesListsMutex;
TimerPtr timer;
};
}
« no previous file with comments | « no previous file | src/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld