LEFT | RIGHT |
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-2015 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 /** | 52 /** |
53 * Scope based isolate manager. Creates a new isolate instance on | 53 * Scope based isolate manager. Creates a new isolate instance on |
54 * constructing and disposes it on destructing. | 54 * constructing and disposes it on destructing. |
55 */ | 55 */ |
56 class ScopedV8Isolate | 56 class ScopedV8Isolate |
57 { | 57 { |
58 public: | 58 public: |
59 ScopedV8Isolate(); | 59 ScopedV8Isolate(); |
60 ~ScopedV8Isolate(); | 60 ~ScopedV8Isolate(); |
61 v8::Isolate* GetIsolate() | 61 v8::Isolate* Get() |
62 { | 62 { |
63 return isolate; | 63 return isolate; |
64 } | 64 } |
65 protected: | 65 private: |
| 66 ScopedV8Isolate(const ScopedV8Isolate&); |
| 67 ScopedV8Isolate& operator=(const ScopedV8Isolate&); |
| 68 |
66 v8::Isolate* isolate; | 69 v8::Isolate* isolate; |
67 }; | 70 }; |
68 | 71 |
69 /** | 72 /** |
70 * Shared smart pointer to ScopedV8Isolate instance; | 73 * Shared smart pointer to ScopedV8Isolate instance; |
71 */ | 74 */ |
72 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; | 75 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; |
73 | 76 |
74 /** | 77 /** |
75 * JavaScript engine used by `FilterEngine`, wraps v8. | 78 * JavaScript engine used by `FilterEngine`, wraps v8. |
(...skipping 10 matching lines...) Expand all Loading... |
86 typedef std::function<void(JsValueList& params)> EventCallback; | 89 typedef std::function<void(JsValueList& params)> EventCallback; |
87 | 90 |
88 /** | 91 /** |
89 * Maps events to callback functions. | 92 * Maps events to callback functions. |
90 */ | 93 */ |
91 typedef std::map<std::string, EventCallback> EventMap; | 94 typedef std::map<std::string, EventCallback> EventMap; |
92 | 95 |
93 /** | 96 /** |
94 * Creates a new JavaScript engine instance. | 97 * Creates a new JavaScript engine instance. |
95 * @param appInfo Information about the app. | 98 * @param appInfo Information about the app. |
| 99 * @param isolate v8::Isolate wrapper. This parameter should be considered |
| 100 * as a temporary hack for tests, it will go away. Issue #3593. |
96 * @return New `JsEngine` instance. | 101 * @return New `JsEngine` instance. |
97 */ | 102 */ |
98 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), const ScopedV8Iso
latePtr& isolate = ScopedV8IsolatePtr()); | 103 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), const ScopedV8Iso
latePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate())); |
99 | 104 |
100 /** | 105 /** |
101 * Registers the callback function for an event. | 106 * Registers the callback function for an event. |
102 * @param eventName Event name. Note that this can be any string - it's a | 107 * @param eventName Event name. Note that this can be any string - it's a |
103 * general purpose event handling mechanism. | 108 * general purpose event handling mechanism. |
104 * @param callback Event callback function. | 109 * @param callback Event callback function. |
105 */ | 110 */ |
106 void SetEventCallback(const std::string& eventName, EventCallback callback); | 111 void SetEventCallback(const std::string& eventName, EventCallback callback); |
107 | 112 |
108 /** | 113 /** |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 * @param name Name of the property to set. | 241 * @param name Name of the property to set. |
237 * @param value Value of the property to set. | 242 * @param value Value of the property to set. |
238 */ | 243 */ |
239 void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr valu
e); | 244 void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr valu
e); |
240 | 245 |
241 /** | 246 /** |
242 * Returns a pointer to associated v8::Isolate. | 247 * Returns a pointer to associated v8::Isolate. |
243 */ | 248 */ |
244 v8::Isolate* GetIsolate() | 249 v8::Isolate* GetIsolate() |
245 { | 250 { |
246 return isolate->GetIsolate(); | 251 return isolate->Get(); |
247 } | 252 } |
248 | 253 |
249 private: | 254 private: |
250 explicit JsEngine(const ScopedV8IsolatePtr& isolate); | 255 explicit JsEngine(const ScopedV8IsolatePtr& isolate); |
251 | 256 |
252 /// Isolate must be disposed only after disposing of all objects which are | 257 /// Isolate must be disposed only after disposing of all objects which are |
253 /// using it. | 258 /// using it. |
254 ScopedV8IsolatePtr isolate; | 259 ScopedV8IsolatePtr isolate; |
255 | 260 |
256 FileSystemPtr fileSystem; | 261 FileSystemPtr fileSystem; |
257 WebRequestPtr webRequest; | 262 WebRequestPtr webRequest; |
258 LogSystemPtr logSystem; | 263 LogSystemPtr logSystem; |
259 std::unique_ptr<v8::UniquePersistent<v8::Context>> context; | 264 std::unique_ptr<v8::UniquePersistent<v8::Context>> context; |
260 EventMap eventCallbacks; | 265 EventMap eventCallbacks; |
261 JsValuePtr globalJsObject; | 266 JsValuePtr globalJsObject; |
262 }; | 267 }; |
263 } | 268 } |
264 | 269 |
265 #endif | 270 #endif |
LEFT | RIGHT |