On Sat, Apr 16, 2011 at 1:43 PM, crtmpserver <[email protected]> wrote:
> Assuming the point is created with var p=new Point(...);, Here is my > revised code. > > http://pastebin.com/UWYi403p Some terribly minor suggestions: ------------- #1 bool V8AppVirtualMachine::BindAPIPointClass(Handle<ObjectTemplate> global) Though, for this purpose, it is functionally identical, i recommend changing the parameter type to: (Handle<ObjectTemplate> & global) (note the '&'). This is cheaper, in terms of function call costs, as it avoids copying the Handle (which, granted, is actually just a very small wrapper object). ------------- #2 //3. Set its class name functionTemplate->SetClassName(String::New("Point")); that isn't strictly necessary, just FYI. It doesn't change how the class behaves, nor its name as it appears in the JS engine (that is set via Set(), as you do further down). ------------- #3 Handle<Value> getPointX(Local<String> property, const AccessorInfo &info) { //1. For brevity, this is hard-coded return Number::New(666.777); } When you get around to actually implementing the accessors and binding member functions and whatnot, there are several libraries which take much of the tedium out of that process by creating these bindings via C++ templates or (in more limited cases) macros. The libraries (which i know about) which fall into that category: http://code.google.com/p/v8-juice/ (that one's mine) https://github.com/tsa/vu8 http://code.google.com/p/cproxyv8/ http://code.google.com/p/v8cgi/ http://nodejs.org/ (That said, i'm assuming you are a new adopter of v8, and i think it's good that you write them by hand before using such a library, to better understand how v8 works.) -- ----- stephan beal http://wanderinghorse.net/home/stephan/ -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
