On Sat, Apr 16, 2011 at 1:43 PM, crtmpserver <[email protected]> wrote:

> Hello,
>
> Thank you for the responses. Indeed, the code was screaming loud when
> the JS added property to prototype was NOT present in the new
> instance: I was creating a brand new object from the constructor
> itself, using the INITIAL template. So, the newly added properties
> from JS were not present.
>
> Assuming the point is created with var p=new Point(...);, Here is my
> revised code.
>
> http://pastebin.com/UWYi403p
>
> Ernst, at line 41 if I'm doing
> global->Set(String::New("Point"), functionTemplate->GetFunction());
>
> as you suggested, I get a nice big crash. GetFunction() returns a
> Function object, not template. Since I'm not in any context scope
> (still building the global template), I don't think that makes any
> sense. Am I right?
>

I was still puzzled by this part and I learned something new: you store a
function template in the global object template. But it comes out as a
function in the instantiated global object. There's transitive template
instantiation going on. It is implemented here:
http://www.google.com/codesearch/p?hl=en#W9JxUuHYyMg/trunk/src/apinatives.js&l=44;
function template instantiations are cached per context; object templates
are not. Two references to the same template give rise to two distinct
objects, a cyclic reference from an object template to itself will crash the
machine during instantiation.

In hindsight this may be obvious - the use of the global object template
would be severely limited otherwise - but still interesting to note.

Matthias


>
> Anyway, thank you both for bringing me on the right path and showed me
> the elephant in the room :). Now it works as expected
>
> Finally, if is not too much to ask, please take a look at the revised
> code and maybe you can throw me some more observations if any.
>
> Cheers,
> Andrei
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
>

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

Reply via email to