Index: src/JsEngine.cpp |
diff --git a/src/JsEngine.cpp b/src/JsEngine.cpp |
index f874cf97c7486193aa51c1ee55a6b8c45ebf1adf..7bf1fc52ea9d5772111224ba406f0300c93430fd 100644 |
--- a/src/JsEngine.cpp |
+++ b/src/JsEngine.cpp |
@@ -64,6 +64,8 @@ namespace |
}; |
} |
+using namespace AdblockPlus; |
+ |
AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() |
{ |
V8Initializer::Init(); |
@@ -76,6 +78,41 @@ AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() |
isolate = nullptr; |
} |
+JsEngine::TimerTaskInfo::~TimerTaskInfo() |
+{ |
+ for (auto& arg : arguments) |
+ arg->Dispose(); |
+} |
+ |
+JsEngine::TimerTask JsEngine::CreateTimerTask(const v8::Arguments& arguments) |
+{ |
+ if (arguments.Length() < 2) |
+ throw std::runtime_error("setTimeout requires at least 2 parameters"); |
+ |
+ if (!arguments[0]->IsFunction()) |
+ throw std::runtime_error("First argument to setTimeout must be a function"); |
+ |
+ auto ii_timerTaskInfo = timerTaskInfos.emplace(timerTaskInfos.end()); |
+ ii_timerTaskInfo->delay = arguments[1]->IntegerValue(); |
+ |
+ for (int i = 0; i < arguments.Length(); i++) |
+ ii_timerTaskInfo->arguments.emplace_back(new v8::Persistent<v8::Value>(GetIsolate(), arguments[i])); |
+ TimerTask retValue = { shared_from_this(), ii_timerTaskInfo }; |
+ return retValue; |
+} |
+ |
+void JsEngine::CallTimerTask(TimerTaskInfos::const_iterator ii_taskInfo) |
+{ |
+ const JsContext context(shared_from_this()); |
+ JsValue callback(shared_from_this(), v8::Local<v8::Value>::New(GetIsolate(), *ii_taskInfo->arguments[0])); |
+ JsValueList callbackArgs; |
+ for (int i = 2; i < ii_taskInfo->arguments.size(); i++) |
+ callbackArgs.emplace_back(new JsValue(shared_from_this(), |
+ v8::Local<v8::Value>::New(GetIsolate(), *ii_taskInfo->arguments[i]))); |
+ callback.Call(callbackArgs); |
+ timerTaskInfos.erase(ii_taskInfo); |
+} |
+ |
AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) |
: isolate(isolate) |
{ |