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

Side by Side Diff: src/JsEngine.cpp

Issue 10420020: Made sure FilterEngine instances are always initialized (Closed)
Patch Set: Using a generic messaging mechanism Created May 23, 2013, 6:35 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | test/BaseJsTest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 { 86 {
87 const Context context(shared_from_this()); 87 const Context context(shared_from_this());
88 const v8::TryCatch tryCatch; 88 const v8::TryCatch tryCatch;
89 const v8::Handle<v8::Script> script = CompileScript(source, filename); 89 const v8::Handle<v8::Script> script = CompileScript(source, filename);
90 CheckTryCatch(tryCatch); 90 CheckTryCatch(tryCatch);
91 v8::Local<v8::Value> result = script->Run(); 91 v8::Local<v8::Value> result = script->Run();
92 CheckTryCatch(tryCatch); 92 CheckTryCatch(tryCatch);
93 return JsValuePtr(new JsValue(shared_from_this(), result)); 93 return JsValuePtr(new JsValue(shared_from_this(), result));
94 } 94 }
95 95
96 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName,
97 AdblockPlus::JsEngine::EventCallback callback)
98 {
99 eventCallbacks[eventName] = callback;
100 }
101
102 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName)
103 {
104 eventCallbacks.erase(eventName);
105 }
106
107 void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName)
108 {
109 EventMap::iterator it = eventCallbacks.find(eventName);
110 if (it != eventCallbacks.end())
111 it->second();
112 }
113
96 void AdblockPlus::JsEngine::Gc() 114 void AdblockPlus::JsEngine::Gc()
97 { 115 {
98 while (!v8::V8::IdleNotification()); 116 while (!v8::V8::IdleNotification());
99 } 117 }
100 118
101 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) 119 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val)
102 { 120 {
103 const Context context(shared_from_this()); 121 const Context context(shared_from_this());
104 return JsValuePtr(new JsValue(shared_from_this(), 122 return JsValuePtr(new JsValue(shared_from_this(),
105 v8::String::New(val.c_str(), val.length()))); 123 v8::String::New(val.c_str(), val.length())));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 throw std::runtime_error("LogSystem cannot be null"); 219 throw std::runtime_error("LogSystem cannot be null");
202 220
203 logSystem = val; 221 logSystem = val;
204 } 222 }
205 223
206 AdblockPlus::JsEngine::Context::Context(const JsEnginePtr jsEngine) 224 AdblockPlus::JsEngine::Context::Context(const JsEnginePtr jsEngine)
207 : locker(jsEngine->isolate), handleScope(), 225 : locker(jsEngine->isolate), handleScope(),
208 contextScope(jsEngine->context) 226 contextScope(jsEngine->context)
209 { 227 {
210 } 228 }
OLDNEW
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | test/BaseJsTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld