| Index: include/AdblockPlus/JsEngine.h | 
| =================================================================== | 
| --- a/include/AdblockPlus/JsEngine.h | 
| +++ b/include/AdblockPlus/JsEngine.h | 
| @@ -30,7 +30,6 @@ | 
| #include <AdblockPlus/WebRequest.h> | 
| #include "tr1_memory.h" | 
| -#include "V8ValueHolder.h" | 
| namespace v8 | 
| { | 
| @@ -40,6 +39,7 @@ | 
| class Context; | 
| template<class T> class Handle; | 
| typedef Handle<Value>(*InvocationCallback)(const Arguments &args); | 
| + typedef void(*FunctionCallback)(const FunctionCallbackInfo<Value>& info); | 
| } | 
| namespace AdblockPlus | 
| @@ -49,21 +49,63 @@ | 
| /** | 
| * Shared smart pointer to a `JsEngine` instance. | 
| */ | 
| - typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; | 
| + typedef std::shared_ptr<JsEngine> JsEnginePtr; | 
| + | 
| + // These classes are inherited by JsEngine to avoid any mistake in the order of object destroying and | 
| + // disposing. The isolate should be disposed after the everything else. v8::Isolate::Scope | 
| + // requires a scope, there is no API to "close" it. | 
| + class IsolateManagerJsEngine | 
| + { | 
| + protected: | 
| + IsolateManagerJsEngine() | 
| + : isolate{v8::Isolate::New()} | 
| + { | 
| + } | 
| + ~IsolateManagerJsEngine() | 
| + { | 
| + isolate->Dispose(); | 
| + } | 
| + v8::Isolate* isolate; | 
| + }; | 
| + | 
| + class IsolateScopeJsEngine : protected IsolateManagerJsEngine | 
| + { | 
| + protected: | 
| + IsolateScopeJsEngine() | 
| + : isolateScope{isolate} | 
| + { | 
| + } | 
| + ~IsolateScopeJsEngine() | 
| + { | 
| + } | 
| + v8::Isolate::Scope isolateScope; | 
| + }; | 
| + | 
| + class ContextScopeJsEngine : protected IsolateScopeJsEngine | 
| + { | 
| + protected: | 
| + ~ContextScopeJsEngine() | 
| + { | 
| + } | 
| + v8::UniquePersistent<v8::Context> context; | 
| + }; | 
| /** | 
| * JavaScript engine used by `FilterEngine`, wraps v8. | 
| */ | 
| - class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> | 
| + class JsEngine : public std::enable_shared_from_this<JsEngine>, protected ContextScopeJsEngine | 
| { | 
| friend class JsValue; | 
| friend class JsContext; | 
| + struct PrivateCtrArg{}; | 
| + public: | 
| + JsEngine(PrivateCtrArg); | 
| + ~JsEngine(); | 
| - public: | 
| /** | 
| * Event callback function. | 
| */ | 
| - typedef std::tr1::function<void(JsValueList& params)> EventCallback; | 
| + typedef std::function<void(JsValueList& params)> EventCallback; | 
| /** | 
| * Maps events to callback functions. | 
| @@ -151,7 +193,7 @@ | 
| * the current `JsEngine`. | 
| * @return New `JsValue` instance. | 
| */ | 
| - JsValuePtr NewCallback(v8::InvocationCallback callback); | 
| + JsValuePtr NewCallback(v8::FunctionCallback callback); | 
| /** | 
| * Returns a `JsEngine` instance contained in a `v8::Arguments` object. | 
| @@ -161,7 +203,7 @@ | 
| * instance. | 
| * @return `JsEngine` instance from `v8::Arguments`. | 
| */ | 
| - static JsEnginePtr FromArguments(const v8::Arguments& arguments); | 
| + static JsEnginePtr FromArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments); | 
| /** | 
| * Converts v8 arguments to `JsValue` objects. | 
| @@ -169,7 +211,7 @@ | 
| * convert. | 
| * @return List of arguments converted to `JsValue` objects. | 
| */ | 
| - JsValueList ConvertArguments(const v8::Arguments& arguments); | 
| + JsValueList ConvertArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments); | 
| /** | 
| * @see `SetFileSystem()`. | 
| @@ -212,13 +254,9 @@ | 
| void SetLogSystem(LogSystemPtr val); | 
| private: | 
| - JsEngine(); | 
| - | 
| FileSystemPtr fileSystem; | 
| WebRequestPtr webRequest; | 
| LogSystemPtr logSystem; | 
| - v8::Isolate* isolate; | 
| - V8ValueHolder<v8::Context> context; | 
| EventMap eventCallbacks; | 
| }; | 
| } |