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

Unified Diff: include/AdblockPlus/JsEngine.h

Issue 5728380594946048: Issue 116 - Document the libadblockplus API (Closed)
Patch Set: Created Aug. 28, 2014, 4:14 p.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
« include/AdblockPlus/AppInfo.h ('K') | « include/AdblockPlus/AppInfo.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/JsEngine.h
===================================================================
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -47,22 +47,73 @@
class JsEngine;
typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr;
+ /**
+ * JavaScript engine used by `FilterEngine`, uses v8.
Wladimir Palant 2014/08/28 17:24:40 "uses v8" => "wraps v8"?
Felix Dahlke 2014/08/28 22:56:41 Done.
+ */
class JsEngine : public std::tr1::enable_shared_from_this<JsEngine>
{
friend class JsValue;
friend class JsContext;
public:
+ /**
+ * Event callback function.
+ */
typedef std::tr1::function<void(JsValueList& params)> EventCallback;
+
+ /**
+ * Maps events to callback functions.
+ */
typedef std::map<std::string, EventCallback> EventMap;
+ /**
+ * Creates a new JavaScript engine instance.
+ * @param appInfo AppInfo Information about the app, used for update checks.
Wladimir Palant 2014/08/28 17:24:40 "AppInfo" is unnecessary here?
Felix Dahlke 2014/08/28 22:56:41 Done.
+ * @return New `JsEngine` instance.
+ */
static JsEnginePtr New(const AppInfo& appInfo = AppInfo());
+
+ /**
+ * Registers the callback function for an event.
+ * @param eventName Name of the event.
Wladimir Palant 2014/08/28 17:24:40 Here and below, why not just "Event name" and "Eve
Felix Dahlke 2014/08/28 22:56:41 Done.
+ * @param callback Event callback function.
+ */
void SetEventCallback(const std::string& eventName, EventCallback callback);
+
+ /**
+ * Removes the callback function for an event.
+ * @param eventName Name of the event.
+ */
void RemoveEventCallback(const std::string& eventName);
+
+ /**
+ * Triggers an event.
+ * @param eventName Name of the event.
+ * @param params Parameters for the event.
+ */
void TriggerEvent(const std::string& eventName, JsValueList& params);
+
+ /**
+ * Evaluates a JavaScript expression.
+ * @param source JavaScript expression to evalute.
Wladimir Palant 2014/08/28 17:24:40 "evaluate"
Felix Dahlke 2014/08/28 22:56:41 Done.
+ * @param filename Optional file name for the expression, used in error
+ * messages.
+ * @return Result of the evaluated expression.
+ */
JsValuePtr Evaluate(const std::string& source,
const std::string& filename = "");
+
+ /**
+ * Initiates a garbage collection.
Wladimir Palant 2014/08/28 17:24:40 I don't think you can use an article here...
Felix Dahlke 2014/08/28 22:56:41 I do, here's one example found in the wild: http:/
+ */
void Gc();
+
+ //@{
+ /**
+ * Creates a new JavaScript value.
+ * @param val Value to convert.
+ * @return New `JsValue` instance.
+ */
JsValuePtr NewValue(const std::string& val);
JsValuePtr NewValue(int64_t val);
JsValuePtr NewValue(bool val);
@@ -80,16 +131,74 @@
return NewValue(static_cast<int64_t>(val));
}
#endif
+ //@}
+
+ /**
+ * Creates a new JavaScript object.
+ * @return New `JsValue` instance.
+ */
JsValuePtr NewObject();
+
+ /**
+ * Creates a new JavaScript callback.
Wladimir Palant 2014/08/28 17:24:40 The thing about documentation is: it should be hel
Felix Dahlke 2014/08/28 22:56:41 Done.
+ * @param callback Callback to convert.
+ * @return New `JsValue` instance.
+ */
JsValuePtr NewCallback(v8::InvocationCallback callback);
+
+ /**
+ * Returns a `JsEngine` instance contained in a `v8::Arguments` object.
+ * @param arguments `v8::Arguments` object containing the `JsEngine`
+ * instance.
+ * @return `JsEngine` instance.
+ */
static JsEnginePtr FromArguments(const v8::Arguments& arguments);
+
+ /**
+ * Converts v8 arguments to `JsValue` objects.
+ * @param arguments `v8::Arguments` object containing the arguments to
+ * convert.
+ * @return List of arguments converted to `JsValue` objects.
+ */
JsValueList ConvertArguments(const v8::Arguments& arguments);
+ /**
+ * @see SetFileSystem().
+ */
FileSystemPtr GetFileSystem();
+
+ /**
+ * Sets the `FileSystem` implementation used for all file I/O.
+ * Setting this is optional, the engine will use a `DefaultFileSystem`
+ * instance by default, which should normally be sufficient.
Wladimir Palant 2014/08/28 17:24:40 "normally be sufficient"? "might be sufficient" is
Felix Dahlke 2014/08/28 22:56:41 Done.
+ * @param The `FileSystem` instance to use.
+ */
void SetFileSystem(FileSystemPtr val);
+
+ /**
+ * @see SetWebRequest().
+ */
WebRequestPtr GetWebRequest();
+
+ /**
+ * Sets the `WebRequest` implementation used for XMLHttpRequests.
+ * Setting this is optional, the engine will use a `DefaultWebRequest`
+ * instance by default, which should normally be sufficient.
+ * @param The `WebRequest` instance to use.
+ */
void SetWebRequest(WebRequestPtr val);
+
+ /**
+ * @see SetLogSystem().
+ */
LogSystemPtr GetLogSystem();
+
+ /**
+ * Sets the `LogSystem` implementation used for logging (e.g. console.log).
Wladimir Palant 2014/08/28 17:24:40 "e.g. to handle console.log() calls from JavaScrip
Felix Dahlke 2014/08/28 22:56:41 Done.
+ * Setting this is optional, the engine will use a `DefaultLogSystem`
+ * instance by default, which should normally be sufficient.
+ * @param The `FileSystem` instance to use.
Wladimir Palant 2014/08/28 17:24:40 FileSystem => LogSystem?
Felix Dahlke 2014/08/28 22:56:41 Done.
+ */
void SetLogSystem(LogSystemPtr val);
private:
« include/AdblockPlus/AppInfo.h ('K') | « include/AdblockPlus/AppInfo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld