Sorry about assert, it's in internal handles (v8::internal::Handle).

Despite it's name val_ in v8::Handle is actually
v8::internal::Object** ---it's a location where a pointer to actual v8
object is stored.  v8's garbage collector is aware of all such handles
and would update v8::internal::Object* pointers when object is moved.

To see the problem you need the code like that (sorry, is not tested).

Local handleA(some object);
Local handleB(*handleA);

with your change handleA != handleB (as they use different locations
to store pointers---their val_ should be different).  W/o handleA ==
handleB as both point to the same object.

yours,
anton.

On Thu, Apr 1, 2010 at 5:01 PM, Evgeny Astigeevich <[email protected]> wrote:
> Could you please explain which assertion you mean?
> Another thing I don't understand:
>
> reinterpret_cast<internal::Object**>
>                                              ^^^  why additional
> pointer sematics is needed
>
> When a handle is empty the overloaded operator '*' returns null
> pointer value and reinterpret_cast converts it to null pointer value
> of destination type.
> Testing on Windows I don't get any problems when 'internal::Object*'
> is used instead of 'internal::Object**'.
>
> Best regards,
> Evgeny Astigeevich
>
> On Apr 1, 3:51 pm, Anton Muhin <[email protected]> wrote:
>> Good day, Evgeny.
>>
>> No.  Handle just another level of indirection.  So this code checks if
>> any of handles is empty (not referencing any objects) and if both are
>> not it checks if they reference the same object.  Your variant would
>> trigger an assertion if any of handles is empty.
>>
>> yours,
>> anton.
>>
>>
>>
>> On Thu, Apr 1, 2010 at 3:47 PM, Evgeny Astigeevich <[email protected]> wrote:
>> > Hi,
>>
>> > I'm trying to figure out the code of v8::Handle:
>>
>> >  template <class S> bool operator==(Handle<S> that) const {
>> >    internal::Object** a =
>> > reinterpret_cast<internal::Object**>(**this);
>> >    internal::Object** b =
>> > reinterpret_cast<internal::Object**>(*that);
>> >    if (a == 0) return b == 0;
>> >    if (b == 0) return false;
>> >    return *a == *b;
>> >  }
>>
>> > The overloaded operator '==' returns true when handles contain the
>> > same value.
>>
>> > Why is it written in such a way? Is it a workaround of compiler bugs?
>> > Does not the following code work:
>>
>> >  template <class S> bool operator==(Handle<S> that) const {
>> >    return reinterpret_cast<internal::Object*>(**this) ==
>> > reinterpret_cast<internal::Object*>(*that);
>> >  }
>>
>> > Best regards,
>> > Evgeny Astigeevich.
>>
>> > --
>> > v8-dev mailing list
>> > [email protected]
>> >http://groups.google.com/group/v8-dev
>>
>> > To unsubscribe, reply using "remove me" as the subject.
>
> --
> v8-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev
>

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

Reply via email to