| 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-2016 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 namespace v8 | 26 namespace v8 |
| 27 { | 27 { |
| 28 class Value; | 28 class Value; |
| 29 class Object; |
| 29 template<class T> class Handle; | 30 template<class T> class Handle; |
| 30 template<class T> class Local; | 31 template<class T> class Local; |
| 31 template<class T> class Persistent; | 32 template<class T> class Persistent; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace AdblockPlus | 35 namespace AdblockPlus |
| 35 { | 36 { |
| 36 class JsValue; | 37 class JsValue; |
| 37 class JsEngine; | 38 class JsEngine; |
| 38 | 39 |
| 39 typedef std::shared_ptr<JsEngine> JsEnginePtr; | 40 typedef std::shared_ptr<JsEngine> JsEnginePtr; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Shared smart pointer to a `JsValue` instance. | 43 * Shared smart pointer to a `JsValue` instance. |
| 43 */ | 44 */ |
| 44 typedef std::shared_ptr<JsValue> JsValuePtr; | 45 typedef std::shared_ptr<JsValue> JsValuePtr; |
| 46 typedef std::shared_ptr<const JsValue> JsConstValuePtr; |
| 45 | 47 |
| 46 /** | 48 /** |
| 47 * List of JavaScript values. | 49 * List of JavaScript values. |
| 48 */ | 50 */ |
| 49 typedef std::vector<AdblockPlus::JsValuePtr> JsValueList; | 51 typedef std::vector<AdblockPlus::JsValuePtr> JsValueList; |
| 52 typedef std::vector<AdblockPlus::JsConstValuePtr> JsConstValueList; |
| 50 | 53 |
| 51 /** | 54 /** |
| 52 * Wrapper for JavaScript values. | 55 * Wrapper for JavaScript values. |
| 53 * See `JsEngine` for creating `JsValue` objects. | 56 * See `JsEngine` for creating `JsValue` objects. |
| 54 */ | 57 */ |
| 55 class JsValue | 58 class JsValue |
| 56 { | 59 { |
| 57 friend class JsEngine; | 60 friend class JsEngine; |
| 58 public: | 61 public: |
| 59 JsValue(JsValue&& src); | 62 JsValue(JsValue&& src); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 * @return Class name of the value. | 117 * @return Class name of the value. |
| 115 */ | 118 */ |
| 116 std::string GetClass() const; | 119 std::string GetClass() const; |
| 117 | 120 |
| 118 /** | 121 /** |
| 119 * Invokes the value as a function (see `IsFunction()`). | 122 * Invokes the value as a function (see `IsFunction()`). |
| 120 * @param params Optional list of parameters. | 123 * @param params Optional list of parameters. |
| 121 * @param thisPtr Optional `this` value. | 124 * @param thisPtr Optional `this` value. |
| 122 * @return Value returned by the function. | 125 * @return Value returned by the function. |
| 123 */ | 126 */ |
| 124 JsValue Call(const JsValueList& params = JsValueList(), | 127 JsValue Call(const JsConstValueList& params = JsConstValueList(), |
| 125 AdblockPlus::JsValuePtr thisPtr = AdblockPlus::JsValuePtr()) const; | 128 AdblockPlus::JsValuePtr thisPtr = AdblockPlus::JsValuePtr()) const; |
| 129 |
| 130 /** |
| 131 * Invokes the value as a function (see `IsFunction()`) with single |
| 132 * parameter. |
| 133 * @param arg A single required parameter. |
| 134 * @return Value returned by the function. |
| 135 */ |
| 136 JsValue Call(const JsValue& arg) const; |
| 126 | 137 |
| 127 v8::Local<v8::Value> UnwrapValue() const; | 138 v8::Local<v8::Value> UnwrapValue() const; |
| 128 protected: | 139 protected: |
| 129 JsEnginePtr jsEngine; | 140 JsEnginePtr jsEngine; |
| 130 private: | 141 private: |
| 131 JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value); | 142 JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value); |
| 132 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); | 143 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); |
| 144 // Parameter args is not const because a pointer to its internal arrays is |
| 145 // passed to v8::Function::Call but the latter does not expect a const point
er. |
| 146 JsValue Call(std::vector<v8::Handle<v8::Value>>& args, v8::Local<v8::Object>
thisObj) const; |
| 147 |
| 133 std::unique_ptr<v8::Persistent<v8::Value>> value; | 148 std::unique_ptr<v8::Persistent<v8::Value>> value; |
| 134 }; | 149 }; |
| 135 } | 150 } |
| 136 | 151 |
| 137 #endif | 152 #endif |
| LEFT | RIGHT |