I found an example of the "magic args" approach combined with v8::External to differentiate how certain objects are constructed:
http://code.google.com/p/v8-juice/source/browse/trunk/src/lib/juice/PathFinder-cw.cc#72 Feel free to contact me off-list with questions about that code. On Jul 10, 2012 11:09 PM, "Stephan Beal" <[email protected]> wrote: > Briefly (i am on a tablet) : this can be done a few different ways, but > getting at the code is really tedious on a tablet :-\. I will post some > links to examples for you tomorrow. One quick idea: have the bound ctor > allow only some weird arguments and throw for everything else (and don't > document them in the js interface) . Your c++ code can then pass the weird > args to FunctionTemplate::NewInstace(). Example: require the args (null, > undefined, the real args...). Then throw if the args do not comply. There > are other (cleaner) ways, too, e.g. passing a v8::External to the ctor (js > code cannot create these). > On Jul 10, 2012 10:34 PM, "Kevin James" <[email protected]> wrote: > >> I want to write bindings for C++ objects whose constructors can't be >> called directly. Examples of what I'm talking about in a browser would >> be Element, ImageData, and Canvas. These are defined as functions in the >> global namespace, but if a script tries to call "new Element()", an >> exception is thrown. Instead an appropriate function has to be called, for >> example "document.createElement()". >> >> How are the bindings for these objects are written? If I create a >> FunctionTemplate, I can have it's constructor always throw an "Illegal >> Constructor" exception, but then how will my C++ code instantiate one of >> these objects? >> >> Thanks. >> >> -- >> 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
