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

Delta Between Two Patch Sets: src/JsEngine.cpp

Issue 9884006: Add file name and line number when reporting exceptions (Closed)
Left Patch Set: Created March 15, 2013, 3:26 p.m.
Right Patch Set: Now with free functions Created March 15, 2013, 3:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « include/AdblockPlus/JsEngine.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <sstream> 2 #include <sstream>
3 3
4 #include "ConsoleJsObject.h" 4 #include "ConsoleJsObject.h"
5 5
6 extern const char* jsSources[]; 6 extern const char* jsSources[];
7 7
8 namespace 8 namespace
9 { 9 {
10 v8::Handle<v8::Context> CreateContext( 10 v8::Handle<v8::Context> CreateContext(
(...skipping 11 matching lines...) Expand all
22 if (tryCatch.HasCaught()) 22 if (tryCatch.HasCaught())
23 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); 23 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message());
24 } 24 }
25 25
26 std::string Slurp(std::istream& stream) 26 std::string Slurp(std::istream& stream)
27 { 27 {
28 std::stringstream content; 28 std::stringstream content;
29 content << stream.rdbuf(); 29 content << stream.rdbuf();
30 return content.str(); 30 return content.str();
31 } 31 }
32
33 std::string ExceptionToString(const v8::Handle<v8::Value> exception,
34 const v8::Handle<v8::Message> message)
35 {
36 std::stringstream error;
37 error << *v8::String::Utf8Value(exception);
38 if (!message.IsEmpty())
39 {
40 error << " at ";
41 error << *v8::String::Utf8Value(message->GetScriptResourceName());
42 error << ":";
43 error << message->GetLineNumber();
44 }
45 return error.str();
46 }
32 } 47 }
33 48
34 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, 49 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception,
35 const v8::Handle<v8::Message> message) 50 const v8::Handle<v8::Message> message)
36 : std::runtime_error(ExceptionToString(exception, message)) 51 : std::runtime_error(ExceptionToString(exception, message))
37 { 52 {
38 }
39
40 std::string AdblockPlus::JsError::ExceptionToString(const v8::Handle<v8::Value> exception,
41 const v8::Handle<v8::Message> message)
42 {
43 std::stringstream error;
44 error << *v8::String::Utf8Value(exception);
45 if (!message.IsEmpty())
46 {
47 error << " at ";
48 error << *v8::String::Utf8Value(message->GetScriptResourceName());
49 error << ":";
50 error << message->GetLineNumber();
51 }
52 return error.str();
53 } 53 }
54 54
55 AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader, 55 AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader,
56 ErrorCallback* const errorCallback) 56 ErrorCallback* const errorCallback)
57 : fileReader(fileReader), context(CreateContext(*errorCallback)) 57 : fileReader(fileReader), context(CreateContext(*errorCallback))
58 { 58 {
59 for (int i = 0; jsSources[i] && jsSources[i + 1]; i += 2) 59 for (int i = 0; jsSources[i] && jsSources[i + 1]; i += 2)
60 Evaluate(jsSources[i + 1], jsSources[i]); 60 Evaluate(jsSources[i + 1], jsSources[i]);
61 } 61 }
62 62
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 const v8::Local<v8::Value> result = function->Call(function, 0, 0); 102 const v8::Local<v8::Value> result = function->Call(function, 0, 0);
103 CheckTryCatch(tryCatch); 103 CheckTryCatch(tryCatch);
104 const v8::String::AsciiValue ascii(result); 104 const v8::String::AsciiValue ascii(result);
105 return *ascii; 105 return *ascii;
106 } 106 }
107 107
108 void AdblockPlus::JsEngine::Gc() 108 void AdblockPlus::JsEngine::Gc()
109 { 109 {
110 while (!v8::V8::IdleNotification()); 110 while (!v8::V8::IdleNotification());
111 } 111 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld