LEFT | RIGHT |
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 Loading... |
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(toString(exception, message)) | 51 : std::runtime_error(ExceptionToString(exception, message)) |
37 { | 52 { |
38 } | |
39 | |
40 std::string AdblockPlus::JsError::toString(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 Loading... |
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 } |
LEFT | RIGHT |