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

Unified Diff: include/AdblockPlus/JsValue.h

Issue 10173031: Don`t use references to JsEngine to avoid use-after-free errors,switch to shared_ptr instead (Closed)
Patch Set: Created April 18, 2013, 4:15 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
Index: include/AdblockPlus/JsValue.h
===================================================================
--- a/include/AdblockPlus/JsValue.h
+++ b/include/AdblockPlus/JsValue.h
@@ -1,27 +1,27 @@
#ifndef ADBLOCKPLUS_JS_VALUE_H
#define ADBLOCKPLUS_JS_VALUE_H
+#include <string>
#include <vector>
#include <v8.h>
-#ifdef _MSC_VER
-#include <memory>
-#else
-#include <tr1/memory>
-#endif
+#include "tr1_memory.h"
namespace AdblockPlus
{
+ class JsValue;
class JsEngine;
- class JsValue;
typedef std::tr1::shared_ptr<JsValue> JsValuePtr;
typedef std::vector<AdblockPlus::JsValuePtr> JsValueList;
+ // Forward declaration to avoid including JsEngine.h
+ typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr;
+
class JsValue
{
friend class JsEngine;
friend class JsObject;
public:
virtual ~JsValue();
bool IsUndefined() const;
@@ -49,17 +49,17 @@ namespace AdblockPlus
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);
+ JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value);
void SetProperty(const std::string& name, v8::Handle<v8::Value> val);
- JsEngine& jsEngine;
+ JsEnginePtr jsEngine;
v8::Persistent<v8::Value> value;
};
}
#endif
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | shell/src/GcCommand.h » ('j') | src/JsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld