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

Unified Diff: include/AdblockPlus/JsValue.h

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Patch Set: Addressed review comments Created April 17, 2013, 7:56 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') | lib/api.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/JsValue.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/include/AdblockPlus/JsValue.h
@@ -0,0 +1,63 @@
+#ifndef ADBLOCKPLUS_JS_VALUE_H
+#define ADBLOCKPLUS_JS_VALUE_H
+
+#include <vector>
+#include <v8.h>
+#ifdef _MSC_VER
+#include <memory>
+#else
+#include <tr1/memory>
+#endif
+
+namespace AdblockPlus
+{
+ class JsEngine;
+ class JsValue;
+
+ typedef std::tr1::shared_ptr<JsValue> JsValuePtr;
+ typedef std::vector<AdblockPlus::JsValuePtr> JsValueList;
+
+ class JsValue
+ {
+ friend class JsEngine;
+ friend class JsObject;
+ public:
+ virtual ~JsValue();
+
+ bool IsUndefined() const;
+ bool IsNull() const;
+ bool IsString() const;
+ bool IsNumber() const;
+ bool IsBool() const;
+ bool IsObject() const;
+ bool IsArray() const;
+ bool IsFunction() const;
+ std::string AsString() const;
+ int64_t AsInt() const;
+ bool AsBool() const;
+ JsValueList AsList() const;
+ JsValuePtr GetProperty(const std::string& name) const;
+ 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);
+ inline void SetProperty(const std::string& name, const char* val)
+ {
+ SetProperty(name, std::string(val));
+ }
+ inline void SetProperty(const std::string& name, int val)
+ {
+ SetProperty(name, static_cast<int64_t>(val));
+ }
+ std::string GetClassName() const;
+ JsValuePtr Call(const JsValueList& params = JsValueList(),
+ AdblockPlus::JsValuePtr thisPtr = AdblockPlus::JsValuePtr()) const;
+ protected:
+ JsValue(JsEngine& jsEngine, v8::Handle<v8::Value> value);
+ void SetProperty(const std::string& name, v8::Handle<v8::Value> val);
+
+ JsEngine& jsEngine;
+ v8::Persistent<v8::Value> value;
+ };
+}
+
+#endif
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | lib/api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld