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

Side by Side Diff: src/FileSystemJsObject.cpp

Issue 6193234183192576: Issue 1197 - change local copy of v8 (to 4.3.15) to work with Visual Studio 2013 (Closed)
Patch Set: rebase and update Created May 17, 2016, 3:18 p.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 | « src/ConsoleJsObject.cpp ('k') | src/GlobalJsObject.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-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
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 31
31 namespace 32 namespace
32 { 33 {
33 class IoThread : public Thread 34 class IoThread : public Thread
34 { 35 {
35 public: 36 public:
36 IoThread(JsEnginePtr jsEngine, JsValuePtr callback) 37 IoThread(JsEnginePtr jsEngine, JsValuePtr callback)
37 : jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()), 38 : jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()),
38 callback(callback) 39 callback(callback)
39 { 40 {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 JsValueList params; 240 JsValueList params;
240 params.push_back(result); 241 params.push_back(result);
241 callback->Call(params); 242 callback->Call(params);
242 delete this; 243 delete this;
243 } 244 }
244 245
245 private: 246 private:
246 std::string path; 247 std::string path;
247 }; 248 };
248 249
249 v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments) 250 void ReadCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
250 { 251 {
251 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 252 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
252 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 253 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
253 254
254 v8::Isolate* isolate = arguments.GetIsolate(); 255 v8::Isolate* isolate = arguments.GetIsolate();
255 if (converted.size() != 2) 256 if (converted.size() != 2)
256 return v8::ThrowException(Utils::ToV8String(isolate, 257 return ThrowException(isolate, "_fileSystem.read requires 2 parameters");
257 "_fileSystem.read requires 2 parameters"));
258 if (!converted[1]->IsFunction()) 258 if (!converted[1]->IsFunction())
259 return v8::ThrowException(Utils::ToV8String(isolate, 259 return ThrowException(isolate, "Second argument to _fileSystem.read must b e a function");
260 "Second argument to _fileSystem.read must be a function"));
261 ReadThread* const readThread = new ReadThread(jsEngine, converted[1], 260 ReadThread* const readThread = new ReadThread(jsEngine, converted[1],
262 converted[0]->AsString()); 261 converted[0]->AsString());
263 readThread->Start(); 262 readThread->Start();
264 return v8::Undefined();
265 } 263 }
266 264
267 v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments) 265 void WriteCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
268 { 266 {
269 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 267 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
270 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 268 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
271 269
272 v8::Isolate* isolate = arguments.GetIsolate(); 270 v8::Isolate* isolate = arguments.GetIsolate();
273 if (converted.size() != 3) 271 if (converted.size() != 3)
274 return v8::ThrowException(Utils::ToV8String(isolate, 272 return ThrowException(isolate, "_fileSystem.write requires 3 parameters");
275 "_fileSystem.write requires 3 parameters"));
276 if (!converted[2]->IsFunction()) 273 if (!converted[2]->IsFunction())
277 return v8::ThrowException(Utils::ToV8String(isolate, 274 return ThrowException(isolate, "Third argument to _fileSystem.write must b e a function");
278 "Third argument to _fileSystem.write must be a function"));
279 WriteThread* const writeThread = new WriteThread(jsEngine, converted[2], 275 WriteThread* const writeThread = new WriteThread(jsEngine, converted[2],
280 converted[0]->AsString(), converted[1]->AsString()); 276 converted[0]->AsString(), converted[1]->AsString());
281 writeThread->Start(); 277 writeThread->Start();
282 return v8::Undefined();
283 } 278 }
284 279
285 v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments) 280 void MoveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
286 { 281 {
287 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 282 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
288 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 283 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
289 284
290 v8::Isolate* isolate = arguments.GetIsolate(); 285 v8::Isolate* isolate = arguments.GetIsolate();
291 if (converted.size() != 3) 286 if (converted.size() != 3)
292 return v8::ThrowException(Utils::ToV8String(isolate, 287 return ThrowException(isolate, "_fileSystem.move requires 3 parameters");
293 "_fileSystem.move requires 3 parameters"));
294 if (!converted[2]->IsFunction()) 288 if (!converted[2]->IsFunction())
295 return v8::ThrowException(Utils::ToV8String(isolate, 289 return ThrowException(isolate, "Third argument to _fileSystem.move must be a function");
296 "Third argument to _fileSystem.move must be a function"));
297 MoveThread* const moveThread = new MoveThread(jsEngine, converted[2], 290 MoveThread* const moveThread = new MoveThread(jsEngine, converted[2],
298 converted[0]->AsString(), converted[1]->AsString()); 291 converted[0]->AsString(), converted[1]->AsString());
299 moveThread->Start(); 292 moveThread->Start();
300 return v8::Undefined();
301 } 293 }
302 294
303 v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments) 295 void RemoveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
304 { 296 {
305 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 297 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
306 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 298 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
307 299
308 v8::Isolate* isolate = arguments.GetIsolate(); 300 v8::Isolate* isolate = arguments.GetIsolate();
309 if (converted.size() != 2) 301 if (converted.size() != 2)
310 return v8::ThrowException(Utils::ToV8String(isolate, 302 return ThrowException(isolate, "_fileSystem.remove requires 2 parameters") ;
311 "_fileSystem.remove requires 2 parameters"));
312 if (!converted[1]->IsFunction()) 303 if (!converted[1]->IsFunction())
313 return v8::ThrowException(Utils::ToV8String(isolate, 304 return ThrowException(isolate, "Second argument to _fileSystem.remove must be a function");
314 "Second argument to _fileSystem.remove must be a function"));
315 RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1], 305 RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1],
316 converted[0]->AsString()); 306 converted[0]->AsString());
317 removeThread->Start(); 307 removeThread->Start();
318 return v8::Undefined();
319 } 308 }
320 309
321 v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments) 310 void StatCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
322 { 311 {
323 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 312 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
324 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 313 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
325 314
326 v8::Isolate* isolate = arguments.GetIsolate(); 315 v8::Isolate* isolate = arguments.GetIsolate();
327 if (converted.size() != 2) 316 if (converted.size() != 2)
328 return v8::ThrowException(Utils::ToV8String(isolate, 317 return ThrowException(isolate, "_fileSystem.stat requires 2 parameters");
329 "_fileSystem.stat requires 2 parameters"));
330 if (!converted[1]->IsFunction()) 318 if (!converted[1]->IsFunction())
331 return v8::ThrowException(Utils::ToV8String(isolate, 319 return ThrowException(isolate, "Second argument to _fileSystem.stat must b e a function");
332 "Second argument to _fileSystem.stat must be a function"));
333 StatThread* const statThread = new StatThread(jsEngine, converted[1], 320 StatThread* const statThread = new StatThread(jsEngine, converted[1],
334 converted[0]->AsString()); 321 converted[0]->AsString());
335 statThread->Start(); 322 statThread->Start();
336 return v8::Undefined();
337 } 323 }
338 324
339 v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments) 325 void ResolveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
340 { 326 {
341 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 327 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
342 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 328 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
343 329
344 v8::Isolate* isolate = arguments.GetIsolate(); 330 v8::Isolate* isolate = arguments.GetIsolate();
345 if (converted.size() != 1) 331 if (converted.size() != 1)
346 return v8::ThrowException(Utils::ToV8String(isolate, 332 return ThrowException(isolate, "_fileSystem.resolve requires 1 parameter") ;
347 "_fileSystem.resolve requires 1 parameter"));
348 333
349 std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsSt ring()); 334 std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsSt ring());
350 335 arguments.GetReturnValue().Set(Utils::ToV8String(isolate, resolved));
351 return Utils::ToV8String(isolate, resolved);
352 } 336 }
353
354 } 337 }
355 338
356 339
357 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) 340 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj)
358 { 341 {
359 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); 342 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback));
360 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); 343 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback));
361 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); 344 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback));
362 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); 345 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback));
363 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); 346 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback));
364 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); 347 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback));
365 return obj; 348 return obj;
366 } 349 }
OLDNEW
« no previous file with comments | « src/ConsoleJsObject.cpp ('k') | src/GlobalJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld