| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 { | 36 { |
| 37 class JsValue; | 37 class JsValue; |
| 38 class JsEngine; | 38 class JsEngine; |
| 39 | 39 |
| 40 typedef std::shared_ptr<JsEngine> JsEnginePtr; | 40 typedef std::shared_ptr<JsEngine> JsEnginePtr; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Shared smart pointer to a `JsValue` instance. | 43 * Shared smart pointer to a `JsValue` instance. |
| 44 */ | 44 */ |
| 45 typedef std::shared_ptr<JsValue> JsValuePtr; | 45 typedef std::shared_ptr<JsValue> JsValuePtr; |
| 46 typedef std::shared_ptr<const JsValue> JsConstValuePtr; | |
| 47 | 46 |
| 48 /** | 47 /** |
| 49 * List of JavaScript values. | 48 * List of JavaScript values. |
| 50 */ | 49 */ |
| 51 typedef std::vector<AdblockPlus::JsValuePtr> JsValueList; | 50 typedef std::vector<AdblockPlus::JsValue> JsValueList; |
| 52 typedef std::vector<AdblockPlus::JsConstValuePtr> JsConstValueList; | |
| 53 | 51 |
| 54 /** | 52 /** |
| 55 * Wrapper for JavaScript values. | 53 * Wrapper for JavaScript values. |
| 56 * See `JsEngine` for creating `JsValue` objects. | 54 * See `JsEngine` for creating `JsValue` objects. |
| 57 */ | 55 */ |
| 58 class JsValue | 56 class JsValue |
| 59 { | 57 { |
| 60 friend class JsEngine; | 58 friend class JsEngine; |
| 61 public: | 59 public: |
| 62 JsValue(JsValue&& src); | 60 JsValue(JsValue&& src); |
| 61 JsValue(const JsValue& src); | |
| 63 virtual ~JsValue(); | 62 virtual ~JsValue(); |
| 64 | 63 |
| 64 JsValue& operator=(const JsValue& src); | |
|
sergei
2017/04/19 18:56:52
I think it would be useful to take the comment fro
hub
2017/04/19 21:56:49
I didn't think the assignment operator overload ne
| |
| 65 | |
| 65 bool IsUndefined() const; | 66 bool IsUndefined() const; |
| 66 bool IsNull() const; | 67 bool IsNull() const; |
| 67 bool IsString() const; | 68 bool IsString() const; |
| 68 bool IsNumber() const; | 69 bool IsNumber() const; |
| 69 bool IsBool() const; | 70 bool IsBool() const; |
| 70 bool IsObject() const; | 71 bool IsObject() const; |
| 71 bool IsArray() const; | 72 bool IsArray() const; |
| 72 bool IsFunction() const; | 73 bool IsFunction() const; |
| 73 std::string AsString() const; | 74 std::string AsString() const; |
| 74 int64_t AsInt() const; | 75 int64_t AsInt() const; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 * @return Class name of the value. | 118 * @return Class name of the value. |
| 118 */ | 119 */ |
| 119 std::string GetClass() const; | 120 std::string GetClass() const; |
| 120 | 121 |
| 121 /** | 122 /** |
| 122 * Invokes the value as a function (see `IsFunction()`). | 123 * Invokes the value as a function (see `IsFunction()`). |
| 123 * @param params Optional list of parameters. | 124 * @param params Optional list of parameters. |
| 124 * @param thisPtr Optional `this` value. | 125 * @param thisPtr Optional `this` value. |
| 125 * @return Value returned by the function. | 126 * @return Value returned by the function. |
| 126 */ | 127 */ |
| 127 JsValue Call(const JsConstValueList& params = JsConstValueList(), | 128 JsValue Call(const JsValueList& params = JsValueList(), |
| 128 const AdblockPlus::JsValuePtr& thisPtr = AdblockPlus::JsValuePtr()) cons t; | 129 const AdblockPlus::JsValuePtr& thisPtr = AdblockPlus::JsValuePtr()) cons t; |
| 129 | 130 |
| 130 /** | 131 /** |
| 131 * Invokes the value as a function (see `IsFunction()`) with single | 132 * Invokes the value as a function (see `IsFunction()`) with single |
| 132 * parameter. | 133 * parameter. |
| 133 * @param arg A single required parameter. | 134 * @param arg A single required parameter. |
| 134 * @return Value returned by the function. | 135 * @return Value returned by the function. |
| 135 */ | 136 */ |
| 136 JsValue Call(const JsValue& arg) const; | 137 JsValue Call(const JsValue& arg) const; |
| 137 | 138 |
| 138 v8::Local<v8::Value> UnwrapValue() const; | 139 v8::Local<v8::Value> UnwrapValue() const; |
| 139 | 140 |
| 140 /** | |
| 141 * Creates a new `JsValue` wrapper for the same JavaScript value. | |
| 142 * @return Value new `JsValue` | |
| 143 */ | |
| 144 JsValue Clone() const; | |
| 145 protected: | 141 protected: |
| 146 JsEnginePtr jsEngine; | 142 JsEnginePtr jsEngine; |
| 147 private: | 143 private: |
| 148 JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value); | 144 JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value); |
| 149 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); | 145 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); |
| 150 // Parameter args is not const because a pointer to its internal arrays is | 146 // 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. | 147 // passed to v8::Function::Call but the latter does not expect a const point er. |
| 152 JsValue Call(std::vector<v8::Handle<v8::Value>>& args, v8::Local<v8::Object> thisObj) const; | 148 JsValue Call(std::vector<v8::Handle<v8::Value>>& args, v8::Local<v8::Object> thisObj) const; |
| 153 | 149 |
| 154 std::unique_ptr<v8::Persistent<v8::Value>> value; | 150 std::unique_ptr<v8::Persistent<v8::Value>> value; |
| 155 }; | 151 }; |
| 156 } | 152 } |
| 157 | 153 |
| 158 #endif | 154 #endif |
| OLD | NEW |