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

Unified Diff: src/JsEngine.cpp

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 | « src/JsContext.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -108,17 +108,18 @@
using namespace AdblockPlus;
-JsEngine::JsWeakValuesList::~JsWeakValuesList()
-{
-}
+template <> JsWeakValuesList<v8::Global<v8::Value>>::~JsWeakValuesList()
+{
+}
-void JsEngine::NotifyLowMemory()
+
+template <> void AdblockPlus::JSENGINEV8::NotifyLowMemory()
{
const JsContext context(*this);
GetIsolate()->MemoryPressureNotification(v8::MemoryPressureLevel::kCritical);
}
-void JsEngine::ScheduleTimer(const v8::FunctionCallbackInfo<v8::Value>& arguments)
+template <> void AdblockPlus::JSENGINEV8::ScheduleTimer(const v8::FunctionCallbackInfo<v8::Value>& arguments)
{
auto jsEngine = FromArguments(arguments);
if (arguments.Length() < 2)
@@ -144,7 +145,7 @@
});
}
-void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID)
+template <> void AdblockPlus::JSENGINEV8::CallTimerTask(const JsWeakValuesID& timerParamsID)
{
auto timerParams = TakeJsValues(timerParamsID);
JsValue callback = std::move(timerParams[0]);
@@ -154,13 +155,14 @@
callback.Call(timerParams);
}
-AdblockPlus::JsEngine::JsEngine(Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate)
+template <> AdblockPlus::JSENGINEV8::JsEngineTemplate(Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate)
: platform(platform)
, isolate(std::move(isolate))
{
}
-AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo,
+
+template <> AdblockPlus::JsEnginePtr AdblockPlus::JSENGINEV8::New(const AppInfo& appInfo,
Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate)
{
if (!isolate)
@@ -180,13 +182,13 @@
return result;
}
-AdblockPlus::JsValue AdblockPlus::JsEngine::GetGlobalObject()
+template <> AdblockPlus::JsValue AdblockPlus::JSENGINEV8::GetGlobalObject()
{
JsContext context(*this);
- return JsValue(shared_from_this(), context.GetV8Context()->Global());
+ return JsValue(shared_from_this(), context.GetJSEngineContext()->Global());
}
-AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source,
+template <> AdblockPlus::JsValue AdblockPlus::JSENGINEV8::Evaluate(const std::string& source,
const std::string& filename)
{
const JsContext context(*this);
@@ -199,8 +201,8 @@
return JsValue(shared_from_this(), result);
}
-void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName,
- const AdblockPlus::JsEngine::EventCallback& callback)
+template <> void AdblockPlus::JSENGINEV8::SetEventCallback(const std::string& eventName,
+ const AdblockPlus::JSENGINEV8::EventCallback& callback)
{
if (!callback)
{
@@ -211,13 +213,13 @@
eventCallbacks[eventName] = callback;
}
-void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName)
+template <> void AdblockPlus::JSENGINEV8::RemoveEventCallback(const std::string& eventName)
{
std::lock_guard<std::mutex> lock(eventCallbacksMutex);
eventCallbacks.erase(eventName);
}
-void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName, AdblockPlus::JsValueList&& params)
+template <> void AdblockPlus::JSENGINEV8::TriggerEvent(const std::string& eventName, AdblockPlus::JsValueList&& params)
{
EventCallback callback;
{
@@ -230,36 +232,36 @@
callback(move(params));
}
-void AdblockPlus::JsEngine::Gc()
+template <> void AdblockPlus::JSENGINEV8::Gc()
{
while (!GetIsolate()->IdleNotification(1000));
}
-AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val)
+template <> AdblockPlus::JsValue AdblockPlus::JSENGINEV8::NewValue(const std::string& val)
{
const JsContext context(*this);
return JsValue(shared_from_this(), Utils::ToV8String(GetIsolate(), val));
}
-AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val)
+template <> AdblockPlus::JsValue AdblockPlus::JSENGINEV8::NewValue(int64_t val)
{
const JsContext context(*this);
return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val));
}
-AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val)
+template <> AdblockPlus::JsValue AdblockPlus::JSENGINEV8::NewValue(bool val)
{
const JsContext context(*this);
return JsValue(shared_from_this(), v8::Boolean::New(GetIsolate(), val));
}
-AdblockPlus::JsValue AdblockPlus::JsEngine::NewObject()
+template <> AdblockPlus::JsValue AdblockPlus::JSENGINEV8::NewObject()
{
const JsContext context(*this);
return JsValue(shared_from_this(), v8::Object::New(GetIsolate()));
}
-AdblockPlus::JsValue AdblockPlus::JsEngine::NewCallback(
+template <> AdblockPlus::JsValue AdblockPlus::JSENGINEV8::NewCallback(
const v8::FunctionCallback& callback)
{
const JsContext context(*this);
@@ -273,7 +275,7 @@
return JsValue(shared_from_this(), templ->GetFunction());
}
-AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments)
+template <> AdblockPlus::JsEnginePtr AdblockPlus::JSENGINEV8::FromArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments)
{
const v8::Local<const v8::External> external =
v8::Local<const v8::External>::Cast(arguments.Data());
@@ -285,7 +287,7 @@
return result;
}
-JsEngine::JsWeakValuesID JsEngine::StoreJsValues(const JsValueList& values)
+template <> AdblockPlus::JsWeakValuesID AdblockPlus::JSENGINEV8::StoreJsValues(const JsValueList& values)
{
JsWeakValuesLists::iterator it;
{
@@ -304,7 +306,7 @@
return retValue;
}
-JsValueList JsEngine::TakeJsValues(const JsWeakValuesID& id)
+template <> JsValueList JSENGINEV8::TakeJsValues(const JsWeakValuesID& id)
{
JsValueList retValue;
{
@@ -321,7 +323,7 @@
return retValue;
}
-AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments)
+template <> AdblockPlus::JsValueList AdblockPlus::JSENGINEV8::ConvertArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments)
{
const JsContext context(*this);
JsValueList list;
@@ -330,7 +332,7 @@
return list;
}
-void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
+void AdblockPlus::JSENGINEV8::SetGlobalProperty(const std::string& name,
const AdblockPlus::JsValue& value)
{
auto global = GetGlobalObject();
« no previous file with comments | « src/JsContext.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld