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

Unified Diff: src/JsEngine.cpp

Issue 9884006: Add file name and line number when reporting exceptions (Closed)
Patch Set: Now with free functions Created March 15, 2013, 3:38 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
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -15,29 +15,45 @@ namespace
global->Set(v8::String::New("console"),
AdblockPlus::ConsoleJsObject::Create(errorCallback));
return v8::Context::New(0, global);
}
void CheckTryCatch(const v8::TryCatch& tryCatch)
{
if (tryCatch.HasCaught())
- throw AdblockPlus::JsError(tryCatch.Exception());
+ 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)
+ {
+ std::stringstream error;
+ error << *v8::String::Utf8Value(exception);
+ if (!message.IsEmpty())
+ {
+ error << " at ";
+ error << *v8::String::Utf8Value(message->GetScriptResourceName());
+ error << ":";
+ error << message->GetLineNumber();
+ }
+ return error.str();
+ }
}
-AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception)
- : std::runtime_error(*v8::String::AsciiValue(exception))
+AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception,
+ const v8::Handle<v8::Message> message)
+ : std::runtime_error(ExceptionToString(exception, message))
{
}
AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader,
ErrorCallback* const errorCallback)
: fileReader(fileReader), context(CreateContext(*errorCallback))
{
for (int i = 0; jsSources[i] && jsSources[i + 1]; i += 2)
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld