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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <AdblockPlus/JsEngine.h>
2 #include <AdblockPlus/JsValue.h> 1 #include <AdblockPlus/JsValue.h>
3 #include <AdblockPlus/ErrorCallback.h> 2 #include <AdblockPlus/ErrorCallback.h>
4 #include <sstream> 3 #include <sstream>
5 4
6 #include "ConsoleJsObject.h" 5 #include "ConsoleJsObject.h"
7 6
8 namespace 7 namespace
9 { 8 {
10 v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments) 9 v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments)
11 { 10 {
12 AdblockPlus::JsEngine& jsEngine = AdblockPlus::JsEngine::FromArguments(argum ents); 11 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
13 const AdblockPlus::JsEngine::Context context(jsEngine); 12 const AdblockPlus::JsEngine::Context context(jsEngine);
14 AdblockPlus::JsValueList converted = jsEngine.ConvertArguments(arguments); 13 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
15 14
16 std::stringstream message; 15 std::stringstream message;
17 for (size_t i = 0; i < converted.size(); i++) 16 for (size_t i = 0; i < converted.size(); i++)
18 message << converted[i]->AsString(); 17 message << converted[i]->AsString();
19 18
20 AdblockPlus::ErrorCallbackPtr callback = jsEngine.GetErrorCallback(); 19 AdblockPlus::ErrorCallbackPtr callback = jsEngine->GetErrorCallback();
21 (*callback)(message.str()); 20 (*callback)(message.str());
22 return v8::Undefined(); 21 return v8::Undefined();
23 } 22 }
24 23
25 v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments) 24 v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments)
26 { 25 {
27 return v8::Undefined(); 26 return v8::Undefined();
28 } 27 }
29 } 28 }
30 29
31 AdblockPlus::JsValuePtr AdblockPlus::ConsoleJsObject::Setup( 30 AdblockPlus::JsValuePtr AdblockPlus::ConsoleJsObject::Setup(
32 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValuePtr obj) 31 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj)
33 { 32 {
34 obj->SetProperty("error", jsEngine.NewCallback(::ErrorCallback)); 33 obj->SetProperty("error", jsEngine->NewCallback(::ErrorCallback));
35 obj->SetProperty("trace", jsEngine.NewCallback(::TraceCallback)); 34 obj->SetProperty("trace", jsEngine->NewCallback(::TraceCallback));
36 return obj; 35 return obj;
37 } 36 }
OLDNEW
« 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