On Mar 31, 3:36 pm, Alex Iskander <[email protected]> wrote: > I'd also like to be able to extend native classes, but I'm not sure > how I'd do it.
For the curious, i've got it working in my class binding framework. The code to do so is independent of the of the rest of libv8-juice, so it might serve as a useful starting or studying point for those wanting to do the same. The overall code is, however, admittedly a bit involved, and it does some rather confusing things in order to support inheritance, such that bound member functions will work properly when called from a subclass of the type of which they are members (i.e. the _real_ type to which they are actually bound, even though the JS object might be a subclass). For those interested in code, go to this page: http://code.google.com/p/v8-juice/wiki/CreatingJSClasses grab the 3 source files listed there (see the TOC). Then go to this page: http://code.google.com/p/v8-juice/wiki/ClassBinder Search the TOC for "Inheriting" and go to that section. That shows what needs to be done. The actual implementation is "a bit" tied up in the guts of the class binding framework. It starts here: http://code.google.com/p/v8-juice/source/browse/trunk/src/include/v8/juice/WeakJSClassCreator.h in GetSelf(). (Search for "* GetSelf" and you should jump right to it). The JS-side inheritance is supported by that function's calls to GetSelfFromPrototype(), which is basically a recursive call back to GetSelf(), and on each call it passes this.prototype, recursing up the prototype chain until no objects are found. As a proof of concept i've sucessfully subclassed curses window objects from JS code, as demonstrated on this page: http://code.google.com/p/v8-juice/wiki/PluginNCurses (Search for "Inheriting" and you'll find the TOC entry/link.) Happy hacking! --~--~---------~--~----~------------~-------~--~----~ v8-users mailing list [email protected] http://groups.google.com/group/v8-users -~----------~----~----~----~------~----~------~--~---
