| Index: include/AdblockPlus/JsValue.h |
| =================================================================== |
| --- a/include/AdblockPlus/JsValue.h |
| +++ b/include/AdblockPlus/JsValue.h |
| @@ -29,14 +29,68 @@ |
| { |
| class Value; |
| class Object; |
| + class Isolate; |
| + class Context; |
| + class Locker; |
| + class HandleScope; |
| + template<class T> class Local; |
| + template<class T> class Global; |
| + template<typename T> class FunctionCallbackInfo; |
| + typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>& info); |
| +} |
| + |
| +namespace duktape |
| +{ |
| + class Value; |
| + class Object; |
| + class Isolate; |
| + class Context; |
| + class Locker; |
| + class HandleScope; |
| template<class T> class Local; |
| template<class T> class Global; |
| + template<typename T> class FunctionCallbackInfo; |
| + typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>& info); |
| } |
| +template <class TValue, class TObject, class TLocalValue, class TGlobalValue, class TLocalObject, class TCallbackFunc, class TCallbackFuncInfo, class TContext, class TLocalContext, class TGlobalContext, class THandleScope, class TLocker, class TIsolate> |
| +struct JsEngineNamespace |
| +{ |
| + typedef TValue Value; |
| + typedef TObject Object; |
| + typedef TLocalValue LocalValue; |
| + typedef TGlobalValue GlobalValue; |
| + typedef TLocalObject LocalObject; |
| + typedef TCallbackFunc CallbackFunc; |
| + typedef TCallbackFuncInfo CallbackFuncInfo; |
| + typedef TContext Context; |
| + typedef TLocalContext LocalContext; |
| + typedef TGlobalContext GlobalContext; |
| + typedef THandleScope HandleScope; |
| + typedef TLocker Locker; |
| + typedef TIsolate Isolate; |
| +}; |
| +#ifdef ABP_DUKTAPE |
| +typedef JsEngineNamespace<duktape::Value, duktape::Object, duktape::Local<duktape::Value>, duktape::Global<duktape::Value>, duktape::Local<duktape::Object>, duktape::FunctionCallback, duktape::FunctionCallbackInfo<duktape::Value>, duktape::Context, duktape::Local<duktape::Context>, duktape::Global<duktape::Context>, duktape::HandleScope, duktape::Locker, duktape::Isolate> JsEngineNamespaceImpl; |
| +#define JSVALUEIMPL JsValueTemplate<JsEngineNamespaceImpl> |
| +#define JSENGINEIMPL JsEngineTemplate<JsEngineNamespaceImpl> |
| +#define JSVALUEDUKTAPE JSVALUEIMPL |
| +#define JSENGINEDUKTAPE JSENGINEIMPL |
| +#else // default to V8 |
| +typedef JsEngineNamespace<v8::Value, v8::Object, v8::Local<v8::Value>, v8::Global<v8::Value>, v8::Local<v8::Object>, v8::FunctionCallback, v8::FunctionCallbackInfo<v8::Value>, v8::Context, v8::Local<v8::Context>, v8::Global<v8::Context>, v8::HandleScope, v8::Locker, v8::Isolate> JsEngineNamespaceImpl; |
| +#define JSVALUEIMPL JsValueTemplate<JsEngineNamespaceImpl> |
| +#define JSENGINEIMPL JsEngineTemplate<JsEngineNamespaceImpl> |
| +#define JSVALUEV8 JSVALUEIMPL |
| +#define JSENGINEV8 JSENGINEIMPL |
| +#endif |
| + |
| namespace AdblockPlus |
| { |
| - class JsValue; |
| - class JsEngine; |
| + template <class T> class JsValueTemplate; |
| + typedef JSVALUEIMPL JsValue; |
| + |
| + template <class T> class JsEngineTemplate; |
| + typedef JSENGINEIMPL JsEngine; |
| typedef std::shared_ptr<JsEngine> JsEnginePtr; |
| @@ -51,16 +105,16 @@ |
| * Wrapper for JavaScript values. |
| * See `JsEngine` for creating `JsValue` objects. |
| */ |
| - class JsValue |
| + template <class T> class JsValueTemplate |
| { |
| - friend class JsEngine; |
| + template <typename T> friend class JsEngineTemplate; |
| public: |
| - JsValue(JsValue&& src); |
| - JsValue(const JsValue& src); |
| - virtual ~JsValue(); |
| + JsValueTemplate(JsValueTemplate<T>&& src); |
| + JsValueTemplate(const JsValueTemplate<T>& src); |
| + virtual ~JsValueTemplate(); |
| - JsValue& operator=(const JsValue& src); |
| - JsValue& operator=(JsValue&& src); |
| + JsValueTemplate<T>& operator=(const JsValueTemplate<T>& src); |
| + JsValueTemplate<T>& operator=(JsValueTemplate<T>&& src); |
| bool IsUndefined() const; |
| bool IsNull() const; |
| @@ -149,19 +203,19 @@ |
| */ |
| JsValue Call(const JsValue& arg) const; |
| - v8::Local<v8::Value> UnwrapValue() const; |
| + typename T::LocalValue UnwrapValue() const; |
| protected: |
| JsEnginePtr jsEngine; |
| private: |
| - JsValue(JsEnginePtr jsEngine, v8::Local<v8::Value> value); |
| - void SetProperty(const std::string& name, v8::Local<v8::Value> val); |
| + JsValueTemplate<T>(JsEnginePtr jsEngine, typename T::LocalValue); |
| + void SetProperty(const std::string& name, typename T::LocalValue val); |
| // Parameter args is not const because a pointer to its internal arrays is |
| // passed to v8::Function::Call but the latter does not expect a const pointer. |
| - JsValue Call(std::vector<v8::Local<v8::Value>>& args, v8::Local<v8::Object> thisObj) const; |
| + JsValue Call(std::vector<typename T::LocalValue>& args, typename T::LocalObject thisObj) const; |
| - std::unique_ptr<v8::Global<v8::Value>> value; |
| + std::unique_ptr<typename T::GlobalValue> value; |
| }; |
| } |