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

Delta Between Two Patch Sets: src/FileSystemJsObject.cpp

Issue 10296001: Implement File API (Closed)
Left Patch Set: Addressed all remaining issues Created April 16, 2013, 11:55 a.m.
Right Patch Set: Addressed the new issues Created April 16, 2013, 1:37 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 | « src/FileSystemJsObject.h ('k') | src/GlobalJsObject.h » ('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 #include <AdblockPlus/FileSystem.h> 1 #include <AdblockPlus/FileSystem.h>
2 #include <stdexcept> 2 #include <stdexcept>
3 #include <sstream> 3 #include <sstream>
4 #include <vector> 4 #include <vector>
5 5
6 #include "FileSystemJsObject.h" 6 #include "FileSystemJsObject.h"
7 #include "Utils.h" 7 #include "Utils.h"
8 #include "Thread.h" 8 #include "Thread.h"
9 #include "Utils.h" 9 #include "Utils.h"
10 10
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 private: 241 private:
242 std::string path; 242 std::string path;
243 }; 243 };
244 244
245 v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments) 245 v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments)
246 { 246 {
247 const v8::Handle<const v8::External> external = 247 const v8::Handle<const v8::External> external =
248 v8::Handle<const v8::External>::Cast(arguments.Data()); 248 v8::Handle<const v8::External>::Cast(arguments.Data());
249 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value()); 249 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value());
250 if (!arguments.Length() == 2) 250 if (arguments.Length() != 2)
Wladimir Palant 2013/04/16 13:03:41 Does this actually work? :) arguments.Length() !=
Felix Dahlke 2013/04/16 14:00:09 lol, yeah it does, but it sure is weird :) Fixed i
Wladimir Palant 2013/04/16 14:10:13 Weird operator precedence rules then...
251 return v8::ThrowException(v8::String::New( 251 return v8::ThrowException(v8::String::New(
252 "_fileSystem.read requires 2 parameters")); 252 "_fileSystem.read requires 2 parameters"));
253 const std::string path = Utils::FromV8String(arguments[0]); 253 const std::string path = Utils::FromV8String(arguments[0]);
254 v8::Handle<v8::Value> callbackValue = arguments[1]; 254 v8::Handle<v8::Value> callbackValue = arguments[1];
255 if (!callbackValue->IsFunction()) 255 if (!callbackValue->IsFunction())
256 return v8::ThrowException(v8::String::New( 256 return v8::ThrowException(v8::String::New(
257 "Second argument to _fileSystem.read must be a function")); 257 "Second argument to _fileSystem.read must be a function"));
258 v8::Handle<v8::Function> callback = 258 v8::Handle<v8::Function> callback =
259 v8::Handle<v8::Function>::Cast(callbackValue); 259 v8::Handle<v8::Function>::Cast(callbackValue);
260 ReadThread* const readThread = new ReadThread(*fileSystem, callback, path); 260 ReadThread* const readThread = new ReadThread(*fileSystem, callback, path);
261 readThread->Start(); 261 readThread->Start();
262 return v8::Undefined(); 262 return v8::Undefined();
263 } 263 }
264 264
265 v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments) 265 v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments)
266 { 266 {
267 const v8::Handle<const v8::External> external = 267 const v8::Handle<const v8::External> external =
268 v8::Handle<const v8::External>::Cast(arguments.Data()); 268 v8::Handle<const v8::External>::Cast(arguments.Data());
269 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value()); 269 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value());
270 if (!arguments.Length() == 3) 270 if (arguments.Length() != 3)
271 return v8::ThrowException(v8::String::New( 271 return v8::ThrowException(v8::String::New(
272 "_fileSystem.write requires 3 parameters")); 272 "_fileSystem.write requires 3 parameters"));
273 const std::string path = Utils::FromV8String(arguments[0]); 273 const std::string path = Utils::FromV8String(arguments[0]);
274 const std::string content = Utils::FromV8String(arguments[1]); 274 const std::string content = Utils::FromV8String(arguments[1]);
275 v8::Handle<v8::Value> callbackValue = arguments[2]; 275 v8::Handle<v8::Value> callbackValue = arguments[2];
276 if (!callbackValue->IsFunction()) 276 if (!callbackValue->IsFunction())
277 return v8::ThrowException(v8::String::New( 277 return v8::ThrowException(v8::String::New(
278 "Third argument to _fileSystem.write must be a function")); 278 "Third argument to _fileSystem.write must be a function"));
279 v8::Handle<v8::Function> callback = 279 v8::Handle<v8::Function> callback =
280 v8::Handle<v8::Function>::Cast(callbackValue); 280 v8::Handle<v8::Function>::Cast(callbackValue);
281 WriteThread* const writeThread = new WriteThread(*fileSystem, callback, 281 WriteThread* const writeThread = new WriteThread(*fileSystem, callback,
282 path, content); 282 path, content);
283 writeThread->Start(); 283 writeThread->Start();
284 return v8::Undefined(); 284 return v8::Undefined();
285 } 285 }
286 286
287 v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments) 287 v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments)
288 { 288 {
289 const v8::Handle<const v8::External> external = 289 const v8::Handle<const v8::External> external =
290 v8::Handle<const v8::External>::Cast(arguments.Data()); 290 v8::Handle<const v8::External>::Cast(arguments.Data());
291 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value()); 291 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value());
292 if (!arguments.Length() == 3) 292 if (arguments.Length() != 3)
293 return v8::ThrowException(v8::String::New( 293 return v8::ThrowException(v8::String::New(
294 "_fileSystem.move requires 3 parameters")); 294 "_fileSystem.move requires 3 parameters"));
295 const std::string fromPath = Utils::FromV8String(arguments[0]); 295 const std::string fromPath = Utils::FromV8String(arguments[0]);
296 const std::string toPath = Utils::FromV8String(arguments[1]); 296 const std::string toPath = Utils::FromV8String(arguments[1]);
297 v8::Handle<v8::Value> callbackValue = arguments[2]; 297 v8::Handle<v8::Value> callbackValue = arguments[2];
298 if (!callbackValue->IsFunction()) 298 if (!callbackValue->IsFunction())
299 return v8::ThrowException(v8::String::New( 299 return v8::ThrowException(v8::String::New(
300 "Third argument to _fileSystem.move must be a function")); 300 "Third argument to _fileSystem.move must be a function"));
301 v8::Handle<v8::Function> callback = 301 v8::Handle<v8::Function> callback =
302 v8::Handle<v8::Function>::Cast(callbackValue); 302 v8::Handle<v8::Function>::Cast(callbackValue);
303 MoveThread* const moveThread = new MoveThread(*fileSystem, callback, 303 MoveThread* const moveThread = new MoveThread(*fileSystem, callback,
304 fromPath, toPath); 304 fromPath, toPath);
305 moveThread->Start(); 305 moveThread->Start();
306 return v8::Undefined(); 306 return v8::Undefined();
307 } 307 }
308 308
309 v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments) 309 v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments)
310 { 310 {
311 const v8::Handle<const v8::External> external = 311 const v8::Handle<const v8::External> external =
312 v8::Handle<const v8::External>::Cast(arguments.Data()); 312 v8::Handle<const v8::External>::Cast(arguments.Data());
313 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value()); 313 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value());
314 if (!arguments.Length() == 2) 314 if (arguments.Length() != 2)
315 return v8::ThrowException(v8::String::New( 315 return v8::ThrowException(v8::String::New(
316 "_fileSystem.remove requires 2 parameters")); 316 "_fileSystem.remove requires 2 parameters"));
317 const std::string path = Utils::FromV8String(arguments[0]); 317 const std::string path = Utils::FromV8String(arguments[0]);
318 v8::Handle<v8::Value> callbackValue = arguments[1]; 318 v8::Handle<v8::Value> callbackValue = arguments[1];
319 if (!callbackValue->IsFunction()) 319 if (!callbackValue->IsFunction())
320 return v8::ThrowException(v8::String::New( 320 return v8::ThrowException(v8::String::New(
321 "Second argument to _fileSystem.remove must be a function")); 321 "Second argument to _fileSystem.remove must be a function"));
322 v8::Handle<v8::Function> callback = 322 v8::Handle<v8::Function> callback =
323 v8::Handle<v8::Function>::Cast(callbackValue); 323 v8::Handle<v8::Function>::Cast(callbackValue);
324 RemoveThread* const removeThread = new RemoveThread(*fileSystem, callback, 324 RemoveThread* const removeThread = new RemoveThread(*fileSystem, callback,
325 path); 325 path);
326 removeThread->Start(); 326 removeThread->Start();
327 return v8::Undefined(); 327 return v8::Undefined();
328 } 328 }
329 329
330 v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments) 330 v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments)
331 { 331 {
332 const v8::Handle<const v8::External> external = 332 const v8::Handle<const v8::External> external =
333 v8::Handle<const v8::External>::Cast(arguments.Data()); 333 v8::Handle<const v8::External>::Cast(arguments.Data());
334 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value()); 334 FileSystem* const fileSystem = static_cast<FileSystem*>(external->Value());
335 if (!arguments.Length() == 2) 335 if (arguments.Length() != 2)
336 return v8::ThrowException(v8::String::New( 336 return v8::ThrowException(v8::String::New(
337 "_fileSystem.stat requires 2 parameters")); 337 "_fileSystem.stat requires 2 parameters"));
338 const std::string path = Utils::FromV8String(arguments[0]); 338 const std::string path = Utils::FromV8String(arguments[0]);
339 v8::Handle<v8::Value> callbackValue = arguments[1]; 339 v8::Handle<v8::Value> callbackValue = arguments[1];
340 if (!callbackValue->IsFunction()) 340 if (!callbackValue->IsFunction())
341 return v8::ThrowException(v8::String::New( 341 return v8::ThrowException(v8::String::New(
342 "Second argument to _fileSystem.stat must be a function")); 342 "Second argument to _fileSystem.stat must be a function"));
343 v8::Handle<v8::Function> callback = 343 v8::Handle<v8::Function> callback =
344 v8::Handle<v8::Function>::Cast(callbackValue); 344 v8::Handle<v8::Function>::Cast(callbackValue);
345 StatThread* const statThread = new StatThread(*fileSystem, callback, path); 345 StatThread* const statThread = new StatThread(*fileSystem, callback, path);
(...skipping 15 matching lines...) Expand all
361 file->Set(v8::String::New("write"), 361 file->Set(v8::String::New("write"),
362 v8::FunctionTemplate::New(WriteCallback, fileSystemExternal)); 362 v8::FunctionTemplate::New(WriteCallback, fileSystemExternal));
363 file->Set(v8::String::New("move"), 363 file->Set(v8::String::New("move"),
364 v8::FunctionTemplate::New(MoveCallback, fileSystemExternal)); 364 v8::FunctionTemplate::New(MoveCallback, fileSystemExternal));
365 file->Set(v8::String::New("remove"), 365 file->Set(v8::String::New("remove"),
366 v8::FunctionTemplate::New(RemoveCallback, fileSystemExternal)); 366 v8::FunctionTemplate::New(RemoveCallback, fileSystemExternal));
367 file->Set(v8::String::New("stat"), 367 file->Set(v8::String::New("stat"),
368 v8::FunctionTemplate::New(StatCallback, fileSystemExternal)); 368 v8::FunctionTemplate::New(StatCallback, fileSystemExternal));
369 return handleScope.Close(file); 369 return handleScope.Close(file);
370 } 370 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld