I have used the following wrapper template to manage assigning new values
to a persistent handle.
The constructors are only for clarity. The real work is done in the
destructor and assignment operator.
It seems to work, but I welcome any corrections or feedback.
template <class T> class SafePersistent : public v8::Persistent<T>
{
public:
SafePersistent<T>() : v8::Persistent<T>() {}
SafePersistent<T>(v8::Handle<T> handle) : v8::Persistent<T>(handle) {}
~SafePersistent<T>() { CheckDispose(); }
v8::Persistent<T>& operator=(const v8::Persistent<T>& other)
{
CheckDispose();
return v8::Persistent<T>::operator=(other);
}
protected:
void CheckDispose()
{
if (!v8::Persistent<T>::IsEmpty())
{
v8::Persistent<T>::Dispose();
v8::Persistent<T>::Clear();
}
}
};
On Thursday, August 22, 2013 5:12:31 PM UTC-5, Jim Acquavella wrote:
>
> Why can't the Persistent use a RIAA pattern that's reference counted?
> Ideally, I'd like to create a persistent, copy it to another persistent
> (which would increment the reference), then the last one to go out of scope
> should be disposed automatically in the destructor. In other words, I'd
> like to use it like a boost::shared_ptr.
>
> http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
>
> This would tremendously simplify my code and ownership of these
> persistents.
>
> Thoughts?
>
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.