Ondřej, Stephan,

On Mon, Dec 6, 2010 at 11:02 PM, Stephan Beal <[email protected]> wrote:
> On Mon, Dec 6, 2010 at 8:41 PM, Ondřej Žára <[email protected]> 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.

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

Reply via email to