Index: src/JsEngine.cpp |
=================================================================== |
--- a/src/JsEngine.cpp |
+++ b/src/JsEngine.cpp |
@@ -88,16 +88,34 @@ AdblockPlus::JsValuePtr AdblockPlus::JsE |
const v8::TryCatch tryCatch; |
const v8::Handle<v8::Script> script = CompileScript(source, filename); |
CheckTryCatch(tryCatch); |
v8::Local<v8::Value> result = script->Run(); |
CheckTryCatch(tryCatch); |
return JsValuePtr(new JsValue(shared_from_this(), result)); |
} |
+void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, |
+ AdblockPlus::JsEngine::EventCallback callback) |
+{ |
+ eventCallbacks[eventName] = callback; |
+} |
+ |
+void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName) |
+{ |
+ eventCallbacks.erase(eventName); |
+} |
+ |
+void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName) |
+{ |
+ EventMap::iterator it = eventCallbacks.find(eventName); |
+ if (it != eventCallbacks.end()) |
+ it->second(); |
+} |
+ |
void AdblockPlus::JsEngine::Gc() |
{ |
while (!v8::V8::IdleNotification()); |
} |
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) |
{ |
const Context context(shared_from_this()); |