Index: include/AdblockPlus/V8ValueHolder.h |
=================================================================== |
--- a/include/AdblockPlus/V8ValueHolder.h |
+++ b/include/AdblockPlus/V8ValueHolder.h |
@@ -25,46 +25,61 @@ |
class Isolate; |
template<class T> class Handle; |
template<class T> class Persistent; |
+ class Value; |
} |
namespace AdblockPlus |
{ |
+ |
Felix Dahlke
2014/07/11 09:22:20
Superfluous whitespace.
|
template<class T> |
class V8ValueHolder |
{ |
public: |
V8ValueHolder() |
{ |
+ value = NULL; |
Wladimir Palant
2014/07/11 06:19:42
Note that we generally use 0 rather than NULL.
Felix Dahlke
2014/07/11 09:22:20
Also, if we actually want to move away from auto_p
sergei
2014/07/22 16:25:38
All members should be initialized in the ctr (in a
Wladimir Palant
2014/07/23 11:21:29
The reset() call below will set the isolate member
|
reset(0, v8::Persistent<T>()); |
} |
V8ValueHolder(V8ValueHolder& value) |
sergei
2014/07/22 16:25:38
Why is not const?
|
{ |
+ this->value = NULL; |
reset(value.isolate, static_cast<v8::Handle<T> >(value)); |
} |
V8ValueHolder(v8::Isolate* isolate, v8::Persistent<T> value) |
{ |
+ this->value = NULL; |
reset(isolate, value); |
} |
V8ValueHolder(v8::Isolate* isolate, v8::Handle<T> value) |
{ |
+ this->value = NULL; |
reset(isolate, value); |
} |
~V8ValueHolder() |
{ |
reset(isolate, v8::Persistent<T>()); |
sergei
2014/07/22 16:25:38
Superfluous space at the end of the line.
|
} |
+ |
+ static void ABPDisposeCallback(v8::Persistent<v8::Value> object, void* parameter) |
+ { |
+ v8::Persistent<v8::Value>* objectPointer = (v8::Persistent<v8::Value>*)parameter; |
sergei
2014/07/22 16:25:38
static cast
|
+ delete objectPointer; |
+ |
+ object.Dispose(); |
sergei
2014/07/22 16:25:38
In the docs it's said we should use ``Dispose(isol
|
+ object.Clear(); |
+ } |
+ |
void reset(v8::Isolate* isolate, v8::Persistent<T> value) |
{ |
- if (this->value.get()) |
+ if (this->value != NULL) |
{ |
- this->value->Dispose(this->isolate); |
- this->value.reset(0); |
+ this->value->MakeWeak(this->value, (v8::WeakReferenceCallback)&AdblockPlus::V8ValueHolder<T>::ABPDisposeCallback); |
Wladimir Palant
2014/07/11 06:19:42
So, why is calling Dispose() an issue here? This V
Felix Dahlke
2014/07/11 09:22:20
I agree, the actual change you made (turning this
Felix Dahlke
2014/07/11 09:24:16
Oh, and we should definitely also ensure to declar
sergei
2014/07/22 16:25:38
The recommended version is with `isolate`.
Oleksandr
2014/10/23 10:48:24
I think ideally we should let V8 dispose the handl
|
} |
if (!value.IsEmpty()) |
{ |
this->isolate = isolate; |
- this->value.reset(new v8::Persistent<T>(value)); |
+ this->value = new v8::Persistent<T>(value); |
} |
} |
@@ -87,7 +102,7 @@ |
} |
private: |
v8::Isolate* isolate; |
- std::auto_ptr<v8::Persistent<T> > value; |
+ v8::Persistent<T>* value; |
Wladimir Palant
2014/07/11 06:19:42
I don't consider using raw pointers a good idea -
Felix Dahlke
2014/07/11 09:22:20
Agreed, auto_ptr is evidently what we want here: D
Oleksandr
2014/10/23 10:48:24
The reason of a raw pointer here is that we want t
|
}; |
} |