Here's what I was able to scrape together based on the example given.

https://gist.github.com/Chaircrusher/48d53ee78567ca213f7a858e91e4771d

Questions:
1. Where do I add functions to the object template? I am doing it by 
calling ObjectTemplate::Set on the ObjectTemplate for the class.  Will that 
work for eg:

var x = new TestClass;
x.Method(something);

2. The constructor function for an object template -- I read conflicting 
information about how this is supposed to work. Some places say that the 
args.This() is an allocated instance of your object. The xample Yang Guo 
gave (which this code follows) suggests you have to allocate an object, set 
its Prototype to args.Holder()->GetPrototype().  Which is it?



On Thursday, December 15, 2016 at 12:20:13 AM UTC-6, Yang Guo wrote:
>
> Yes, the documentation for various APIs is a bit lacking, unless you 
> already know where to look. For what you are describing it sounds like you 
> want to take a look here:
>
>
> https://cs.chromium.org/chromium/src/v8/test/cctest/test-api.cc?q=test-api.cc&sq=package:chromium&dr&l=11365
>
> Cheers,
>
> Yang
>
>
>
>
> On Wednesday, December 14, 2016 at 11:53:31 PM UTC+1, kent williams wrote:
>>
>> Call me silly but I've spent this afternoon looking at v8/samples and the 
>> various web pages/blog entries (and the embedder's guide) and not getting a 
>> clear picture of how to create a new object type with methods and a 
>> constructor in v8.
>>
>> Is there a good example out there?
>>
>> In my particular case, I have this implemented using SpiderMonkey, which 
>> seems a lot more straightforward.  It has the JS_InitClass call where you 
>> pass in a constructor, a destructor, and an array of method descriptors.
>>
>> In v8, it seems spread out and confusing.  There's this: 
>> https://gist.github.com/mythagel/4527961 but end up sidetracked by 
>> decoding all the C++11 junk.
>>
>> If that's it, I'll just buckle down and figure it out. But if someone can 
>> point me at something to start from, I'd be much obliged!
>>
>

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to