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

Delta Between Two Patch Sets: src/FileSystemJsObject.cpp

Issue 29451722: Issue 4907 - Update v8 to 5.7.278 in libadblockplus (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Left Patch Set: Created May 30, 2017, 3:02 p.m.
Right Patch Set: independence from file mode of make_gyp_wrapper.py Created July 4, 2017, 11:11 a.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 | « src/ConsoleJsObject.cpp ('k') | src/GlobalJsObject.cpp » ('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-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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus/FileSystem.h> 18 #include <AdblockPlus/FileSystem.h>
19 #include <stdexcept> 19 #include <stdexcept>
20 #include <sstream> 20 #include <sstream>
21 #include <vector> 21 #include <vector>
22 22
23 #include <AdblockPlus/JsValue.h> 23 #include <AdblockPlus/JsValue.h>
24 #include "FileSystemJsObject.h" 24 #include "FileSystemJsObject.h"
25 #include "JsContext.h" 25 #include "JsContext.h"
26 #include "Thread.h" 26 #include "Thread.h"
27 #include "Utils.h" 27 #include "Utils.h"
28 28
29 using namespace AdblockPlus; 29 using namespace AdblockPlus;
30 using AdblockPlus::Utils::ThrowException; 30 using AdblockPlus::Utils::ThrowExceptionInJS;
31 31
32 namespace 32 namespace
33 { 33 {
34 class IoThread : public Thread 34 class IoThread : public Thread
35 { 35 {
36 public: 36 public:
37 IoThread(const JsEnginePtr& jsEngine, const JsValue& callback) 37 IoThread(const JsEnginePtr& jsEngine, const JsValue& callback)
38 : Thread(true), jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()), 38 : Thread(true), jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()),
39 callback(callback) 39 callback(callback)
40 { 40 {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 std::string path; 242 std::string path;
243 }; 243 };
244 244
245 void ReadCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 245 void ReadCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
246 { 246 {
247 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 247 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
248 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 248 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
249 249
250 v8::Isolate* isolate = arguments.GetIsolate(); 250 v8::Isolate* isolate = arguments.GetIsolate();
251 if (converted.size() != 2) 251 if (converted.size() != 2)
252 return ThrowException(isolate, "_fileSystem.read requires 2 parameters"); 252 return ThrowExceptionInJS(isolate, "_fileSystem.read requires 2 parameters ");
253 if (!converted[1].IsFunction()) 253 if (!converted[1].IsFunction())
254 return ThrowException(isolate, "Second argument to _fileSystem.read must b e a function"); 254 return ThrowExceptionInJS(isolate, "Second argument to _fileSystem.read mu st be a function");
255 ReadThread* const readThread = new ReadThread(jsEngine, converted[1], 255 ReadThread* const readThread = new ReadThread(jsEngine, converted[1],
256 converted[0].AsString()); 256 converted[0].AsString());
257 readThread->Start(); 257 readThread->Start();
258 } 258 }
259 259
260 void WriteCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 260 void WriteCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
261 { 261 {
262 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 262 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
263 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 263 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
264 264
265 v8::Isolate* isolate = arguments.GetIsolate(); 265 v8::Isolate* isolate = arguments.GetIsolate();
266 if (converted.size() != 3) 266 if (converted.size() != 3)
267 return ThrowException(isolate, "_fileSystem.write requires 3 parameters"); 267 return ThrowExceptionInJS(isolate, "_fileSystem.write requires 3 parameter s");
268 if (!converted[2].IsFunction()) 268 if (!converted[2].IsFunction())
269 return ThrowException(isolate, "Third argument to _fileSystem.write must b e a function"); 269 return ThrowExceptionInJS(isolate, "Third argument to _fileSystem.write mu st be a function");
270 WriteThread* const writeThread = new WriteThread(jsEngine, converted[2], 270 WriteThread* const writeThread = new WriteThread(jsEngine, converted[2],
271 converted[0].AsString(), converted[1].AsString()); 271 converted[0].AsString(), converted[1].AsString());
272 writeThread->Start(); 272 writeThread->Start();
273 } 273 }
274 274
275 void MoveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 275 void MoveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
276 { 276 {
277 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 277 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
278 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 278 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
279 279
280 v8::Isolate* isolate = arguments.GetIsolate(); 280 v8::Isolate* isolate = arguments.GetIsolate();
281 if (converted.size() != 3) 281 if (converted.size() != 3)
282 return ThrowException(isolate, "_fileSystem.move requires 3 parameters"); 282 return ThrowExceptionInJS(isolate, "_fileSystem.move requires 3 parameters ");
283 if (!converted[2].IsFunction()) 283 if (!converted[2].IsFunction())
284 return ThrowException(isolate, "Third argument to _fileSystem.move must be a function"); 284 return ThrowExceptionInJS(isolate, "Third argument to _fileSystem.move mus t be a function");
285 MoveThread* const moveThread = new MoveThread(jsEngine, converted[2], 285 MoveThread* const moveThread = new MoveThread(jsEngine, converted[2],
286 converted[0].AsString(), converted[1].AsString()); 286 converted[0].AsString(), converted[1].AsString());
287 moveThread->Start(); 287 moveThread->Start();
288 } 288 }
289 289
290 void RemoveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 290 void RemoveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
291 { 291 {
292 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 292 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
293 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 293 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
294 294
295 v8::Isolate* isolate = arguments.GetIsolate(); 295 v8::Isolate* isolate = arguments.GetIsolate();
296 if (converted.size() != 2) 296 if (converted.size() != 2)
297 return ThrowException(isolate, "_fileSystem.remove requires 2 parameters") ; 297 return ThrowExceptionInJS(isolate, "_fileSystem.remove requires 2 paramete rs");
298 if (!converted[1].IsFunction()) 298 if (!converted[1].IsFunction())
299 return ThrowException(isolate, "Second argument to _fileSystem.remove must be a function"); 299 return ThrowExceptionInJS(isolate, "Second argument to _fileSystem.remove must be a function");
300 RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1], 300 RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1],
301 converted[0].AsString()); 301 converted[0].AsString());
302 removeThread->Start(); 302 removeThread->Start();
303 } 303 }
304 304
305 void StatCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 305 void StatCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
306 { 306 {
307 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 307 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
308 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 308 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
309 309
310 v8::Isolate* isolate = arguments.GetIsolate(); 310 v8::Isolate* isolate = arguments.GetIsolate();
311 if (converted.size() != 2) 311 if (converted.size() != 2)
312 return ThrowException(isolate, "_fileSystem.stat requires 2 parameters"); 312 return ThrowExceptionInJS(isolate, "_fileSystem.stat requires 2 parameters ");
313 if (!converted[1].IsFunction()) 313 if (!converted[1].IsFunction())
314 return ThrowException(isolate, "Second argument to _fileSystem.stat must b e a function"); 314 return ThrowExceptionInJS(isolate, "Second argument to _fileSystem.stat mu st be a function");
315 StatThread* const statThread = new StatThread(jsEngine, converted[1], 315 StatThread* const statThread = new StatThread(jsEngine, converted[1],
316 converted[0].AsString()); 316 converted[0].AsString());
317 statThread->Start(); 317 statThread->Start();
318 } 318 }
319 319
320 void ResolveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 320 void ResolveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
321 { 321 {
322 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 322 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
323 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 323 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
324 324
325 v8::Isolate* isolate = arguments.GetIsolate(); 325 v8::Isolate* isolate = arguments.GetIsolate();
326 if (converted.size() != 1) 326 if (converted.size() != 1)
327 return ThrowException(isolate, "_fileSystem.resolve requires 1 parameter") ; 327 return ThrowExceptionInJS(isolate, "_fileSystem.resolve requires 1 paramet er");
328 328
329 std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0].AsStr ing()); 329 std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0].AsStr ing());
330 arguments.GetReturnValue().Set(Utils::ToV8String(isolate, resolved)); 330 arguments.GetReturnValue().Set(Utils::ToV8String(isolate, resolved));
331 } 331 }
332 } 332 }
333 333
334 334
335 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj) 335 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj)
336 { 336 {
337 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback)); 337 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback));
338 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback)); 338 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback));
339 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback)); 339 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback));
340 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback)); 340 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback));
341 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback)); 341 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback));
342 obj.SetProperty("resolve", jsEngine.NewCallback(::ResolveCallback)); 342 obj.SetProperty("resolve", jsEngine.NewCallback(::ResolveCallback));
343 return obj; 343 return obj;
344 } 344 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld