Index: src/JsEngine.cpp |
=================================================================== |
--- a/src/JsEngine.cpp |
+++ b/src/JsEngine.cpp |
@@ -15,32 +15,48 @@ 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(); |
} |
} |
-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(toString(exception, message)) |
{ |
} |
+std::string AdblockPlus::JsError::toString(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::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) |
Evaluate(jsSources[i + 1], jsSources[i]); |
} |