LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #ifndef ADBLOCK_PLUS_JS_VALUE_H | 18 #ifndef ADBLOCK_PLUS_JS_VALUE_H |
19 #define ADBLOCK_PLUS_JS_VALUE_H | 19 #define ADBLOCK_PLUS_JS_VALUE_H |
20 | 20 |
21 #include <stdint.h> | 21 #include <stdint.h> |
22 #include <string> | 22 #include <string> |
23 #include <vector> | 23 #include <vector> |
24 #include <memory> | 24 #include <memory> |
25 | 25 |
| 26 #include <AdblockPlus/IFileSystem.h> |
| 27 |
26 namespace v8 | 28 namespace v8 |
27 { | 29 { |
28 class Value; | 30 class Value; |
29 class Object; | 31 class Object; |
30 template<class T> class Local; | 32 template<class T> class Local; |
31 template<class T> class Global; | 33 template<class T> class Global; |
32 } | 34 } |
33 | 35 |
34 namespace AdblockPlus | 36 namespace AdblockPlus |
35 { | 37 { |
36 class JsValue; | 38 class JsValue; |
37 class JsEngine; | 39 class JsEngine; |
38 | 40 |
39 typedef std::shared_ptr<JsEngine> JsEnginePtr; | 41 typedef std::shared_ptr<JsEngine> JsEnginePtr; |
| 42 |
| 43 typedef IFileSystem::IOBuffer StringBuffer; |
40 | 44 |
41 /** | 45 /** |
42 * List of JavaScript values. | 46 * List of JavaScript values. |
43 */ | 47 */ |
44 typedef std::vector<AdblockPlus::JsValue> JsValueList; | 48 typedef std::vector<AdblockPlus::JsValue> JsValueList; |
45 | 49 |
46 /** | 50 /** |
47 * Wrapper for JavaScript values. | 51 * Wrapper for JavaScript values. |
48 * See `JsEngine` for creating `JsValue` objects. | 52 * See `JsEngine` for creating `JsValue` objects. |
49 */ | 53 */ |
(...skipping 10 matching lines...) Expand all Loading... |
60 | 64 |
61 bool IsUndefined() const; | 65 bool IsUndefined() const; |
62 bool IsNull() const; | 66 bool IsNull() const; |
63 bool IsString() const; | 67 bool IsString() const; |
64 bool IsNumber() const; | 68 bool IsNumber() const; |
65 bool IsBool() const; | 69 bool IsBool() const; |
66 bool IsObject() const; | 70 bool IsObject() const; |
67 bool IsArray() const; | 71 bool IsArray() const; |
68 bool IsFunction() const; | 72 bool IsFunction() const; |
69 std::string AsString() const; | 73 std::string AsString() const; |
70 std::vector<char> AsBuffer() const; | 74 StringBuffer AsStringBuffer() const; |
71 int64_t AsInt() const; | 75 int64_t AsInt() const; |
72 bool AsBool() const; | 76 bool AsBool() const; |
73 JsValueList AsList() const; | 77 JsValueList AsList() const; |
74 | 78 |
75 /** | 79 /** |
76 * Returns a list of property names if this is an object (see `IsObject()`). | 80 * Returns a list of property names if this is an object (see `IsObject()`). |
77 * @return List of property names. | 81 * @return List of property names. |
78 */ | 82 */ |
79 std::vector<std::string> GetOwnPropertyNames() const; | 83 std::vector<std::string> GetOwnPropertyNames() const; |
80 | 84 |
81 /** | 85 /** |
82 * Returns a property value if this is an object (see `IsObject()`). | 86 * Returns a property value if this is an object (see `IsObject()`). |
83 * @param name Property name. | 87 * @param name Property name. |
84 * @return Property value, undefined (see `IsUndefined()`) if the property | 88 * @return Property value, undefined (see `IsUndefined()`) if the property |
85 * does not exist. | 89 * does not exist. |
86 */ | 90 */ |
87 JsValue GetProperty(const std::string& name) const; | 91 JsValue GetProperty(const std::string& name) const; |
88 | 92 |
89 //@{ | 93 //@{ |
90 /** | 94 /** |
91 * Sets a property value if this is an object (see `IsObject()`). | 95 * Sets a property value if this is an object (see `IsObject()`). |
92 * @param name Property name. | 96 * @param name Property name. |
93 * @param val Property value. | 97 * @param val Property value. |
94 */ | 98 */ |
95 void SetProperty(const std::string& name, const std::string& val); | 99 void SetProperty(const std::string& name, const std::string& val); |
96 void SetProperty(const std::string& name, const std::vector<char>& val); | 100 void SetProperty(const std::string& name, const StringBuffer& val); |
97 void SetProperty(const std::string& name, int64_t val); | 101 void SetProperty(const std::string& name, int64_t val); |
98 void SetProperty(const std::string& name, bool val); | 102 void SetProperty(const std::string& name, bool val); |
99 void SetProperty(const std::string& name, const JsValue& value); | 103 void SetProperty(const std::string& name, const JsValue& value); |
100 inline void SetProperty(const std::string& name, const char* val) | 104 inline void SetProperty(const std::string& name, const char* val) |
101 { | 105 { |
102 SetProperty(name, std::string(val)); | 106 SetProperty(name, std::string(val)); |
103 } | 107 } |
104 inline void SetProperty(const std::string& name, int val) | 108 inline void SetProperty(const std::string& name, int val) |
105 { | 109 { |
106 SetProperty(name, static_cast<int64_t>(val)); | 110 SetProperty(name, static_cast<int64_t>(val)); |
107 } | 111 } |
108 //@} | 112 //@} |
| 113 /** |
| 114 * Sets a property value string if this is an object (see `IsObject()`). |
| 115 * @param name Property name. |
| 116 * @param val Property value as a StringBuffer. |
| 117 */ |
| 118 void SetStringBufferProperty(const std::string& name, const StringBuffer& va
l); |
109 | 119 |
110 /** | 120 /** |
111 * Returns the value's class name, e.g.\ _Array_ for arrays | 121 * Returns the value's class name, e.g.\ _Array_ for arrays |
112 * (see `IsArray()`). | 122 * (see `IsArray()`). |
113 * Technically, this is the name of the function that was used as a | 123 * Technically, this is the name of the function that was used as a |
114 * constructor. | 124 * constructor. |
115 * @return Class name of the value. | 125 * @return Class name of the value. |
116 */ | 126 */ |
117 std::string GetClass() const; | 127 std::string GetClass() const; |
118 | 128 |
(...skipping 30 matching lines...) Expand all Loading... |
149 | 159 |
150 // Parameter args is not const because a pointer to its internal arrays is | 160 // Parameter args is not const because a pointer to its internal arrays is |
151 // passed to v8::Function::Call but the latter does not expect a const point
er. | 161 // passed to v8::Function::Call but the latter does not expect a const point
er. |
152 JsValue Call(std::vector<v8::Local<v8::Value>>& args, v8::Local<v8::Object>
thisObj) const; | 162 JsValue Call(std::vector<v8::Local<v8::Value>>& args, v8::Local<v8::Object>
thisObj) const; |
153 | 163 |
154 std::unique_ptr<v8::Global<v8::Value>> value; | 164 std::unique_ptr<v8::Global<v8::Value>> value; |
155 }; | 165 }; |
156 } | 166 } |
157 | 167 |
158 #endif | 168 #endif |
LEFT | RIGHT |