On Sat, Mar 28, 2009 at 11:49 AM, Stephan Beal <[email protected]> wrote:
> What if Foo and Bar both hold an External at slot 0? Then IsExternal()
> will work, External::Cast() will work, but static_cast<Foo*>() won't
> work. In my experience, only one internal slot is ever used, so all
> bound classes are using slot 0 (i have yet to see a use case which
> would be simplified by using more than one slot).

Sorry, i hit send too quickly - i wanted to touch on how i work around
this problem.

In essence: when a native is created, i map its typeless void pointer
to the native value of itself. e.g.

Foo * f = new Foo;
someMappingRoutine<Foo>( f /* as void pointer*/, f /* native pointer */ )

in my bound functions i extract the external, get its void pointer,
then check my map to see if i have a void pointer of the correct type.
If not, fail gracefully (don't segfault, but throw a JS exception).
The whole process is automated by the class binding framework (see the
first article link i posted), but that's essentially what it boils
down to and it's easy to (re)implement. For native types which inherit
other natives i had to add some extra support so that a bound member
of SubType would pick up the "this" pointer when calling a
virtual/inherited native/bound member function, but that was
suprisingly easy to do (and ties in transparently to the void-to-T
conversion). That's all covered in the two links i posted above.

:)

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to