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

Side by Side Diff: include/AdblockPlus/JsValue.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.
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 #ifndef ADBLOCKPLUS_JS_VALUE_H 1 #ifndef ADBLOCKPLUS_JS_VALUE_H
2 #define ADBLOCKPLUS_JS_VALUE_H 2 #define ADBLOCKPLUS_JS_VALUE_H
3 3
4 #include <string>
4 #include <vector> 5 #include <vector>
5 #include <v8.h> 6 #include <v8.h>
6 #ifdef _MSC_VER 7 #include "tr1_memory.h"
7 #include <memory>
8 #else
9 #include <tr1/memory>
10 #endif
11 8
12 namespace AdblockPlus 9 namespace AdblockPlus
13 { 10 {
11 class JsValue;
14 class JsEngine; 12 class JsEngine;
15 class JsValue;
16 13
17 typedef std::tr1::shared_ptr<JsValue> JsValuePtr; 14 typedef std::tr1::shared_ptr<JsValue> JsValuePtr;
18 typedef std::vector<AdblockPlus::JsValuePtr> JsValueList; 15 typedef std::vector<AdblockPlus::JsValuePtr> JsValueList;
19 16
17 // Forward declaration to avoid including JsEngine.h
18 typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr;
19
20 class JsValue 20 class JsValue
21 { 21 {
22 friend class JsEngine; 22 friend class JsEngine;
23 friend class JsObject; 23 friend class JsObject;
24 public: 24 public:
25 virtual ~JsValue(); 25 virtual ~JsValue();
26 26
27 bool IsUndefined() const; 27 bool IsUndefined() const;
28 bool IsNull() const; 28 bool IsNull() const;
29 bool IsString() const; 29 bool IsString() const;
(...skipping 17 matching lines...) Expand all
47 SetProperty(name, std::string(val)); 47 SetProperty(name, std::string(val));
48 } 48 }
49 inline void SetProperty(const std::string& name, int val) 49 inline void SetProperty(const std::string& name, int val)
50 { 50 {
51 SetProperty(name, static_cast<int64_t>(val)); 51 SetProperty(name, static_cast<int64_t>(val));
52 } 52 }
53 std::string GetClassName() const; 53 std::string GetClassName() const;
54 JsValuePtr Call(const JsValueList& params = JsValueList(), 54 JsValuePtr Call(const JsValueList& params = JsValueList(),
55 AdblockPlus::JsValuePtr thisPtr = AdblockPlus::JsValuePtr()) const; 55 AdblockPlus::JsValuePtr thisPtr = AdblockPlus::JsValuePtr()) const;
56 protected: 56 protected:
57 JsValue(JsEngine& jsEngine, v8::Handle<v8::Value> value); 57 JsValue(JsEnginePtr jsEngine, v8::Handle<v8::Value> value);
58 void SetProperty(const std::string& name, v8::Handle<v8::Value> val); 58 void SetProperty(const std::string& name, v8::Handle<v8::Value> val);
59 59
60 JsEngine& jsEngine; 60 JsEnginePtr jsEngine;
61 v8::Persistent<v8::Value> value; 61 v8::Persistent<v8::Value> value;
62 }; 62 };
63 } 63 }
64 64
65 #endif 65 #endif
OLDNEW
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | shell/src/GcCommand.h » ('j') | src/JsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld