| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 Loading... |
| 86 */ | 86 */ |
| 87 class JsEngine : public std::enable_shared_from_this<JsEngine> | 87 class JsEngine : public std::enable_shared_from_this<JsEngine> |
| 88 { | 88 { |
| 89 friend class JsValue; | 89 friend class JsValue; |
| 90 friend class JsContext; | 90 friend class JsContext; |
| 91 | 91 |
| 92 public: | 92 public: |
| 93 /** | 93 /** |
| 94 * Event callback function. | 94 * Event callback function. |
| 95 */ | 95 */ |
| 96 typedef std::function<void(const JsConstValueList& params)> EventCallback; | 96 typedef std::function<void(const JsValueList& params)> EventCallback; |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Callback function returning false when current connection is not allowed | 99 * Callback function returning false when current connection is not allowed |
| 100 * e.g. because it is a metered connection. | 100 * e.g. because it is a metered connection. |
| 101 */ | 101 */ |
| 102 typedef std::function<bool()> IsConnectionAllowedCallback; | 102 typedef std::function<bool()> IsConnectionAllowedCallback; |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * Maps events to callback functions. | 105 * Maps events to callback functions. |
| 106 */ | 106 */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 * Removes the callback function for an event. | 130 * Removes the callback function for an event. |
| 131 * @param eventName Event name. | 131 * @param eventName Event name. |
| 132 */ | 132 */ |
| 133 void RemoveEventCallback(const std::string& eventName); | 133 void RemoveEventCallback(const std::string& eventName); |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * Triggers an event. | 136 * Triggers an event. |
| 137 * @param eventName Event name. | 137 * @param eventName Event name. |
| 138 * @param params Event parameters. | 138 * @param params Event parameters. |
| 139 */ | 139 */ |
| 140 void TriggerEvent(const std::string& eventName, const JsConstValueList& para
ms); | 140 void TriggerEvent(const std::string& eventName, const JsValueList& params); |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Evaluates a JavaScript expression. | 143 * Evaluates a JavaScript expression. |
| 144 * @param source JavaScript expression to evaluate. | 144 * @param source JavaScript expression to evaluate. |
| 145 * @param filename Optional file name for the expression, used in error | 145 * @param filename Optional file name for the expression, used in error |
| 146 * messages. | 146 * messages. |
| 147 * @return Result of the evaluated expression. | 147 * @return Result of the evaluated expression. |
| 148 */ | 148 */ |
| 149 JsValuePtr Evaluate(const std::string& source, | 149 JsValuePtr Evaluate(const std::string& source, |
| 150 const std::string& filename = ""); | 150 const std::string& filename = ""); |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * Initiates a garbage collection. | 153 * Initiates a garbage collection. |
| 154 */ | 154 */ |
| 155 void Gc(); | 155 void Gc(); |
| 156 | 156 |
| 157 //@{ | 157 //@{ |
| 158 /** | 158 /** |
| 159 * Creates a new JavaScript value. | 159 * Creates a new JavaScript value. |
| 160 * @param val Value to convert. | 160 * @param val Value to convert. |
| 161 * @return New `JsValue` instance. | 161 * @return New `JsValue` instance. |
| 162 */ | 162 */ |
| 163 JsValuePtr NewValue(const std::string& val); | 163 JsValue NewValue(const std::string& val); |
| 164 JsValuePtr NewValue(int64_t val); | 164 JsValue NewValue(int64_t val); |
| 165 JsValuePtr NewValue(bool val); | 165 JsValue NewValue(bool val); |
| 166 inline JsValuePtr NewValue(const char* val) | 166 inline JsValue NewValue(const char* val) |
| 167 { | 167 { |
| 168 return NewValue(std::string(val)); | 168 return NewValue(std::string(val)); |
| 169 } | 169 } |
| 170 inline JsValuePtr NewValue(int val) | 170 inline JsValue NewValue(int val) |
| 171 { | 171 { |
| 172 return NewValue(static_cast<int64_t>(val)); | 172 return NewValue(static_cast<int64_t>(val)); |
| 173 } | 173 } |
| 174 #ifdef __APPLE__ | 174 #ifdef __APPLE__ |
| 175 inline JsValuePtr NewValue(long val) | 175 inline JsValue NewValue(long val) |
| 176 { | 176 { |
| 177 return NewValue(static_cast<int64_t>(val)); | 177 return NewValue(static_cast<int64_t>(val)); |
| 178 } | 178 } |
| 179 #endif | 179 #endif |
| 180 //@} | 180 //@} |
| 181 | 181 |
| 182 /** | 182 /** |
| 183 * Creates a new JavaScript object. | 183 * Creates a new JavaScript object. |
| 184 * @return New `JsValue` instance. | 184 * @return New `JsValue` instance. |
| 185 */ | 185 */ |
| 186 JsValuePtr NewObject(); | 186 JsValue NewObject(); |
| 187 | 187 |
| 188 /** | 188 /** |
| 189 * Creates a JavaScript function that invokes a C++ callback. | 189 * Creates a JavaScript function that invokes a C++ callback. |
| 190 * @param callback C++ callback to invoke. The callback receives a | 190 * @param callback C++ callback to invoke. The callback receives a |
| 191 * `v8::Arguments` object and can use `FromArguments()` to retrieve | 191 * `v8::Arguments` object and can use `FromArguments()` to retrieve |
| 192 * the current `JsEngine`. | 192 * the current `JsEngine`. |
| 193 * @return New `JsValue` instance. | 193 * @return New `JsValue` instance. |
| 194 */ | 194 */ |
| 195 JsValue NewCallback(const v8::InvocationCallback& callback); | 195 JsValue NewCallback(const v8::InvocationCallback& callback); |
| 196 | 196 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 210 * callback associated for global setTimeout method. | 210 * callback associated for global setTimeout method. |
| 211 */ | 211 */ |
| 212 static void ScheduleTimer(const v8::Arguments& arguments); | 212 static void ScheduleTimer(const v8::Arguments& arguments); |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * Converts v8 arguments to `JsValue` objects. | 215 * Converts v8 arguments to `JsValue` objects. |
| 216 * @param arguments `v8::Arguments` object containing the arguments to | 216 * @param arguments `v8::Arguments` object containing the arguments to |
| 217 * convert. | 217 * convert. |
| 218 * @return List of arguments converted to `const JsValue` objects. | 218 * @return List of arguments converted to `const JsValue` objects. |
| 219 */ | 219 */ |
| 220 JsConstValueList ConvertArguments(const v8::Arguments& arguments); | 220 JsValueList ConvertArguments(const v8::Arguments& arguments); |
| 221 | 221 |
| 222 /** | 222 /** |
| 223 * @see `SetFileSystem()`. | 223 * @see `SetFileSystem()`. |
| 224 */ | 224 */ |
| 225 FileSystemPtr GetFileSystem() const; | 225 FileSystemPtr GetFileSystem() const; |
| 226 | 226 |
| 227 /** | 227 /** |
| 228 * Sets the `FileSystem` implementation used for all file I/O. | 228 * Sets the `FileSystem` implementation used for all file I/O. |
| 229 * Setting this is optional, the engine will use a `DefaultFileSystem` | 229 * Setting this is optional, the engine will use a `DefaultFileSystem` |
| 230 * instance by default, which might be sufficient. | 230 * instance by default, which might be sufficient. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 EventMap eventCallbacks; | 311 EventMap eventCallbacks; |
| 312 std::mutex eventCallbacksMutex; | 312 std::mutex eventCallbacksMutex; |
| 313 mutable std::mutex isConnectionAllowedMutex; | 313 mutable std::mutex isConnectionAllowedMutex; |
| 314 IsConnectionAllowedCallback isConnectionAllowed; | 314 IsConnectionAllowedCallback isConnectionAllowed; |
| 315 TimerTasks timerTasks; | 315 TimerTasks timerTasks; |
| 316 TimerPtr timer; | 316 TimerPtr timer; |
| 317 }; | 317 }; |
| 318 } | 318 } |
| 319 | 319 |
| 320 #endif | 320 #endif |
| OLD | NEW |