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

Unified Diff: src/JsEngine.cpp

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Patch Set: Created April 12, 2013, 2:55 p.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
@@ -65,29 +65,28 @@ AdblockPlus::JsError::JsError(const v8::
AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader,
WebRequest* const webRequest,
ErrorCallback* const errorCallback)
: fileReader(fileReader), context(CreateContext(*errorCallback, *webRequest))
{
}
-std::string AdblockPlus::JsEngine::Evaluate(const std::string& source,
+AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& source,
const std::string& filename)
{
const v8::Locker locker(v8::Isolate::GetCurrent());
const v8::HandleScope handleScope;
const v8::Context::Scope contextScope(context);
const v8::TryCatch tryCatch;
const v8::Handle<v8::Script> script = CompileScript(source, filename);
CheckTryCatch(tryCatch);
v8::Local<v8::Value> result = script->Run();
CheckTryCatch(tryCatch);
- v8::String::Utf8Value resultString(result);
- return std::string(*resultString);
+ return JsValuePtr(new JsValue(v8::Isolate::GetCurrent(), context, result));
}
void AdblockPlus::JsEngine::Load(const std::string& scriptPath)
{
const std::auto_ptr<std::istream> file = fileReader->Read(scriptPath);
if (!*file)
throw std::runtime_error("Unable to load script " + scriptPath);
Evaluate(Slurp(*file));
« include/AdblockPlus/JsValue.h ('K') | « libadblockplus.gyp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld