one more question to V8 gurus: what *exactly* is the difference
between This and Holder (in v8::Arguments and v8::AccessorInfo)? I
just encountered [1] and realized that I use args.This() in many
places in my code - mostly to store/retrieve internal fields...
thanks for this link. After reading the thread, I conclude that This
and Holder can be safely treated as the same, as long as I can
guarantee that my method is called within the correct object (e.g. the
method is not assigned to a different object's property).
Thanks,
Ondrej
2010/12/6 Stephan Beal <sgb...@googlemail.com>:
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
thanks for this link. After reading the thread, I conclude that This
and Holder can be safely treated as the same, as long as I can
guarantee that my method is called within the correct object (e.g. the
method is not assigned to a different object's property).
On Mon, Dec 6, 2010 at 11:02 PM, Stephan Beal <sgb...@googlemail.com> wrote:
> On Mon, Dec 6, 2010 at 8:41 PM, Ondřej Žára <ondre...@gmail.com> wrote:
>>
>> thanks for this link. After reading the thread, I conclude that This
>> and Holder can be safely treated as the same, as long as I can
>> guarantee that my method is called within the correct object (e.g. the
>> method is not assigned to a different object's property).
>
> That's how i interpret it as well. If we're wrong, i hope one of the v8
> gurus who is reading this will correct us :).
They are not the same. This() corresponds to JS 'this' and should be
operated upon when you'd like to have a normal JS semantics.
Holder() is the objects which is instance of your FunctionTemplate.
That's not always easy to see the difference, but Christian gives a
nice example: x = { __proto__: document }, x.createElements("div").
In this case This would point to the objects pointed by 'x' variable
as well and Holder would point to object pointed by 'document'.
Therefore, if you expect some internal structure (for example, many
host objects wrap native objects and store pointers to them into
internal fields), attempt to use This would fail (it should have no
internal fields, or worse, you'll get wrong pointer), but Holder
should have expected internal fields.
Overall Holder should be always in the prototype chain of This and
hence if you read the property, you can freely use both. However
setting the property would behave differently if This() != Holder()
--- the property would end at different object.
So in each context This vs. Holder should be carefully chosen.
yours,
anton.
...So in each context This vs. Holder should be carefully chosen.