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

Side by Side Diff: src/FileSystemJsObject.cpp

Issue 10369004: File system path resolving (Closed)
Patch Set: Created April 24, 2013, 2:10 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
« src/DefaultFileSystem.cpp ('K') | « src/DefaultFileSystem.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <AdblockPlus/JsValue.h> 6 #include <AdblockPlus/JsValue.h>
7 #include "FileSystemJsObject.h" 7 #include "FileSystemJsObject.h"
8 #include "Utils.h" 8 #include "Utils.h"
9 #include "Thread.h" 9 #include "Thread.h"
10 #include "Utils.h" 10 #include "Utils.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 JsValueList params; 177 JsValueList params;
178 params.push_back(errorValue); 178 params.push_back(errorValue);
179 callback->Call(params); 179 callback->Call(params);
180 delete this; 180 delete this;
181 } 181 }
182 182
183 private: 183 private:
184 std::string path; 184 std::string path;
185 }; 185 };
186 186
187
187 class StatThread : public IoThread 188 class StatThread : public IoThread
188 { 189 {
189 public: 190 public:
190 StatThread(JsEnginePtr jsEngine, JsValuePtr callback, 191 StatThread(JsEnginePtr jsEngine, JsValuePtr callback,
191 const std::string& path) 192 const std::string& path)
192 : IoThread(jsEngine, callback), path(path) 193 : IoThread(jsEngine, callback), path(path)
193 { 194 {
194 } 195 }
195 196
196 void Run() 197 void Run()
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 return v8::ThrowException(v8::String::New( 306 return v8::ThrowException(v8::String::New(
306 "_fileSystem.stat requires 2 parameters")); 307 "_fileSystem.stat requires 2 parameters"));
307 if (!converted[1]->IsFunction()) 308 if (!converted[1]->IsFunction())
308 return v8::ThrowException(v8::String::New( 309 return v8::ThrowException(v8::String::New(
309 "Second argument to _fileSystem.stat must be a function")); 310 "Second argument to _fileSystem.stat must be a function"));
310 StatThread* const statThread = new StatThread(jsEngine, converted[1], 311 StatThread* const statThread = new StatThread(jsEngine, converted[1],
311 converted[0]->AsString()); 312 converted[0]->AsString());
312 statThread->Start(); 313 statThread->Start();
313 return v8::Undefined(); 314 return v8::Undefined();
314 } 315 }
316
317 v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments)
318 {
319 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
320 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
321
322 if (converted.size() != 1)
323 return v8::ThrowException(v8::String::New(
324 "_fileSystem.resolve requires 1 parameter"));
325
326 std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsSt ring());
327
328 return v8::String::New(resolved.c_str(), resolved.length());
Wladimir Palant 2013/04/24 09:17:35 Please use Utils::ToV8String() here.
329 }
330
315 } 331 }
316 332
333
317 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj) 334 JsValuePtr FileSystemJsObject::Setup(JsEnginePtr jsEngine, JsValuePtr obj)
318 { 335 {
319 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback)); 336 obj->SetProperty("read", jsEngine->NewCallback(::ReadCallback));
320 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback)); 337 obj->SetProperty("write", jsEngine->NewCallback(::WriteCallback));
321 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback)); 338 obj->SetProperty("move", jsEngine->NewCallback(::MoveCallback));
322 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback)); 339 obj->SetProperty("remove", jsEngine->NewCallback(::RemoveCallback));
323 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback)); 340 obj->SetProperty("stat", jsEngine->NewCallback(::StatCallback));
341 obj->SetProperty("resolve", jsEngine->NewCallback(::ResolveCallback));
324 return obj; 342 return obj;
325 } 343 }
OLDNEW
« src/DefaultFileSystem.cpp ('K') | « src/DefaultFileSystem.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld