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

Unified Diff: include/AdblockPlus/JsValue.h

Issue 5728380594946048: Issue 116 - Document the libadblockplus API (Closed)
Patch Set: Addressed remaining comments Created Sept. 2, 2014, 5:21 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | include/AdblockPlus/LogSystem.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/JsValue.h
===================================================================
--- a/include/AdblockPlus/JsValue.h
+++ b/include/AdblockPlus/JsValue.h
@@ -35,10 +35,22 @@
class JsValue;
class JsEngine;
- typedef std::tr1::shared_ptr<JsValue> JsValuePtr;
- typedef std::vector<AdblockPlus::JsValuePtr> JsValueList;
typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr;
+ /**
+ * Shared smart pointer to a `JsValue` instance.
+ */
+ typedef std::tr1::shared_ptr<JsValue> JsValuePtr;
+
+ /**
+ * List of JavaScript values.
+ */
+ typedef std::vector<AdblockPlus::JsValuePtr> JsValueList;
+
+ /**
+ * Wrapper for JavaScript values.
+ * See `JsEngine` for creating `JsValue` objects.
+ */
class JsValue
{
friend class JsEngine;
@@ -58,8 +70,27 @@
int64_t AsInt() const;
bool AsBool() const;
JsValueList AsList() const;
+
+ /**
+ * Returns a list of property names if this is an object (see `IsObject()`).
+ * @return List of property names.
+ */
std::vector<std::string> GetOwnPropertyNames() const;
+
+ /**
+ * Returns a property value if this is an object (see `IsObject()`).
+ * @param name Property name.
+ * @return Property value, undefined (see `IsUndefined()`) if the property
+ * does not exist.
+ */
JsValuePtr GetProperty(const std::string& name) const;
+
+ //@{
+ /**
+ * Sets a property value if this is an object (see `IsObject()`).
+ * @param name Property name.
+ * @param val Property value.
+ */
void SetProperty(const std::string& name, const std::string& val);
void SetProperty(const std::string& name, int64_t val);
void SetProperty(const std::string& name, bool val);
@@ -72,9 +103,26 @@
{
SetProperty(name, static_cast<int64_t>(val));
}
+ //@}
+
+ /**
+ * Returns the value's class name, e.g.\ _Array_ for arrays
+ * (see `IsArray()`).
+ * Technically, this is the name of the function that was used as a
+ * constructor.
+ * @return Class name of the value.
+ */
std::string GetClass() const;
+
+ /**
+ * Invokes the value as a function (see `IsFunction()`).
+ * @param params Optional list of parameters.
+ * @param thisPtr Optional `this` value.
+ * @return Value returned by the function.
+ */
JsValuePtr Call(const JsValueList& params = JsValueList(),
AdblockPlus::JsValuePtr thisPtr = AdblockPlus::JsValuePtr()) const;
+
protected:
JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value);
void SetProperty(const std::string& name, v8::Handle<v8::Value> val);
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | include/AdblockPlus/LogSystem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld