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

Delta Between Two Patch Sets: include/AdblockPlus/JsEngine.h

Issue 6233220328718336: Issue #3593, #1197- fix isolate management (Closed)
Left Patch Set: make ScopedV8Isolate uncopyable Created Jan. 22, 2016, 10:39 a.m.
Right Patch Set: rebase fix v8 initialization Created May 20, 2016, 3:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | libadblockplus.gyp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 { 43 {
44 class JsEngine; 44 class JsEngine;
45 45
46 /** 46 /**
47 * Shared smart pointer to a `JsEngine` instance. 47 * Shared smart pointer to a `JsEngine` instance.
48 */ 48 */
49 typedef std::shared_ptr<JsEngine> JsEnginePtr; 49 typedef std::shared_ptr<JsEngine> JsEnginePtr;
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.
Eric 2016/01/26 14:48:58 Better wording in the comment would call this a "r
sergei 2016/01/27 15:06:07 It seems your terminology is slightly different fr
Eric 2016/01/27 17:21:01 "Resource wrapper" is more common.
54 */ 54 */
55 class ScopedV8Isolate 55 class ScopedV8Isolate
Eric 2016/01/26 14:48:58 Call it "V8Isolate". Every class is scoped; there'
sergei 2016/01/27 15:06:08 I would not object to call it V8Isolate if it were
56 { 56 {
57 public: 57 public:
58 ScopedV8Isolate(); 58 ScopedV8Isolate();
59 ~ScopedV8Isolate(); 59 ~ScopedV8Isolate();
Eric 2016/01/26 14:48:58 Since you're inlining the definition of "GetIsolat
sergei 2016/01/27 15:06:09 Constructor and destructor are enough complicated
Eric 2016/01/27 17:21:01 That's reasonable.
60 v8::Isolate* GetIsolate() 60 v8::Isolate* Get()
61 { 61 {
62 return isolate; 62 return isolate;
63 } 63 }
64 protected:
65 v8::Isolate* isolate;
Eric 2016/01/26 14:48:57 This member should be private; the "protected" dec
sergei 2016/01/27 15:06:09 Done.
66 private: 64 private:
67 ScopedV8Isolate(const ScopedV8Isolate&); 65 ScopedV8Isolate(const ScopedV8Isolate&);
68 ScopedV8Isolate& operator=(const ScopedV8Isolate&); 66 ScopedV8Isolate& operator=(const ScopedV8Isolate&);
67
68 v8::Isolate* isolate;
69 }; 69 };
70 70
71 /** 71 /**
72 * Shared smart pointer to ScopedV8Isolate instance; 72 * Shared smart pointer to ScopedV8Isolate instance;
73 */ 73 */
74 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; 74 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
Eric 2016/01/26 14:48:58 There's no need for this typedef, and 'shared_ptr'
sergei 2016/01/27 15:06:08 Now it's used in several places in JsEngine and on
Eric 2016/01/27 17:21:01 It does not need to be used in any of those places
sergei 2016/01/28 14:02:50 Sorry, what can be used? Are you saying that std::
Eric 2016/01/28 16:42:41 Of course not. I'm going to post a review. It wil
75 75
76 /** 76 /**
77 * JavaScript engine used by `FilterEngine`, wraps v8. 77 * JavaScript engine used by `FilterEngine`, wraps v8.
78 */ 78 */
79 class JsEngine : public std::enable_shared_from_this<JsEngine> 79 class JsEngine : public std::enable_shared_from_this<JsEngine>
80 { 80 {
81 friend class JsValue; 81 friend class JsValue;
82 friend class JsContext; 82 friend class JsContext;
83 83
84 public: 84 public:
85 /** 85 /**
86 * Event callback function. 86 * Event callback function.
87 */ 87 */
88 typedef std::function<void(JsValueList& params)> EventCallback; 88 typedef std::function<void(JsValueList& params)> EventCallback;
89 89
90 /** 90 /**
91 * Maps events to callback functions. 91 * Maps events to callback functions.
92 */ 92 */
93 typedef std::map<std::string, EventCallback> EventMap; 93 typedef std::map<std::string, EventCallback> EventMap;
94 94
95 /** 95 /**
96 * Creates a new JavaScript engine instance. 96 * Creates a new JavaScript engine instance.
97 * @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.
98 * @return New `JsEngine` instance. 100 * @return New `JsEngine` instance.
99 */ 101 */
100 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()));
Eric 2016/01/26 14:48:57 Having an argument for the isolate in the construc
sergei 2016/01/27 15:06:07 It sounds like "having a clean testable architectu
Eric 2016/01/27 17:21:01 It's not clean, in my opinion. It's creating an un
sergei 2016/01/28 14:02:50 Answered in BaseJsTest (https://codereview.adblock
101 103
102 /** 104 /**
103 * Registers the callback function for an event. 105 * Registers the callback function for an event.
104 * @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
105 * general purpose event handling mechanism. 107 * general purpose event handling mechanism.
106 * @param callback Event callback function. 108 * @param callback Event callback function.
107 */ 109 */
108 void SetEventCallback(const std::string& eventName, EventCallback callback); 110 void SetEventCallback(const std::string& eventName, EventCallback callback);
109 111
110 /** 112 /**
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 /** 238 /**
237 * Sets a global property that can be accessed by all the scripts. 239 * Sets a global property that can be accessed by all the scripts.
238 * @param name Name of the property to set. 240 * @param name Name of the property to set.
239 * @param value Value of the property to set. 241 * @param value Value of the property to set.
240 */ 242 */
241 void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr valu e); 243 void SetGlobalProperty(const std::string& name, AdblockPlus::JsValuePtr valu e);
242 244
243 /** 245 /**
244 * Returns a pointer to associated v8::Isolate. 246 * Returns a pointer to associated v8::Isolate.
245 */ 247 */
246 v8::Isolate* GetIsolate() 248 v8::Isolate* GetIsolate()
Eric 2016/01/26 14:48:58 Note: returns a raw pointer, not a smart one, even
sergei 2016/01/27 15:06:09 By fact we need raw v8::Isolate for internal purpo
247 { 249 {
248 return isolate->GetIsolate(); 250 return isolate->Get();
249 } 251 }
250 252
251 private: 253 private:
252 explicit JsEngine(const ScopedV8IsolatePtr& isolate); 254 explicit JsEngine(const ScopedV8IsolatePtr& isolate);
253 255
254 /// 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
255 /// using it. 257 /// using it.
256 ScopedV8IsolatePtr isolate; 258 ScopedV8IsolatePtr isolate;
257 259
258 FileSystemPtr fileSystem; 260 FileSystemPtr fileSystem;
259 WebRequestPtr webRequest; 261 WebRequestPtr webRequest;
260 LogSystemPtr logSystem; 262 LogSystemPtr logSystem;
261 std::unique_ptr<v8::Persistent<v8::Context>> context; 263 std::unique_ptr<v8::Persistent<v8::Context>> context;
262 EventMap eventCallbacks; 264 EventMap eventCallbacks;
263 JsValuePtr globalJsObject; 265 JsValuePtr globalJsObject;
264 }; 266 };
265 } 267 }
266 268
267 #endif 269 #endif
LEFTRIGHT
« no previous file | libadblockplus.gyp » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld