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

Unified Diff: include/AdblockPlus/JsEngine.h

Issue 29661564: Template out V8 and prepare for other JS engine implementations
Patch Set: Created Jan. 10, 2018, 1:29 p.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 | include/AdblockPlus/JsValue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/JsEngine.h
===================================================================
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -44,8 +44,8 @@
namespace AdblockPlus
{
- class JsEngine;
class Platform;
+ template <typename T> class JsEngineTemplate;
/**
* Shared smart pointer to a `JsEngine` instance.
@@ -67,20 +67,32 @@
virtual v8::Isolate* Get() = 0;
};
+ template <typename T>
+ struct JsWeakValuesList
+ {
+ ~JsWeakValuesList();
+ std::vector<T> values;
+ };
+ typedef std::list<JsWeakValuesList<v8::Global<v8::Value>>> JsWeakValuesLists;
+
+ /**
+ * An opaque structure representing ID of stored JsValueList.
+ */
+ class JsWeakValuesID
+ {
+ template <typename T> friend class JsEngineTemplate;
+ JsWeakValuesLists::const_iterator iterator;
+ };
+
+
/**
* JavaScript engine used by `FilterEngine`, wraps v8.
*/
- class JsEngine : public std::enable_shared_from_this<JsEngine>
+ template <typename T> class JsEngineTemplate : public std::enable_shared_from_this<JsEngineTemplate<T>>
{
- friend class JsValue;
- friend class JsContext;
+ template <typename T> friend class JsValueTemplate;
+ template <typename T> friend class JsContextTemplate;
- struct JsWeakValuesList
- {
- ~JsWeakValuesList();
- std::vector<v8::Global<v8::Value>> values;
- };
- typedef std::list<JsWeakValuesList> JsWeakValuesLists;
public:
/**
* Event callback function.
@@ -93,15 +105,6 @@
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.
@@ -186,7 +189,7 @@
* the current `JsEngine`.
* @return New `JsValue` instance.
*/
- JsValue NewCallback(const v8::FunctionCallback& callback);
+ JsValue NewCallback(const typename T::CallbackFunc& callback);
/**
* Returns a `JsEngine` instance contained in a `v8::FunctionCallbackInfo` object.
@@ -196,7 +199,7 @@
* instance.
* @return `JsEngine` instance from `v8::FunctionCallbackInfo`.
*/
- static JsEnginePtr FromArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments);
+ static JsEnginePtr FromArguments(const typename T::CallbackFuncInfo& arguments);
/**
* Stores `JsValue`s in a way they don't keep a strong reference to
@@ -223,14 +226,14 @@
* @param arguments `v8::FunctionCallbackInfo` is the arguments received in C++
* callback associated for global setTimeout method.
*/
- static void ScheduleTimer(const v8::FunctionCallbackInfo<v8::Value>& arguments);
+ static void ScheduleTimer(const typename T::CallbackFuncInfo& arguments);
/*
* Private functionality required to implement web requests.
* @param arguments `v8::FunctionCallbackInfo` is the arguments received in C++
* callback associated for global GET method.
*/
- static void ScheduleWebRequest(const v8::FunctionCallbackInfo<v8::Value>& arguments);
+ static void ScheduleWebRequest(const typename T::CallbackFuncInfo& arguments);
/**
* Converts v8 arguments to `JsValue` objects.
@@ -238,7 +241,7 @@
* convert.
* @return List of arguments converted to `const JsValue` objects.
*/
- JsValueList ConvertArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments);
+ JsValueList ConvertArguments(const typename T::CallbackFuncInfo& arguments);
/**
* Sets a global property that can be accessed by all the scripts.
@@ -250,7 +253,7 @@
/**
* Returns a pointer to associated v8::Isolate.
*/
- v8::Isolate* GetIsolate()
+ typename T::Isolate* GetIsolate()
{
return isolate->Get();
}
@@ -271,7 +274,7 @@
private:
void CallTimerTask(const JsWeakValuesID& timerParamsID);
- explicit JsEngine(Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate);
+ explicit JsEngineTemplate(Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate);
JsValue GetGlobalObject();
@@ -280,7 +283,7 @@
/// using it.
std::unique_ptr<IV8IsolateProvider> isolate;
- std::unique_ptr<v8::Global<v8::Context>> context;
+ std::unique_ptr<typename T::GlobalContext> context;
EventMap eventCallbacks;
std::mutex eventCallbacksMutex;
JsWeakValuesLists jsWeakValuesLists;
« no previous file with comments | « no previous file | include/AdblockPlus/JsValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld