LEFT | RIGHT |
1 #ifndef ADBLOCKPLUS_JS_VALUE_H | 1 #ifndef ADBLOCKPLUS_JS_VALUE_H |
2 #define ADBLOCKPLUS_JS_VALUE_H | 2 #define ADBLOCKPLUS_JS_VALUE_H |
3 | 3 |
| 4 #include <vector> |
4 #include <v8.h> | 5 #include <v8.h> |
| 6 #ifdef _MSC_VER |
| 7 #include <memory> |
| 8 #else |
| 9 #include <tr1/memory> |
| 10 #endif |
5 | 11 |
6 namespace AdblockPlus | 12 namespace AdblockPlus |
7 { | 13 { |
8 class JsEngine; | 14 class JsEngine; |
9 class JsValue; | 15 class JsValue; |
10 | 16 |
11 typedef std::tr1::shared_ptr<JsValue> JsValuePtr; | 17 typedef std::tr1::shared_ptr<JsValue> JsValuePtr; |
| 18 typedef std::vector<AdblockPlus::JsValuePtr> JsValueList; |
12 | 19 |
13 class JsValue | 20 class JsValue |
14 { | 21 { |
15 friend class JsEngine; | 22 friend class JsEngine; |
| 23 friend class JsObject; |
16 public: | 24 public: |
17 virtual ~JsValue(); | 25 virtual ~JsValue(); |
18 | 26 |
19 bool IsUndefined() const; | 27 bool IsUndefined() const; |
20 bool IsNull() const; | 28 bool IsNull() const; |
21 bool IsString() const; | 29 bool IsString() const; |
22 bool IsNumber() const; | 30 bool IsNumber() const; |
23 bool IsBool() const; | 31 bool IsBool() const; |
24 bool IsObject() const; | 32 bool IsObject() const; |
| 33 bool IsArray() const; |
| 34 bool IsFunction() const; |
25 std::string AsString() const; | 35 std::string AsString() const; |
26 int64_t AsInt() const; | 36 int64_t AsInt() const; |
27 bool AsBool() const; | 37 bool AsBool() const; |
| 38 JsValueList AsList() const; |
28 JsValuePtr GetProperty(const std::string& name) const; | 39 JsValuePtr GetProperty(const std::string& name) const; |
29 void SetProperty(const std::string& name, const std::string& val); | 40 void SetProperty(const std::string& name, const std::string& val); |
30 void SetProperty(const std::string& name, int64_t val); | 41 void SetProperty(const std::string& name, int64_t val); |
31 void SetProperty(const std::string& name, bool val); | 42 void SetProperty(const std::string& name, bool val); |
| 43 inline void SetProperty(const std::string& name, const char* val) |
| 44 { |
| 45 SetProperty(name, std::string(val)); |
| 46 } |
| 47 inline void SetProperty(const std::string& name, int val) |
| 48 { |
| 49 SetProperty(name, static_cast<int64_t>(val)); |
| 50 } |
| 51 std::string GetClassName() const; |
| 52 JsValuePtr Call(const JsValueList& params = JsValueList(), |
| 53 AdblockPlus::JsValuePtr thisPtr = AdblockPlus::JsValuePtr()) const; |
32 protected: | 54 protected: |
33 JsValue(v8::Isolate* isolate, v8::Handle<v8::Context> context, | 55 JsValue(JsEngine& jsEngine, v8::Handle<v8::Value> value); |
34 v8::Handle<v8::Value> value); | |
35 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); | 56 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); |
36 | 57 |
37 v8::Isolate* isolate; | 58 JsEngine& jsEngine; |
38 v8::Persistent<v8::Context> context; | |
39 v8::Persistent<v8::Value> value; | 59 v8::Persistent<v8::Value> value; |
40 }; | 60 }; |
41 } | 61 } |
42 | 62 |
43 #endif | 63 #endif |
LEFT | RIGHT |