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: Added tests, resolved type conversion ambiguities, implemented some missing API calls Created April 15, 2013, 6:23 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
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, (int64_t)val);
Felix Dahlke 2013/04/16 15:14:33 As above, I'd prefer static_cast.
+ }
+ 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

Powered by Google App Engine
This is Rietveld