Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include/AdblockPlus/JsEngine.h

Issue 29527588: Issue 5570 - Make V8 isolate injectable into JsEngine (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Aug. 25, 2017, 8:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/AdblockPlus/Platform.h » ('j') | include/AdblockPlus/Platform.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 { 46 {
47 class JsEngine; 47 class JsEngine;
48 class Platform; 48 class Platform;
49 49
50 /** 50 /**
51 * Shared smart pointer to a `JsEngine` instance. 51 * Shared smart pointer to a `JsEngine` instance.
52 */ 52 */
53 typedef std::shared_ptr<JsEngine> JsEnginePtr; 53 typedef std::shared_ptr<JsEngine> JsEnginePtr;
54 54
55 /** 55 /**
56 * Scope based isolate manager. Creates a new isolate instance on 56 * Provides with isolate. The main aim of this iterface is to delegate a
57 * constructing and disposes it on destructing. 57 * proper initialization and deinitialization of v8::Isolate to an embedder.
58 */ 58 */
59 class ScopedV8Isolate 59 struct IV8IsolateProvider
60 { 60 {
61 public: 61 virtual ~IV8IsolateProvider() {}
62 ScopedV8Isolate();
63 ~ScopedV8Isolate();
64 v8::Isolate* Get()
65 {
66 return isolate;
67 }
68 private:
69 ScopedV8Isolate(const ScopedV8Isolate&);
70 ScopedV8Isolate& operator=(const ScopedV8Isolate&);
71 62
72 v8::Isolate* isolate; 63 /**
64 * Returns v8::Isolate. All subsequent calls of this method should return
65 * the same pointer to v8::Isolate as the first call.
66 */
67 virtual v8::Isolate* Get() = 0;
73 }; 68 };
74 69
75 /** 70 /**
76 * JavaScript engine used by `FilterEngine`, wraps v8. 71 * JavaScript engine used by `FilterEngine`, wraps v8.
77 */ 72 */
78 class JsEngine : public std::enable_shared_from_this<JsEngine> 73 class JsEngine : public std::enable_shared_from_this<JsEngine>
79 { 74 {
80 friend class JsValue; 75 friend class JsValue;
81 friend class JsContext; 76 friend class JsContext;
82 77
(...skipping 23 matching lines...) Expand all
106 friend class JsEngine; 101 friend class JsEngine;
107 JsWeakValuesLists::const_iterator iterator; 102 JsWeakValuesLists::const_iterator iterator;
108 }; 103 };
109 104
110 /** 105 /**
111 * Creates a new JavaScript engine instance. 106 * Creates a new JavaScript engine instance.
112 * 107 *
113 * @param appInfo Information about the app. 108 * @param appInfo Information about the app.
114 * @param platform AdblockPlus platform providing with necessary 109 * @param platform AdblockPlus platform providing with necessary
115 * dependencies. 110 * dependencies.
111 * @param isolate A provider of v8::Isolate, if the value is nullptr then
112 * a default implementation is used.
116 * @return New `JsEngine` instance. 113 * @return New `JsEngine` instance.
117 */ 114 */
118 static JsEnginePtr New(const AppInfo& appInfo, Platform& platform); 115 static JsEnginePtr New(const AppInfo& appInfo, Platform& platform, std::uniq ue_ptr<IV8IsolateProvider> isolate = nullptr);
119 /** 116 /**
120 * Registers the callback function for an event. 117 * Registers the callback function for an event.
121 * @param eventName Event name. Note that this can be any string - it's a 118 * @param eventName Event name. Note that this can be any string - it's a
122 * general purpose event handling mechanism. 119 * general purpose event handling mechanism.
123 * @param callback Event callback function. 120 * @param callback Event callback function.
124 */ 121 */
125 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback); 122 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback);
126 123
127 /** 124 /**
128 * Removes the callback function for an event. 125 * Removes the callback function for an event.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 * @param name Name of the property to set. 246 * @param name Name of the property to set.
250 * @param value Value of the property to set. 247 * @param value Value of the property to set.
251 */ 248 */
252 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value); 249 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value);
253 250
254 /** 251 /**
255 * Returns a pointer to associated v8::Isolate. 252 * Returns a pointer to associated v8::Isolate.
256 */ 253 */
257 v8::Isolate* GetIsolate() 254 v8::Isolate* GetIsolate()
258 { 255 {
259 return isolate.Get(); 256 return isolate->Get();
260 } 257 }
261 258
262 /** 259 /**
263 * Notifies JS engine about critically low memory what should cause a 260 * Notifies JS engine about critically low memory what should cause a
264 * garbage collection. 261 * garbage collection.
265 */ 262 */
266 void NotifyLowMemory(); 263 void NotifyLowMemory();
267 264
268 /** 265 /**
269 * Private functionality. 266 * Private functionality.
270 */ 267 */
271 Platform& GetPlatform() 268 Platform& GetPlatform()
272 { 269 {
273 return platform; 270 return platform;
274 } 271 }
275 private: 272 private:
276 void CallTimerTask(const JsWeakValuesID& timerParamsID); 273 void CallTimerTask(const JsWeakValuesID& timerParamsID);
277 274
278 explicit JsEngine(Platform& platform); 275 explicit JsEngine(Platform& platform, std::unique_ptr<IV8IsolateProvider> is olate);
279 276
280 JsValue GetGlobalObject(); 277 JsValue GetGlobalObject();
281 278
279 Platform& platform;
282 /// Isolate must be disposed only after disposing of all objects which are 280 /// Isolate must be disposed only after disposing of all objects which are
283 /// using it. 281 /// using it.
284 ScopedV8Isolate isolate; 282 std::unique_ptr<IV8IsolateProvider> isolate;
285 Platform& platform;
286 283
287 std::unique_ptr<v8::Global<v8::Context>> context; 284 std::unique_ptr<v8::Global<v8::Context>> context;
288 EventMap eventCallbacks; 285 EventMap eventCallbacks;
289 std::mutex eventCallbacksMutex; 286 std::mutex eventCallbacksMutex;
290 JsWeakValuesLists jsWeakValuesLists; 287 JsWeakValuesLists jsWeakValuesLists;
291 std::mutex jsWeakValuesListsMutex; 288 std::mutex jsWeakValuesListsMutex;
292 }; 289 };
293 } 290 }
294 291
295 #endif 292 #endif
OLDNEW
« no previous file with comments | « no previous file | include/AdblockPlus/Platform.h » ('j') | include/AdblockPlus/Platform.h » ('J')

Powered by Google App Engine
This is Rietveld