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

Unified Diff: src/JsValue.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/JsValue.cpp
===================================================================
--- a/src/JsValue.cpp
+++ b/src/JsValue.cpp
@@ -12,26 +12,26 @@ namespace
}
v8::Local<v8::String> toV8String(const std::string& str)
{
return v8::String::New(str.c_str(), str.length());
}
}
-AdblockPlus::JsValue::JsValue(AdblockPlus::JsEngine& jsEngine,
+AdblockPlus::JsValue::JsValue(AdblockPlus::JsEnginePtr jsEngine,
v8::Handle<v8::Value> value)
: jsEngine(jsEngine),
- value(v8::Persistent<v8::Value>::New(jsEngine.isolate, value))
+ value(v8::Persistent<v8::Value>::New(jsEngine->isolate, value))
{
}
AdblockPlus::JsValue::~JsValue()
{
- value.Dispose(jsEngine.isolate);
+ value.Dispose(jsEngine->isolate);
}
bool AdblockPlus::JsValue::IsUndefined() const
{
const JsEngine::Context context(jsEngine);
return value->IsUndefined();
}
@@ -187,17 +187,17 @@ AdblockPlus::JsValuePtr AdblockPlus::JsV
AdblockPlus::JsValuePtr thisPtr) const
{
if (!IsFunction())
throw new std::runtime_error("Attempting to call a non-function");
const JsEngine::Context context(jsEngine);
if (!thisPtr)
- thisPtr = JsValuePtr(new JsValue(jsEngine, jsEngine.context->Global()));
+ thisPtr = JsValuePtr(new JsValue(jsEngine, jsEngine->context->Global()));
if (!thisPtr->IsObject())
throw new std::runtime_error("`this` pointer has to be an object");
v8::Persistent<v8::Object> thisObj = v8::Persistent<v8::Object>::Cast(thisPtr->value);
size_t argc = params.size();
v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[argc];
for (size_t i = 0; i < argc; ++i)
argv[i] = params[i]->value;
« src/JsEngine.cpp ('K') | « src/JsEngine.cpp ('k') | src/WebRequestJsObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld