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

Unified Diff: src/JsEngine.cpp

Issue 10296001: Implement File API (Closed)
Patch Set: Addressed all remaining issues Created April 16, 2013, 11:55 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -2,17 +2,20 @@
#include <sstream>
#include "GlobalJsObject.h"
+#include "Utils.h"
namespace
{
v8::Handle<v8::Context> CreateContext(
- AdblockPlus::ErrorCallback& errorCallback,
- AdblockPlus::WebRequest& webRequest)
+ AdblockPlus::FileSystem& fileSystem,
+ AdblockPlus::WebRequest& webRequest,
+ AdblockPlus::ErrorCallback& errorCallback)
{
const v8::Locker locker(v8::Isolate::GetCurrent());
const v8::HandleScope handleScope;
const v8::Handle<v8::ObjectTemplate> global =
- AdblockPlus::GlobalJsObject::Create(errorCallback, webRequest);
+ AdblockPlus::GlobalJsObject::Create(fileSystem, webRequest,
+ errorCallback);
return v8::Context::New(0, global);
}
@@ -34,13 +37,6 @@
throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message());
}
- std::string Slurp(std::istream& stream)
- {
- std::stringstream content;
- content << stream.rdbuf();
- return content.str();
- }
-
std::string ExceptionToString(const v8::Handle<v8::Value> exception,
const v8::Handle<v8::Message> message)
{
@@ -63,10 +59,11 @@
{
}
-AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader,
+AdblockPlus::JsEngine::JsEngine(FileSystem* const fileSystem,
WebRequest* const webRequest,
ErrorCallback* const errorCallback)
- : fileReader(fileReader), context(CreateContext(*errorCallback, *webRequest))
+ : fileSystem(fileSystem),
+ context(CreateContext(*fileSystem, *webRequest, *errorCallback))
{
}
@@ -87,10 +84,10 @@
void AdblockPlus::JsEngine::Load(const std::string& scriptPath)
{
- const std::auto_ptr<std::istream> file = fileReader->Read(scriptPath);
- if (!*file)
+ const std::tr1::shared_ptr<std::istream> file = fileSystem->Read(scriptPath);
+ if (!file || !*file)
throw std::runtime_error("Unable to load script " + scriptPath);
- Evaluate(Slurp(*file));
+ Evaluate(Utils::Slurp(*file));
}
void AdblockPlus::JsEngine::Gc()
« src/FileSystemJsObject.cpp ('K') | « src/GlobalJsObject.cpp ('k') | src/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld