Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 }; | 17 }; |
18 | 18 |
19 class JsEngine | 19 class JsEngine |
20 { | 20 { |
21 public: | 21 public: |
22 JsEngine(const FileReader* const fileReader, | 22 JsEngine(const FileReader* const fileReader, |
23 ErrorCallback* const errorCallback); | 23 ErrorCallback* const errorCallback); |
24 void Evaluate(const char* source, const char* filename = NULL); | 24 void Evaluate(const char* source, const char* filename = NULL); |
Felix Dahlke
2013/03/15 15:18:36
Have you considered having just one Evaluate funct
Wladimir Palant
2013/03/15 16:00:41
I would rather use char* for the main function - w
Felix Dahlke
2013/03/15 17:10:47
It's up to you. std::string is obviously more C++-
| |
25 void Evaluate(const std::string& source) | 25 void Evaluate(const std::string& source, |
Felix Dahlke
2013/03/15 15:18:36
I prefer to have all implementations in the .cpp f
Wladimir Palant
2013/03/15 16:00:41
Yes, I tend to be a bit sloppy about that - fair p
| |
26 { | 26 const std::string& filename = ""); |
27 Evaluate(source.c_str()); | |
28 } | |
29 void Evaluate(const std::string& source, const std::string& filename) | |
30 { | |
31 Evaluate(filename.c_str(), source.c_str()); | |
32 } | |
33 void Load(const std::string& scriptPath); | 27 void Load(const std::string& scriptPath); |
34 std::string Call(const std::string& functionName); | 28 std::string Call(const std::string& functionName); |
35 void Gc(); | 29 void Gc(); |
36 | 30 |
37 private: | 31 private: |
38 const FileReader* const fileReader; | 32 const FileReader* const fileReader; |
39 v8::Persistent<v8::Context> context; | 33 v8::Persistent<v8::Context> context; |
40 inline v8::Handle<v8::Script> CompileScript(const char* source, const char* filename); | |
Felix Dahlke
2013/03/15 15:18:36
You probably don't want to declare this inline. It
| |
41 }; | 34 }; |
42 } | 35 } |
43 | 36 |
44 #endif | 37 #endif |
LEFT | RIGHT |