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

Side by Side Diff: include/AdblockPlus/JsValue.h

Issue 29417605: Issue 5034 - Part 3: Create plain JsValue instead of JsValuePtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Added value test for copy ctor Created April 20, 2017, 12:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
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
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
OLDNEW
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | shell/src/PrefsCommand.cpp » ('j') | test/JsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld