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

Unified Diff: include/AdblockPlus/JsEngine.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/JsEngine.h
===================================================================
--- a/include/AdblockPlus/JsEngine.h
+++ b/include/AdblockPlus/JsEngine.h
@@ -16,24 +16,25 @@ namespace AdblockPlus
{
class JsError : public std::runtime_error
{
public:
JsError(const v8::Handle<v8::Value> exception,
const v8::Handle<v8::Message> message);
};
+ class JsEngine;
typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr;
- class JsEngine
+ class JsEngine : public std::tr1::enable_shared_from_this<JsEngine>
{
friend class JsValue;
public:
- JsEngine(const AppInfo& appInfo = AppInfo());
+ static JsEnginePtr New(const AppInfo& appInfo = AppInfo());
JsValuePtr Evaluate(const std::string& source,
const std::string& filename = "");
void Load(const std::string& scriptPath);
void Gc();
JsValuePtr NewValue(const std::string& val);
JsValuePtr NewValue(int64_t val);
JsValuePtr NewValue(bool val);
inline JsValuePtr NewValue(const char* val)
@@ -41,39 +42,41 @@ namespace AdblockPlus
return NewValue(std::string(val));
}
inline JsValuePtr NewValue(int val)
{
return NewValue(static_cast<int64_t>(val));
}
JsValuePtr NewObject();
JsValuePtr NewCallback(v8::InvocationCallback callback);
- static JsEngine& FromArguments(const v8::Arguments& arguments);
+ static JsEnginePtr FromArguments(const v8::Arguments& arguments);
JsValueList ConvertArguments(const v8::Arguments& arguments);
FileSystemPtr GetFileSystem();
void SetFileSystem(FileSystemPtr val);
WebRequestPtr GetWebRequest();
void SetWebRequest(WebRequestPtr val);
ErrorCallbackPtr GetErrorCallback();
void SetErrorCallback(ErrorCallbackPtr val);
class Context
{
public:
- Context(const JsEngine& jsEngine);
+ Context(const JsEnginePtr jsEngine);
virtual inline ~Context() {};
private:
const v8::Locker locker;
const v8::HandleScope handleScope;
const v8::Context::Scope contextScope;
};
private:
+ JsEngine();
+
FileSystemPtr fileSystem;
WebRequestPtr webRequest;
ErrorCallbackPtr errorCallback;
v8::Isolate* isolate;
v8::Persistent<v8::Context> context;
};
}

Powered by Google App Engine
This is Rietveld