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

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

Issue 29442722: Issue 3593 - stop sharing v8::Isolate among tests (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: address comments Created May 26, 2017, 10:54 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 | src/JsEngine.cpp » ('j') | no next file with comments »
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-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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 return isolate; 75 return isolate;
76 } 76 }
77 private: 77 private:
78 ScopedV8Isolate(const ScopedV8Isolate&); 78 ScopedV8Isolate(const ScopedV8Isolate&);
79 ScopedV8Isolate& operator=(const ScopedV8Isolate&); 79 ScopedV8Isolate& operator=(const ScopedV8Isolate&);
80 80
81 v8::Isolate* isolate; 81 v8::Isolate* isolate;
82 }; 82 };
83 83
84 /** 84 /**
85 * Shared smart pointer to ScopedV8Isolate instance;
86 */
87 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
88
89 /**
90 * JavaScript engine used by `FilterEngine`, wraps v8. 85 * JavaScript engine used by `FilterEngine`, wraps v8.
91 */ 86 */
92 class JsEngine : public std::enable_shared_from_this<JsEngine> 87 class JsEngine : public std::enable_shared_from_this<JsEngine>
93 { 88 {
94 friend class JsValue; 89 friend class JsValue;
95 friend class JsContext; 90 friend class JsContext;
96 91
97 struct JsWeakValuesList 92 struct JsWeakValuesList
98 { 93 {
99 ~JsWeakValuesList(); 94 ~JsWeakValuesList();
(...skipping 25 matching lines...) Expand all
125 * Creates a new JavaScript engine instance. 120 * Creates a new JavaScript engine instance.
126 * @param appInfo Information about the app. 121 * @param appInfo Information about the app.
127 * @param timer Implementation of timer. 122 * @param timer Implementation of timer.
128 * @param webRequest Implementation of web request. 123 * @param webRequest Implementation of web request.
129 * @param isolate v8::Isolate wrapper. This parameter should be considered 124 * @param isolate v8::Isolate wrapper. This parameter should be considered
130 * as a temporary hack for tests, it will go away. Issue #3593. 125 * as a temporary hack for tests, it will go away. Issue #3593.
131 * @return New `JsEngine` instance. 126 * @return New `JsEngine` instance.
132 */ 127 */
133 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), 128 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(),
134 TimerPtr timer = CreateDefaultTimer(), 129 TimerPtr timer = CreateDefaultTimer(),
135 WebRequestPtr webRequest = CreateDefaultWebRequest(), 130 WebRequestPtr webRequest = CreateDefaultWebRequest());
136 const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate ()));
137 131
138 /** 132 /**
139 * Registers the callback function for an event. 133 * Registers the callback function for an event.
140 * @param eventName Event name. Note that this can be any string - it's a 134 * @param eventName Event name. Note that this can be any string - it's a
141 * general purpose event handling mechanism. 135 * general purpose event handling mechanism.
142 * @param callback Event callback function. 136 * @param callback Event callback function.
143 */ 137 */
144 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback); 138 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback);
145 139
146 /** 140 /**
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 * @param name Name of the property to set. 297 * @param name Name of the property to set.
304 * @param value Value of the property to set. 298 * @param value Value of the property to set.
305 */ 299 */
306 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value); 300 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value);
307 301
308 /** 302 /**
309 * Returns a pointer to associated v8::Isolate. 303 * Returns a pointer to associated v8::Isolate.
310 */ 304 */
311 v8::Isolate* GetIsolate() 305 v8::Isolate* GetIsolate()
312 { 306 {
313 return isolate->Get(); 307 return isolate.Get();
314 } 308 }
315 309
316 /** 310 /**
317 * Notifies JS engine about critically low memory what should cause a 311 * Notifies JS engine about critically low memory what should cause a
318 * garbage collection. 312 * garbage collection.
319 */ 313 */
320 void NotifyLowMemory(); 314 void NotifyLowMemory();
321 private: 315 private:
322 void CallTimerTask(const JsWeakValuesID& timerParamsID); 316 void CallTimerTask(const JsWeakValuesID& timerParamsID);
323 317
324 explicit JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer, WebRequ estPtr webRequest); 318 explicit JsEngine(TimerPtr timer, WebRequestPtr webRequest);
325 319
326 JsValue GetGlobalObject(); 320 JsValue GetGlobalObject();
327 321
328 /// Isolate must be disposed only after disposing of all objects which are 322 /// Isolate must be disposed only after disposing of all objects which are
329 /// using it. 323 /// using it.
330 ScopedV8IsolatePtr isolate; 324 ScopedV8Isolate isolate;
331 325
332 FileSystemPtr fileSystem; 326 FileSystemPtr fileSystem;
333 LogSystemPtr logSystem; 327 LogSystemPtr logSystem;
334 std::unique_ptr<v8::Persistent<v8::Context>> context; 328 std::unique_ptr<v8::Persistent<v8::Context>> context;
335 EventMap eventCallbacks; 329 EventMap eventCallbacks;
336 std::mutex eventCallbacksMutex; 330 std::mutex eventCallbacksMutex;
337 JsWeakValuesLists jsWeakValuesLists; 331 JsWeakValuesLists jsWeakValuesLists;
338 std::mutex jsWeakValuesListsMutex; 332 std::mutex jsWeakValuesListsMutex;
339 TimerPtr timer; 333 TimerPtr timer;
340 WebRequestPtr webRequest; 334 WebRequestPtr webRequest;
341 WebRequestSharedPtr webRequestLegacy; 335 WebRequestSharedPtr webRequestLegacy;
342 }; 336 };
343 } 337 }
344 338
345 #endif 339 #endif
OLDNEW
« no previous file with comments | « no previous file | src/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld