Index: src/GlobalJsObject.cpp |
=================================================================== |
--- a/src/GlobalJsObject.cpp |
+++ b/src/GlobalJsObject.cpp |
@@ -79,22 +79,34 @@ namespace |
} |
timeoutThread->Start(); |
// We should actually return the timer ID here, which could be |
// used via clearTimeout(). But since we don't seem to need |
// clearTimeout(), we can save that for later. |
return v8::Undefined(); |
} |
+ |
+ v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) |
+ { |
+ AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments); |
+ AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); |
+ if (converted.size() != 1) |
+ return v8::ThrowException(v8::String::New("_triggerEvent expects one parameter")); |
+ |
+ jsEngine->TriggerEvent(converted[0]->AsString()); |
+ return v8::Undefined(); |
+ } |
} |
JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, |
JsValuePtr obj) |
{ |
obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); |
+ obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback)); |
obj->SetProperty("_fileSystem", |
FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); |
obj->SetProperty("_webRequest", |
WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); |
obj->SetProperty("console", |
ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); |
obj->SetProperty("_appInfo", |
AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); |