| 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; | 
| }; | 
| } |