D'oh I just copied/pasted someone else's previous example in the thread.
Yes, Local<Handle> is the right way. As far as the crash goes... If you check out the silkjs repository, you'll see I do near zero error checking in the C++ code. So it does crash, just like a C/C++ program will if you pass garbage to an OS call (for example). However, you can do something like this (which silkjs does do). Wrap the calls to C++ with JavaScript that does the error checking before calling the C++ function. IMO, it makes the API a lot cleaner. The C++ code might return false on failure, but your JavaScript API built on top of the C++ might want to throw an exception. The throwing of exceptions being YOUR API's method of choice of handling errors. Someone else's API might want to return true/false to indicate success. Cheers On Apr 12, 2012, at 4:45 AM, Stephan Beal wrote: > On Thu, Apr 12, 2012 at 1:32 PM, Mike Schwartz <[email protected]> wrote: > // this C++ function is callable from JS > v8::Persistent<v8::Function>::Cast(obj); > > Out of curiosity: why do you use Persistent there? i've never used Persistent > for a local-scope handle before. > > @OP: be very aware that Cast() will CRASH your app if obj is-not-a Function, > so check arg.IsObject() first. > > -- > ----- stephan beal > http://wanderinghorse.net/home/stephan/ > http://gplus.to/sgbeal > > > -- > 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
