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