| OLD | NEW |
| 1 #ifndef ADBLOCKPLUS_JS_ENGINE_H | 1 #ifndef ADBLOCKPLUS_JS_ENGINE_H |
| 2 #define ADBLOCKPLUS_JS_ENGINE_H | 2 #define ADBLOCKPLUS_JS_ENGINE_H |
| 3 | 3 |
| 4 #include <stdexcept> | 4 #include <stdexcept> |
| 5 #include <string> | 5 #include <string> |
| 6 #include <v8.h> | 6 #include <v8.h> |
| 7 | 7 |
| 8 class ErrorCallback; | 8 class ErrorCallback; |
| 9 class FileReader; | 9 class FileReader; |
| 10 | 10 |
| 11 namespace AdblockPlus | 11 namespace AdblockPlus |
| 12 { | 12 { |
| 13 class JsError : public std::runtime_error | 13 class JsError : public std::runtime_error |
| 14 { | 14 { |
| 15 public: | 15 public: |
| 16 JsError(const v8::Handle<v8::Value> exception); | 16 JsError(const v8::Handle<v8::Value> exception, |
| 17 const v8::Handle<v8::Message> message); |
| 18 |
| 19 private: |
| 20 static std::string ExceptionToString(const v8::Handle<v8::Value> exception, |
| 21 const v8::Handle<v8::Message> message); |
| 17 }; | 22 }; |
| 18 | 23 |
| 19 class JsEngine | 24 class JsEngine |
| 20 { | 25 { |
| 21 public: | 26 public: |
| 22 JsEngine(const FileReader* const fileReader, | 27 JsEngine(const FileReader* const fileReader, |
| 23 ErrorCallback* const errorCallback); | 28 ErrorCallback* const errorCallback); |
| 24 void Evaluate(const char* source, const char* filename = NULL); | 29 void Evaluate(const char* source, const char* filename = NULL); |
| 25 void Evaluate(const std::string& source) | 30 void Evaluate(const std::string& source) |
| 26 { | 31 { |
| 27 Evaluate(source.c_str()); | 32 Evaluate(source.c_str()); |
| 28 } | 33 } |
| 29 void Evaluate(const std::string& source, const std::string& filename) | 34 void Evaluate(const std::string& source, const std::string& filename) |
| 30 { | 35 { |
| 31 Evaluate(filename.c_str(), source.c_str()); | 36 Evaluate(filename.c_str(), source.c_str()); |
| 32 } | 37 } |
| 33 void Load(const std::string& scriptPath); | 38 void Load(const std::string& scriptPath); |
| 34 std::string Call(const std::string& functionName); | 39 std::string Call(const std::string& functionName); |
| 35 void Gc(); | 40 void Gc(); |
| 36 | 41 |
| 37 private: | 42 private: |
| 38 const FileReader* const fileReader; | 43 const FileReader* const fileReader; |
| 39 v8::Persistent<v8::Context> context; | 44 v8::Persistent<v8::Context> context; |
| 40 inline v8::Handle<v8::Script> CompileScript(const char* source, const char*
filename); | 45 inline v8::Handle<v8::Script> CompileScript(const char* source, const char*
filename); |
| 41 }; | 46 }; |
| 42 } | 47 } |
| 43 | 48 |
| 44 #endif | 49 #endif |
| OLD | NEW |