Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 27 matching lines...) Expand all Loading... | |
38 class Isolate; | 38 class Isolate; |
39 class Value; | 39 class Value; |
40 class Context; | 40 class Context; |
41 template<class T> class Handle; | 41 template<class T> class Handle; |
42 typedef Handle<Value>(*InvocationCallback)(const Arguments &args); | 42 typedef Handle<Value>(*InvocationCallback)(const Arguments &args); |
43 } | 43 } |
44 | 44 |
45 namespace AdblockPlus | 45 namespace AdblockPlus |
46 { | 46 { |
47 class JsEngine; | 47 class JsEngine; |
48 | |
49 /** | |
50 * Shared smart pointer to a `JsEngine` instance. | |
51 */ | |
48 typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; | 52 typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; |
49 | 53 |
50 /** | 54 /** |
51 * JavaScript engine used by `FilterEngine`, uses v8. | 55 * JavaScript engine used by `FilterEngine`, wraps v8. |
Wladimir Palant
2014/08/28 17:24:40
"uses v8" => "wraps v8"?
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
52 */ | 56 */ |
53 class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> | 57 class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> |
54 { | 58 { |
55 friend class JsValue; | 59 friend class JsValue; |
56 friend class JsContext; | 60 friend class JsContext; |
57 | 61 |
58 public: | 62 public: |
59 /** | 63 /** |
60 * Event callback function. | 64 * Event callback function. |
61 */ | 65 */ |
62 typedef std::tr1::function<void(JsValueList& params)> EventCallback; | 66 typedef std::tr1::function<void(JsValueList& params)> EventCallback; |
63 | 67 |
64 /** | 68 /** |
65 * Maps events to callback functions. | 69 * Maps events to callback functions. |
66 */ | 70 */ |
67 typedef std::map<std::string, EventCallback> EventMap; | 71 typedef std::map<std::string, EventCallback> EventMap; |
68 | 72 |
69 /** | 73 /** |
70 * Creates a new JavaScript engine instance. | 74 * Creates a new JavaScript engine instance. |
71 * @param appInfo AppInfo Information about the app, used for update checks. | 75 * @param appInfo Information about the app. |
Wladimir Palant
2014/08/28 17:24:40
"AppInfo" is unnecessary here?
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
72 * @return New `JsEngine` instance. | 76 * @return New `JsEngine` instance. |
73 */ | 77 */ |
74 static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); | 78 static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); |
75 | 79 |
76 /** | 80 /** |
77 * Registers the callback function for an event. | 81 * Registers the callback function for an event. |
78 * @param eventName Name of the event. | 82 * @param eventName Event name. Note that this can be any string - it's a |
Wladimir Palant
2014/08/28 17:24:40
Here and below, why not just "Event name" and "Eve
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
83 * general purpose event handling mechanism. | |
79 * @param callback Event callback function. | 84 * @param callback Event callback function. |
80 */ | 85 */ |
81 void SetEventCallback(const std::string& eventName, EventCallback callback); | 86 void SetEventCallback(const std::string& eventName, EventCallback callback); |
82 | 87 |
83 /** | 88 /** |
84 * Removes the callback function for an event. | 89 * Removes the callback function for an event. |
85 * @param eventName Name of the event. | 90 * @param eventName Event name. |
86 */ | 91 */ |
87 void RemoveEventCallback(const std::string& eventName); | 92 void RemoveEventCallback(const std::string& eventName); |
88 | 93 |
89 /** | 94 /** |
90 * Triggers an event. | 95 * Triggers an event. |
91 * @param eventName Name of the event. | 96 * @param eventName Event name. |
92 * @param params Parameters for the event. | 97 * @param params Event parameters. |
93 */ | 98 */ |
94 void TriggerEvent(const std::string& eventName, JsValueList& params); | 99 void TriggerEvent(const std::string& eventName, JsValueList& params); |
95 | 100 |
96 /** | 101 /** |
97 * Evaluates a JavaScript expression. | 102 * Evaluates a JavaScript expression. |
98 * @param source JavaScript expression to evalute. | 103 * @param source JavaScript expression to evaluate. |
Wladimir Palant
2014/08/28 17:24:40
"evaluate"
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
99 * @param filename Optional file name for the expression, used in error | 104 * @param filename Optional file name for the expression, used in error |
100 * messages. | 105 * messages. |
101 * @return Result of the evaluated expression. | 106 * @return Result of the evaluated expression. |
102 */ | 107 */ |
103 JsValuePtr Evaluate(const std::string& source, | 108 JsValuePtr Evaluate(const std::string& source, |
104 const std::string& filename = ""); | 109 const std::string& filename = ""); |
105 | 110 |
106 /** | 111 /** |
107 * Initiates a garbage collection. | 112 * Initiates a garbage collection. |
Wladimir Palant
2014/08/28 17:24:40
I don't think you can use an article here...
Felix Dahlke
2014/08/28 22:56:41
I do, here's one example found in the wild: http:/
| |
108 */ | 113 */ |
109 void Gc(); | 114 void Gc(); |
110 | 115 |
111 //@{ | 116 //@{ |
112 /** | 117 /** |
113 * Creates a new JavaScript value. | 118 * Creates a new JavaScript value. |
114 * @param val Value to convert. | 119 * @param val Value to convert. |
115 * @return New `JsValue` instance. | 120 * @return New `JsValue` instance. |
116 */ | 121 */ |
117 JsValuePtr NewValue(const std::string& val); | 122 JsValuePtr NewValue(const std::string& val); |
(...skipping 15 matching lines...) Expand all Loading... | |
133 #endif | 138 #endif |
134 //@} | 139 //@} |
135 | 140 |
136 /** | 141 /** |
137 * Creates a new JavaScript object. | 142 * Creates a new JavaScript object. |
138 * @return New `JsValue` instance. | 143 * @return New `JsValue` instance. |
139 */ | 144 */ |
140 JsValuePtr NewObject(); | 145 JsValuePtr NewObject(); |
141 | 146 |
142 /** | 147 /** |
143 * Creates a new JavaScript callback. | 148 * Creates a JavaScript function that invokes a C++ callback. |
Wladimir Palant
2014/08/28 17:24:40
The thing about documentation is: it should be hel
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
144 * @param callback Callback to convert. | 149 * @param callback C++ callback to invoke. The callback receives a |
150 * `v8::Arguments` object and can use `FromArguments()` to retrieve | |
151 * the current `JsEngine`. | |
145 * @return New `JsValue` instance. | 152 * @return New `JsValue` instance. |
146 */ | 153 */ |
147 JsValuePtr NewCallback(v8::InvocationCallback callback); | 154 JsValuePtr NewCallback(v8::InvocationCallback callback); |
148 | 155 |
149 /** | 156 /** |
150 * Returns a `JsEngine` instance contained in a `v8::Arguments` object. | 157 * Returns a `JsEngine` instance contained in a `v8::Arguments` object. |
158 * Use this in callbacks created via `NewCallback()` to retrieve the current | |
159 * `JsEngine`. | |
151 * @param arguments `v8::Arguments` object containing the `JsEngine` | 160 * @param arguments `v8::Arguments` object containing the `JsEngine` |
152 * instance. | 161 * instance. |
153 * @return `JsEngine` instance. | 162 * @return `JsEngine` instance from `v8::Arguments`. |
154 */ | 163 */ |
155 static JsEnginePtr FromArguments(const v8::Arguments& arguments); | 164 static JsEnginePtr FromArguments(const v8::Arguments& arguments); |
156 | 165 |
157 /** | 166 /** |
158 * Converts v8 arguments to `JsValue` objects. | 167 * Converts v8 arguments to `JsValue` objects. |
159 * @param arguments `v8::Arguments` object containing the arguments to | 168 * @param arguments `v8::Arguments` object containing the arguments to |
160 * convert. | 169 * convert. |
161 * @return List of arguments converted to `JsValue` objects. | 170 * @return List of arguments converted to `JsValue` objects. |
162 */ | 171 */ |
163 JsValueList ConvertArguments(const v8::Arguments& arguments); | 172 JsValueList ConvertArguments(const v8::Arguments& arguments); |
164 | 173 |
165 /** | 174 /** |
166 * @see SetFileSystem(). | 175 * @see `SetFileSystem()`. |
167 */ | 176 */ |
168 FileSystemPtr GetFileSystem(); | 177 FileSystemPtr GetFileSystem(); |
169 | 178 |
170 /** | 179 /** |
171 * Sets the `FileSystem` implementation used for all file I/O. | 180 * Sets the `FileSystem` implementation used for all file I/O. |
172 * Setting this is optional, the engine will use a `DefaultFileSystem` | 181 * Setting this is optional, the engine will use a `DefaultFileSystem` |
173 * instance by default, which should normally be sufficient. | 182 * instance by default, which might be sufficient. |
Wladimir Palant
2014/08/28 17:24:40
"normally be sufficient"? "might be sufficient" is
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
174 * @param The `FileSystem` instance to use. | 183 * @param The `FileSystem` instance to use. |
175 */ | 184 */ |
176 void SetFileSystem(FileSystemPtr val); | 185 void SetFileSystem(FileSystemPtr val); |
177 | 186 |
178 /** | 187 /** |
179 * @see SetWebRequest(). | 188 * @see `SetWebRequest()`. |
180 */ | 189 */ |
181 WebRequestPtr GetWebRequest(); | 190 WebRequestPtr GetWebRequest(); |
182 | 191 |
183 /** | 192 /** |
184 * Sets the `WebRequest` implementation used for XMLHttpRequests. | 193 * Sets the `WebRequest` implementation used for XMLHttpRequests. |
185 * Setting this is optional, the engine will use a `DefaultWebRequest` | 194 * Setting this is optional, the engine will use a `DefaultWebRequest` |
186 * instance by default, which should normally be sufficient. | 195 * instance by default, which might be sufficient. |
187 * @param The `WebRequest` instance to use. | 196 * @param The `WebRequest` instance to use. |
188 */ | 197 */ |
189 void SetWebRequest(WebRequestPtr val); | 198 void SetWebRequest(WebRequestPtr val); |
190 | 199 |
191 /** | 200 /** |
192 * @see SetLogSystem(). | 201 * @see `SetLogSystem()`. |
193 */ | 202 */ |
194 LogSystemPtr GetLogSystem(); | 203 LogSystemPtr GetLogSystem(); |
195 | 204 |
196 /** | 205 /** |
197 * Sets the `LogSystem` implementation used for logging (e.g. console.log). | 206 * Sets the `LogSystem` implementation used for logging (e.g. to handle |
Wladimir Palant
2014/08/28 17:24:40
"e.g. to handle console.log() calls from JavaScrip
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
207 * `console.log()` calls from JavaScript). | |
198 * Setting this is optional, the engine will use a `DefaultLogSystem` | 208 * Setting this is optional, the engine will use a `DefaultLogSystem` |
199 * instance by default, which should normally be sufficient. | 209 * instance by default, which might be sufficient. |
200 * @param The `FileSystem` instance to use. | 210 * @param The `LogSystem` instance to use. |
Wladimir Palant
2014/08/28 17:24:40
FileSystem => LogSystem?
Felix Dahlke
2014/08/28 22:56:41
Done.
| |
201 */ | 211 */ |
202 void SetLogSystem(LogSystemPtr val); | 212 void SetLogSystem(LogSystemPtr val); |
203 | 213 |
204 private: | 214 private: |
205 JsEngine(); | 215 JsEngine(); |
206 | 216 |
207 FileSystemPtr fileSystem; | 217 FileSystemPtr fileSystem; |
208 WebRequestPtr webRequest; | 218 WebRequestPtr webRequest; |
209 LogSystemPtr logSystem; | 219 LogSystemPtr logSystem; |
210 v8::Isolate* isolate; | 220 v8::Isolate* isolate; |
211 V8ValueHolder<v8::Context> context; | 221 V8ValueHolder<v8::Context> context; |
212 EventMap eventCallbacks; | 222 EventMap eventCallbacks; |
213 }; | 223 }; |
214 } | 224 } |
215 | 225 |
216 #endif | 226 #endif |
LEFT | RIGHT |