| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 ScopedV8Isolate& operator=(const ScopedV8Isolate&); | 67 ScopedV8Isolate& operator=(const ScopedV8Isolate&); |
| 68 | 68 |
| 69 v8::Isolate* isolate; | 69 v8::Isolate* isolate; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Shared smart pointer to ScopedV8Isolate instance; | 73 * Shared smart pointer to ScopedV8Isolate instance; |
| 74 */ | 74 */ |
| 75 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; | 75 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; |
| 76 | 76 |
| 77 struct ImmediateSingleUseThreadType {}; ///< Marker class for scheduling polic
y | |
| 78 extern const ImmediateSingleUseThreadType ImmediateSingleUseThread; ///< Dummy
constant for scheduling policy | |
| 79 | |
| 80 /** | 77 /** |
| 81 * JavaScript engine used by `FilterEngine`, wraps v8. | 78 * JavaScript engine used by `FilterEngine`, wraps v8. |
| 82 */ | 79 */ |
| 83 class JsEngine : public std::enable_shared_from_this<JsEngine> | 80 class JsEngine : public std::enable_shared_from_this<JsEngine> |
| 84 { | 81 { |
| 85 public: | 82 public: |
| 86 /** | 83 /** |
| 87 * Event callback function. | 84 * Event callback function. |
| 88 */ | 85 */ |
| 89 typedef std::function<void(JsValueList& params)> EventCallback; | 86 typedef std::function<void(JsValueList& params)> EventCallback; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 * Evaluates a JavaScript expression. | 124 * Evaluates a JavaScript expression. |
| 128 * @param source JavaScript expression to evaluate. | 125 * @param source JavaScript expression to evaluate. |
| 129 * @param filename Optional file name for the expression, used in error | 126 * @param filename Optional file name for the expression, used in error |
| 130 * messages. | 127 * messages. |
| 131 * @return Result of the evaluated expression. | 128 * @return Result of the evaluated expression. |
| 132 */ | 129 */ |
| 133 JsValuePtr Evaluate(const std::string& source, | 130 JsValuePtr Evaluate(const std::string& source, |
| 134 const std::string& filename = ""); | 131 const std::string& filename = ""); |
| 135 | 132 |
| 136 /** | 133 /** |
| 137 * Schedule a task with these policies: | |
| 138 * - timing policy: start execution immediately. | |
| 139 * - threading policy: run the task in a single-use thread. | |
| 140 * | |
| 141 * @param task | |
| 142 * Task to execute. All v8 handles should refer to the present engine. | |
| 143 * @param ImmediateSingleUseThreadType | |
| 144 * The schedule policy--create a new thread and discard it afterwards. | |
| 145 */ | |
| 146 void Schedule(std::function<void()> task, ImmediateSingleUseThreadType); | |
| 147 | |
| 148 /** | |
| 149 * Block until there are no more tasks running in the scheduler. | |
| 150 * | |
| 151 * Note: this function does not prevent new tasks from being scheduled. | |
| 152 */ | |
| 153 void WaitForQuietScheduler(); | |
| 154 | |
| 155 /** | |
| 156 * Initiates a garbage collection. | 134 * Initiates a garbage collection. |
| 157 */ | 135 */ |
| 158 void Gc(); | 136 void Gc(); |
| 159 | 137 |
| 160 //@{ | 138 //@{ |
| 161 /** | 139 /** |
| 162 * Creates a new JavaScript value. | 140 * Creates a new JavaScript value. |
| 163 * @param val Value to convert. | 141 * @param val Value to convert. |
| 164 * @return New `JsValue` instance. | 142 * @return New `JsValue` instance. |
| 165 */ | 143 */ |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 JsValuePtr GetGlobalObject(); | 260 JsValuePtr GetGlobalObject(); |
| 283 | 261 |
| 284 /// Isolate must be disposed only after disposing of all objects which are | 262 /// Isolate must be disposed only after disposing of all objects which are |
| 285 /// using it. | 263 /// using it. |
| 286 ScopedV8IsolatePtr isolate; | 264 ScopedV8IsolatePtr isolate; |
| 287 | 265 |
| 288 FileSystemPtr fileSystem; | 266 FileSystemPtr fileSystem; |
| 289 WebRequestPtr webRequest; | 267 WebRequestPtr webRequest; |
| 290 LogSystemPtr logSystem; | 268 LogSystemPtr logSystem; |
| 291 EventMap eventCallbacks; | 269 EventMap eventCallbacks; |
| 292 | |
| 293 // Forward declaration for PImpl idiom | |
| 294 class SchedulerImpl; | |
| 295 /** | |
| 296 * Scheduler for tasks executed under the current engine. | |
| 297 * | |
| 298 * \par Invariant | |
| 299 * `bool(scheduler)` is always true | |
| 300 */ | |
| 301 std::unique_ptr<SchedulerImpl> scheduler; | |
| 302 }; | 270 }; |
| 303 } | 271 } |
| 304 | 272 |
| 305 #endif | 273 #endif |
| OLD | NEW |