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

Delta Between Two Patch Sets: include/AdblockPlus/JsEngine.h

Issue 10198022: Pass application data into libadblockplus (Closed)
Left Patch Set: Created April 12, 2013, 1:23 p.m.
Right Patch Set: Merged upstream, addressed issues, renamed AppInfo fields Created April 17, 2013, 2:47 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
LEFTRIGHT
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 #include <AdblockPlus/JsValue.h>
7 8
8 namespace AdblockPlus 9 namespace AdblockPlus
9 { 10 {
10 struct AppInfo; 11 struct AppInfo;
12 class FileSystem;
13 class WebRequest;
11 class ErrorCallback; 14 class ErrorCallback;
12 class FileReader;
13 class WebRequest;
14 15
15 class JsError : public std::runtime_error 16 class JsError : public std::runtime_error
16 { 17 {
17 public: 18 public:
18 explicit JsError(const v8::Handle<v8::Value> exception, 19 explicit JsError(const v8::Handle<v8::Value> exception,
19 const v8::Handle<v8::Message> message); 20 const v8::Handle<v8::Message> message);
20 }; 21 };
21 22
22 class JsEngine 23 class JsEngine
23 { 24 {
25 friend class JsValue;
26
24 public: 27 public:
25 JsEngine(const AppInfo& appInfo, 28 JsEngine(const AppInfo& appInfo,
26 const FileReader* const fileReader, 29 FileSystem* const fileReader,
27 WebRequest* const webRequest, 30 WebRequest* const webRequest,
28 ErrorCallback* const errorCallback); 31 ErrorCallback* const errorCallback);
29 std::string Evaluate(const std::string& source, 32 JsValuePtr Evaluate(const std::string& source,
30 const std::string& filename = ""); 33 const std::string& filename = "");
31 void Load(const std::string& scriptPath); 34 void Load(const std::string& scriptPath);
32 void Gc(); 35 void Gc();
36 JsValuePtr NewValue(const std::string& val);
37 JsValuePtr NewValue(int64_t val);
38 JsValuePtr NewValue(bool val);
39 inline JsValuePtr NewValue(const char* val)
40 {
41 return NewValue(std::string(val));
42 }
43 inline JsValuePtr NewValue(int val)
44 {
45 return NewValue(static_cast<int64_t>(val));
46 }
47 JsValuePtr NewObject();
48 static JsEngine& FromArguments(const v8::Arguments& arguments);
49 JsValueList ConvertArguments(const v8::Arguments& arguments);
50
51 inline FileSystem& GetFileSystem()
52 {
53 return fileSystem;
54 }
55 inline WebRequest& GetWebRequest()
56 {
57 return webRequest;
58 }
59 inline ErrorCallback& GetErrorCallback()
60 {
61 return errorCallback;
62 }
63
64 class Context
65 {
66 public:
67 Context(const JsEngine& jsEngine);
68 virtual inline ~Context() {};
69
70 private:
71 const v8::Locker locker;
72 const v8::HandleScope handleScope;
73 const v8::Context::Scope contextScope;
74 };
33 75
34 private: 76 private:
35 const FileReader* const fileReader; 77 FileSystem& fileSystem;
78 WebRequest& webRequest;
79 ErrorCallback& errorCallback;
80 v8::Isolate* isolate;
36 v8::Persistent<v8::Context> context; 81 v8::Persistent<v8::Context> context;
37 }; 82 };
38 } 83 }
39 84
40 #endif 85 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld