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

Unified Diff: test/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: test/ConsoleJsObject.cpp
===================================================================
--- a/test/ConsoleJsObject.cpp
+++ b/test/ConsoleJsObject.cpp
@@ -9,29 +9,29 @@ public:
void operator()(const std::string& message)
{
lastMessage = message;
}
};
TEST(ConsoleJsObjectTest, ErrorInvokesErrorCallback)
{
- AdblockPlus::JsEngine jsEngine;
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
MockErrorCallback* errorCallback = new MockErrorCallback();
- jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback));
- jsEngine.Evaluate("console.error('foo')");
+ jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback));
+ jsEngine->Evaluate("console.error('foo')");
ASSERT_EQ("foo", errorCallback->lastMessage);
}
TEST(ConsoleJsObjectTest, ErrorWithMultipleArguments)
{
- AdblockPlus::JsEngine jsEngine;
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
MockErrorCallback* errorCallback = new MockErrorCallback();
- jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback));
- jsEngine.Evaluate("console.error('foo', 'bar')");
+ jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback));
+ jsEngine->Evaluate("console.error('foo', 'bar')");
ASSERT_EQ("foobar", errorCallback->lastMessage);
}
TEST(ConsoleJsObjectTest, TraceDoesNothing)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.Evaluate("console.trace()");
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->Evaluate("console.trace()");
}
« src/JsEngine.cpp ('K') | « test/AppInfoJsObject.cpp ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld