I see.  You want to make the handle reference counted instead of the
pointer it manages.

I need to look a little more closely at the v8 handle code.  I was under
the assumption that v8::Handle was the base class for v8::Local and
v8::Persistent.  Where v8::Local would dispose of everything inside a
v8::HandleScope and v8::Persistent is only disposed manually.

With this, I can create a v8::Persistent where I can assign new v8::Values,
provided I check and dispose of any current value first.  Also, any class
that has a v8::Persistent as a member, must check and dispose of it when
destructed.  The wrapper template handles these cases automatically.

On Thu, Aug 22, 2013 at 11:19 PM, Jim Acquavella <[email protected]>wrote:

> But it's not reference counted and copyable. I want the last reference to
> dispose the handle.
>
> Sent from my iPad
>
> On Aug 22, 2013, at 20:33, Isaac Burns <[email protected]> wrote:
>
> 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<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 a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/v8-users/6kSAbnUb-rQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>  --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/v8-users/6kSAbnUb-rQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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.

Reply via email to