On Oct 21, 2008, at 12:57 AM, Christian Plesner Hansen wrote:

>
>> wrap->jsObject_ = Persistent<Object>(args.This());
>> instead of
>> wrap->jsObject_ = Persistent<Object>::New(args.This());
>>
>> I wonder what the use of the first constructor is?
>
> Persistent handles automatically convert to plain Handles so you can  
> do
>
>  Persistent<Object> obj = ...;
>  Handle<Object> hnd = obj;
>
> This means that you may have a Handle value that you know is a
> persistent handle.  In that case the first constructor can be used to
> "cast" the handle back to a persistent handle
>
>  Persistent<Object> re_obj = Persistent<Object>(hnd);
>
> Unfortunately the constructor does not verify that the handle being
> converted is a persistent handle, otherwise that would have caught the
> issue with your code.


Makes sense. I would recommend three things for this constructor:

in a debug build, assert it's been passed a persistent handle
declare it 'explicit' to make it less likely to be used by accident
add a comment explaining the situation

Sound right? Time to file a bug?

Pete Gontier <http://pete.gontier.org/>


--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to