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

Unified Diff: src/ConsoleJsObject.cpp

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: src/ConsoleJsObject.cpp
===================================================================
--- a/src/ConsoleJsObject.cpp
+++ b/src/ConsoleJsObject.cpp
@@ -1,37 +1,36 @@
-#include <AdblockPlus/JsEngine.h>
#include <AdblockPlus/JsValue.h>
#include <AdblockPlus/ErrorCallback.h>
#include <sstream>
#include "ConsoleJsObject.h"
namespace
{
v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments)
{
- AdblockPlus::JsEngine& jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
+ AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
const AdblockPlus::JsEngine::Context context(jsEngine);
- AdblockPlus::JsValueList converted = jsEngine.ConvertArguments(arguments);
+ AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
std::stringstream message;
for (size_t i = 0; i < converted.size(); i++)
message << converted[i]->AsString();
- AdblockPlus::ErrorCallbackPtr callback = jsEngine.GetErrorCallback();
+ AdblockPlus::ErrorCallbackPtr callback = jsEngine->GetErrorCallback();
(*callback)(message.str());
return v8::Undefined();
}
v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments)
{
return v8::Undefined();
}
}
AdblockPlus::JsValuePtr AdblockPlus::ConsoleJsObject::Setup(
- AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValuePtr obj)
+ AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj)
{
- obj->SetProperty("error", jsEngine.NewCallback(::ErrorCallback));
- obj->SetProperty("trace", jsEngine.NewCallback(::TraceCallback));
+ obj->SetProperty("error", jsEngine->NewCallback(::ErrorCallback));
+ obj->SetProperty("trace", jsEngine->NewCallback(::TraceCallback));
return obj;
}
« no previous file with comments | « src/ConsoleJsObject.h ('k') | src/FileSystemJsObject.h » ('j') | src/JsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld