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

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

Issue 29451722: Issue 4907 - Update v8 to 5.7.278 in libadblockplus (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created June 2, 2017, 7:13 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 | « dependencies ('k') | include/AdblockPlus/JsValue.h » ('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 16 matching lines...) Expand all
27 #include <mutex> 27 #include <mutex>
28 #include <AdblockPlus/AppInfo.h> 28 #include <AdblockPlus/AppInfo.h>
29 #include <AdblockPlus/LogSystem.h> 29 #include <AdblockPlus/LogSystem.h>
30 #include <AdblockPlus/FileSystem.h> 30 #include <AdblockPlus/FileSystem.h>
31 #include <AdblockPlus/JsValue.h> 31 #include <AdblockPlus/JsValue.h>
32 #include <AdblockPlus/WebRequest.h> 32 #include <AdblockPlus/WebRequest.h>
33 #include <AdblockPlus/ITimer.h> 33 #include <AdblockPlus/ITimer.h>
34 34
35 namespace v8 35 namespace v8
36 { 36 {
37 class Arguments;
38 class Isolate; 37 class Isolate;
39 class Value; 38 class Value;
40 class Context; 39 class Context;
41 template<class T> class Handle; 40 template<typename T> class FunctionCallbackInfo;
42 typedef Handle<Value>(*InvocationCallback)(const Arguments &args); 41 typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>& info);
43 } 42 }
44 43
45 namespace AdblockPlus 44 namespace AdblockPlus
46 { 45 {
47 class JsEngine; 46 class JsEngine;
48 47
49 /** 48 /**
50 * Shared smart pointer to a `JsEngine` instance. 49 * Shared smart pointer to a `JsEngine` instance.
51 */ 50 */
52 typedef std::shared_ptr<JsEngine> JsEnginePtr; 51 typedef std::shared_ptr<JsEngine> JsEnginePtr;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 * JavaScript engine used by `FilterEngine`, wraps v8. 84 * JavaScript engine used by `FilterEngine`, wraps v8.
86 */ 85 */
87 class JsEngine : public std::enable_shared_from_this<JsEngine> 86 class JsEngine : public std::enable_shared_from_this<JsEngine>
88 { 87 {
89 friend class JsValue; 88 friend class JsValue;
90 friend class JsContext; 89 friend class JsContext;
91 90
92 struct JsWeakValuesList 91 struct JsWeakValuesList
93 { 92 {
94 ~JsWeakValuesList(); 93 ~JsWeakValuesList();
95 std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> values; 94 std::vector<v8::Global<v8::Value>> values;
96 }; 95 };
97 typedef std::list<JsWeakValuesList> JsWeakValuesLists; 96 typedef std::list<JsWeakValuesList> JsWeakValuesLists;
98 public: 97 public:
99 /** 98 /**
100 * Event callback function. 99 * Event callback function.
101 */ 100 */
102 typedef std::function<void(JsValueList&& params)> EventCallback; 101 typedef std::function<void(JsValueList&& params)> EventCallback;
103 102
104 /** 103 /**
105 * Maps events to callback functions. 104 * Maps events to callback functions.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 191
193 /** 192 /**
194 * Creates a new JavaScript object. 193 * Creates a new JavaScript object.
195 * @return New `JsValue` instance. 194 * @return New `JsValue` instance.
196 */ 195 */
197 JsValue NewObject(); 196 JsValue NewObject();
198 197
199 /** 198 /**
200 * Creates a JavaScript function that invokes a C++ callback. 199 * Creates a JavaScript function that invokes a C++ callback.
201 * @param callback C++ callback to invoke. The callback receives a 200 * @param callback C++ callback to invoke. The callback receives a
202 * `v8::Arguments` object and can use `FromArguments()` to retrieve 201 * `v8::FunctionCallbackInfo` object and can use `FromArguments()` to retrieve
203 * the current `JsEngine`. 202 * the current `JsEngine`.
204 * @return New `JsValue` instance. 203 * @return New `JsValue` instance.
205 */ 204 */
206 JsValue NewCallback(const v8::InvocationCallback& callback); 205 JsValue NewCallback(const v8::FunctionCallback& callback);
207 206
208 /** 207 /**
209 * Returns a `JsEngine` instance contained in a `v8::Arguments` object. 208 * Returns a `JsEngine` instance contained in a `v8::FunctionCallbackInfo` o bject.
210 * Use this in callbacks created via `NewCallback()` to retrieve the current 209 * Use this in callbacks created via `NewCallback()` to retrieve the current
211 * `JsEngine`. 210 * `JsEngine`.
212 * @param arguments `v8::Arguments` object containing the `JsEngine` 211 * @param arguments `v8::FunctionCallbackInfo` object containing the `JsEngi ne`
213 * instance. 212 * instance.
214 * @return `JsEngine` instance from `v8::Arguments`. 213 * @return `JsEngine` instance from `v8::FunctionCallbackInfo`.
215 */ 214 */
216 static JsEnginePtr FromArguments(const v8::Arguments& arguments); 215 static JsEnginePtr FromArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments);
217 216
218 /** 217 /**
219 * Stores `JsValue`s in a way they don't keep a strong reference to 218 * Stores `JsValue`s in a way they don't keep a strong reference to
220 * `JsEngine` and which are destroyed when `JsEngine` is destroyed. These 219 * `JsEngine` and which are destroyed when `JsEngine` is destroyed. These
221 * methods should be used when one needs to carry a JsValue in a callback 220 * methods should be used when one needs to carry a JsValue in a callback
222 * directly or indirectly passed to `JsEngine`. 221 * directly or indirectly passed to `JsEngine`.
223 * The method is thread-safe. 222 * The method is thread-safe.
224 * @param `JsValueList` to store. 223 * @param `JsValueList` to store.
225 * @return `JsWeakValuesID` of stored values which allows to restore them 224 * @return `JsWeakValuesID` of stored values which allows to restore them
226 * later. 225 * later.
227 */ 226 */
228 JsWeakValuesID StoreJsValues(const JsValueList& values); 227 JsWeakValuesID StoreJsValues(const JsValueList& values);
229 228
230 /** 229 /**
231 * Extracts and removes from `JsEngine` earlier stored `JsValue`s. 230 * Extracts and removes from `JsEngine` earlier stored `JsValue`s.
232 * The method is thread-safe. 231 * The method is thread-safe.
233 * @param id `JsWeakValuesID` of values. 232 * @param id `JsWeakValuesID` of values.
234 * @return `JsValueList` of stored values. 233 * @return `JsValueList` of stored values.
235 */ 234 */
236 JsValueList TakeJsValues(const JsWeakValuesID& id); 235 JsValueList TakeJsValues(const JsWeakValuesID& id);
237 236
238 /* 237 /*
239 * Private functionality required to implement timers. 238 * Private functionality required to implement timers.
240 * @param arguments `v8::Arguments` is the arguments received in C++ 239 * @param arguments `v8::FunctionCallbackInfo` is the arguments received in C++
241 * callback associated for global setTimeout method. 240 * callback associated for global setTimeout method.
242 */ 241 */
243 static void ScheduleTimer(const v8::Arguments& arguments); 242 static void ScheduleTimer(const v8::FunctionCallbackInfo<v8::Value>& argumen ts);
244 243
245 /* 244 /*
246 * Private functionality required to implement web requests. 245 * Private functionality required to implement web requests.
247 * @param arguments `v8::Arguments` is the arguments received in C++ 246 * @param arguments `v8::FunctionCallbackInfo` is the arguments received in C++
248 * callback associated for global GET method. 247 * callback associated for global GET method.
249 */ 248 */
250 static void ScheduleWebRequest(const v8::Arguments& arguments); 249 static void ScheduleWebRequest(const v8::FunctionCallbackInfo<v8::Value>& ar guments);
251 250
252 /** 251 /**
253 * Converts v8 arguments to `JsValue` objects. 252 * Converts v8 arguments to `JsValue` objects.
254 * @param arguments `v8::Arguments` object containing the arguments to 253 * @param arguments `v8::FunctionCallbackInfo` object containing the argumen ts to
255 * convert. 254 * convert.
256 * @return List of arguments converted to `const JsValue` objects. 255 * @return List of arguments converted to `const JsValue` objects.
257 */ 256 */
258 JsValueList ConvertArguments(const v8::Arguments& arguments); 257 JsValueList ConvertArguments(const v8::FunctionCallbackInfo<v8::Value>& argu ments);
259 258
260 /** 259 /**
261 * @see `SetFileSystem()`. 260 * @see `SetFileSystem()`.
262 */ 261 */
263 FileSystemPtr GetFileSystem() const; 262 FileSystemPtr GetFileSystem() const;
264 263
265 /** 264 /**
266 * Sets the `FileSystem` implementation used for all file I/O. 265 * Sets the `FileSystem` implementation used for all file I/O.
267 * Setting this is optional, the engine will use a `DefaultFileSystem` 266 * Setting this is optional, the engine will use a `DefaultFileSystem`
268 * instance by default, which might be sufficient. 267 * instance by default, which might be sufficient.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 explicit JsEngine(TimerPtr timer, WebRequestPtr webRequest); 317 explicit JsEngine(TimerPtr timer, WebRequestPtr webRequest);
319 318
320 JsValue GetGlobalObject(); 319 JsValue GetGlobalObject();
321 320
322 /// Isolate must be disposed only after disposing of all objects which are 321 /// Isolate must be disposed only after disposing of all objects which are
323 /// using it. 322 /// using it.
324 ScopedV8Isolate isolate; 323 ScopedV8Isolate isolate;
325 324
326 FileSystemPtr fileSystem; 325 FileSystemPtr fileSystem;
327 LogSystemPtr logSystem; 326 LogSystemPtr logSystem;
328 std::unique_ptr<v8::Persistent<v8::Context>> context; 327 std::unique_ptr<v8::Global<v8::Context>> context;
329 EventMap eventCallbacks; 328 EventMap eventCallbacks;
330 std::mutex eventCallbacksMutex; 329 std::mutex eventCallbacksMutex;
331 JsWeakValuesLists jsWeakValuesLists; 330 JsWeakValuesLists jsWeakValuesLists;
332 std::mutex jsWeakValuesListsMutex; 331 std::mutex jsWeakValuesListsMutex;
333 TimerPtr timer; 332 TimerPtr timer;
334 WebRequestPtr webRequest; 333 WebRequestPtr webRequest;
335 WebRequestSharedPtr webRequestLegacy; 334 WebRequestSharedPtr webRequestLegacy;
336 }; 335 };
337 } 336 }
338 337
339 #endif 338 #endif
OLDNEW
« no previous file with comments | « dependencies ('k') | include/AdblockPlus/JsValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld