I can confirm that this code:
  obj->SetPrototype(ctorFunc->Get(String::New("prototype")));
does the job!
Maybe it's good enough for my purposes, although it would be nicer (and 
probably more efficient) to get the 'prototype' by a specialize call. 
Anyway, I need to do this only once when registering a new type in the 
context.


12 март 2012, понеделник 19:44:12 UTC+2, avasilev написа:
>
> In javascript it's doable by doing this:
>
> function MyType()
> {}
> var obj;
> obj.__proto__ = MyType.prototype;
>
>
> (obj instanceof MyType) will return true;
> However, trying to do this in C++, by doing
>
> obj->SetPrototype(MyTypeFunc->GetPrototype())
>
> does not work, and I can see that MyTypeFunc->GetPrototype() returns a 
> function, printed as:
> Empty{}
>
> Now the question is - how do I get the 'prototype' property of the 
> constructor? Maybe I should just get it as an ordinary property? Any ideas?
>
> 12 март 2012, понеделник 18:19:02 UTC+2, avasilev написа:
>>
>> Yes, it works for me also, but the problem is that this also calls the 
>> constructor invocation callback, which I want to avoid in this case.
>>
>>
>> 12 март 2012, понеделник 17:55:17 UTC+2, Stephan Beal написа:
>>>
>>> On Mon, Mar 12, 2012 at 4:39 PM, avasilev <[email protected]> wrote:
>>>
>>>> Basically I would like to be able to have instanceof working on objects 
>>>> that implement native bindings. If I create the object in C++ via 
>>>> Function::NewInstance(), then this works as expected. However, I want to 
>>>> be 
>>>> able to create an object both via the js constructor, and in C++ code 
>>>> without the C++ code calling the js constructor (which happend if I use 
>>>> Function::NewInstance()).
>>>
>>>
>>> If you want v8 to know about the object, the native ctor must tell it. 
>>> Or you can...
>>>  
>>>
>>>> Is it possible to do that? I tried to instantiate the object from the 
>>>> constructor's prototype template, via 
>>>> ctorFunc->PrototypeTemplate()->NewIsntance(), but this does not do the job 
>>>> and instanceof does not recognize the object as created by this 
>>>> constructor. Any ideas?
>>>>
>>>
>>> NewInstance() works for me. Here's an example of how i'm using it:
>>>
>>>
>>> http://code.google.com/p/v8-juice/source/browse/convert/include/cvv8/ClassCreator.hpp?r=2173#894
>>>
>>> The CastFromJS() call there essentially needs to be replaced with your 
>>> extract-native-from-JS-Object routine.
>>>
>>> If you want to be able to destroy such object from C++ code (don't use 
>>> delete - it will leave the v8 bits pointing at dead objects), there's an 
>>> example of that here:
>>>
>>>
>>> http://code.google.com/p/v8-juice/source/browse/convert/include/cvv8/ClassCreator.hpp?r=2173#971
>>>
>>> i hope that helps.
>>>
>>> -- 
>>> ----- stephan beal
>>> http://wanderinghorse.net/home/stephan/
>>> http://gplus.to/sgbeal
>>>
>>>

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

Reply via email to