| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 
| 3  * Copyright (C) 2006-2014 Eyeo GmbH | 3  * Copyright (C) 2006-2014 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 244 | 244 | 
| 245   private: | 245   private: | 
| 246     std::string path; | 246     std::string path; | 
| 247   }; | 247   }; | 
| 248 | 248 | 
| 249   v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments) | 249   v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments) | 
| 250   { | 250   { | 
| 251     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 251     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 
| 252     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 252     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 
| 253 | 253 | 
|  | 254     v8::Isolate* isolate = arguments.GetIsolate(); | 
| 254     if (converted.size() != 2) | 255     if (converted.size() != 2) | 
| 255       return v8::ThrowException(v8::String::New( | 256       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 256         "_fileSystem.read requires 2 parameters")); | 257         "_fileSystem.read requires 2 parameters")); | 
| 257     if (!converted[1]->IsFunction()) | 258     if (!converted[1]->IsFunction()) | 
| 258       return v8::ThrowException(v8::String::New( | 259       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 259         "Second argument to _fileSystem.read must be a function")); | 260         "Second argument to _fileSystem.read must be a function")); | 
| 260     ReadThread* const readThread = new ReadThread(jsEngine, converted[1], | 261     ReadThread* const readThread = new ReadThread(jsEngine, converted[1], | 
| 261         converted[0]->AsString()); | 262         converted[0]->AsString()); | 
| 262     readThread->Start(); | 263     readThread->Start(); | 
| 263     return v8::Undefined(); | 264     return v8::Undefined(); | 
| 264   } | 265   } | 
| 265 | 266 | 
| 266   v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments) | 267   v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments) | 
| 267   { | 268   { | 
| 268     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 269     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 
| 269     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 270     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 
| 270 | 271 | 
|  | 272     v8::Isolate* isolate = arguments.GetIsolate(); | 
| 271     if (converted.size() != 3) | 273     if (converted.size() != 3) | 
| 272       return v8::ThrowException(v8::String::New( | 274       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 273         "_fileSystem.write requires 3 parameters")); | 275         "_fileSystem.write requires 3 parameters")); | 
| 274     if (!converted[2]->IsFunction()) | 276     if (!converted[2]->IsFunction()) | 
| 275       return v8::ThrowException(v8::String::New( | 277       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 276         "Third argument to _fileSystem.write must be a function")); | 278         "Third argument to _fileSystem.write must be a function")); | 
| 277     WriteThread* const writeThread = new WriteThread(jsEngine, converted[2], | 279     WriteThread* const writeThread = new WriteThread(jsEngine, converted[2], | 
| 278         converted[0]->AsString(), converted[1]->AsString()); | 280         converted[0]->AsString(), converted[1]->AsString()); | 
| 279     writeThread->Start(); | 281     writeThread->Start(); | 
| 280     return v8::Undefined(); | 282     return v8::Undefined(); | 
| 281   } | 283   } | 
| 282 | 284 | 
| 283   v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments) | 285   v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments) | 
| 284   { | 286   { | 
| 285     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 287     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 
| 286     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 288     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 
| 287 | 289 | 
|  | 290     v8::Isolate* isolate = arguments.GetIsolate(); | 
| 288     if (converted.size() != 3) | 291     if (converted.size() != 3) | 
| 289       return v8::ThrowException(v8::String::New( | 292       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 290         "_fileSystem.move requires 3 parameters")); | 293         "_fileSystem.move requires 3 parameters")); | 
| 291     if (!converted[2]->IsFunction()) | 294     if (!converted[2]->IsFunction()) | 
| 292       return v8::ThrowException(v8::String::New( | 295       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 293         "Third argument to _fileSystem.move must be a function")); | 296         "Third argument to _fileSystem.move must be a function")); | 
| 294     MoveThread* const moveThread = new MoveThread(jsEngine, converted[2], | 297     MoveThread* const moveThread = new MoveThread(jsEngine, converted[2], | 
| 295         converted[0]->AsString(), converted[1]->AsString()); | 298         converted[0]->AsString(), converted[1]->AsString()); | 
| 296     moveThread->Start(); | 299     moveThread->Start(); | 
| 297     return v8::Undefined(); | 300     return v8::Undefined(); | 
| 298   } | 301   } | 
| 299 | 302 | 
| 300   v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments) | 303   v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments) | 
| 301   { | 304   { | 
| 302     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 305     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 
| 303     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 306     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 
| 304 | 307 | 
|  | 308     v8::Isolate* isolate = arguments.GetIsolate(); | 
| 305     if (converted.size() != 2) | 309     if (converted.size() != 2) | 
| 306       return v8::ThrowException(v8::String::New( | 310       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 307         "_fileSystem.remove requires 2 parameters")); | 311         "_fileSystem.remove requires 2 parameters")); | 
| 308     if (!converted[1]->IsFunction()) | 312     if (!converted[1]->IsFunction()) | 
| 309       return v8::ThrowException(v8::String::New( | 313       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 310         "Second argument to _fileSystem.remove must be a function")); | 314         "Second argument to _fileSystem.remove must be a function")); | 
| 311     RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1], | 315     RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1], | 
| 312         converted[0]->AsString()); | 316         converted[0]->AsString()); | 
| 313     removeThread->Start(); | 317     removeThread->Start(); | 
| 314     return v8::Undefined(); | 318     return v8::Undefined(); | 
| 315   } | 319   } | 
| 316 | 320 | 
| 317   v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments) | 321   v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments) | 
| 318   { | 322   { | 
| 319     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 323     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 
| 320     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 324     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 
| 321 | 325 | 
|  | 326     v8::Isolate* isolate = arguments.GetIsolate(); | 
| 322     if (converted.size() != 2) | 327     if (converted.size() != 2) | 
| 323       return v8::ThrowException(v8::String::New( | 328       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 324         "_fileSystem.stat requires 2 parameters")); | 329         "_fileSystem.stat requires 2 parameters")); | 
| 325     if (!converted[1]->IsFunction()) | 330     if (!converted[1]->IsFunction()) | 
| 326       return v8::ThrowException(v8::String::New( | 331       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 327         "Second argument to _fileSystem.stat must be a function")); | 332         "Second argument to _fileSystem.stat must be a function")); | 
| 328     StatThread* const statThread = new StatThread(jsEngine, converted[1], | 333     StatThread* const statThread = new StatThread(jsEngine, converted[1], | 
| 329         converted[0]->AsString()); | 334         converted[0]->AsString()); | 
| 330     statThread->Start(); | 335     statThread->Start(); | 
| 331     return v8::Undefined(); | 336     return v8::Undefined(); | 
| 332   } | 337   } | 
| 333 | 338 | 
| 334   v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments) | 339   v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments) | 
| 335   { | 340   { | 
| 336     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 341     AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
     uments); | 
| 337     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 342     AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 
| 338 | 343 | 
|  | 344     v8::Isolate* isolate = arguments.GetIsolate(); | 
| 339     if (converted.size() != 1) | 345     if (converted.size() != 1) | 
| 340       return v8::ThrowException(v8::String::New( | 346       return v8::ThrowException(Utils::ToV8String(isolate, | 
| 341         "_fileSystem.resolve requires 1 parameter")); | 347         "_fileSystem.resolve requires 1 parameter")); | 
| 342 | 348 | 
| 343     std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsSt
     ring()); | 349     std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsSt
     ring()); | 
| 344 | 350 | 
| 345     return Utils::ToV8String(resolved); | 351     return Utils::ToV8String(isolate, resolved); | 
| 346   } | 352   } | 
| 347 | 353 | 
| 348 } | 354 } | 
| 349 | 355 | 
| 350 | 356 | 
| 351 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) | 357 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) | 
| 352 { | 358 { | 
| 353   obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); | 359   obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); | 
| 354   obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); | 360   obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); | 
| 355   obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); | 361   obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); | 
| 356   obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); | 362   obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); | 
| 357   obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); | 363   obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); | 
| 358   obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); | 364   obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback)); | 
| 359   return obj; | 365   return obj; | 
| 360 } | 366 } | 
| OLD | NEW | 
|---|