Exposing the FunctionTemplate and Function objects should work across contexts (though I've never tried it myself). I think it should just work, but it is possible that security problems could arise. http://code.google.com/apis/v8/embed.html#security
I agree that exposing the FunctionTemplate is probably the easiest way to do what you are trying to do. The way I did it was significantly more complicated: I created an entire script engine layer which sits on top of v8 and abstracts all types and the entirety of v8 itself -- wrapping classes involves no use of Handles, etc. -- it is all abstracted. It makes some aspects of wrapping types dead simple (the last class I wrapped "just worked"), but comes with a penalty of extra overhead (and thus reduced performance) and extra complexity. That method probably not what you want nor need. Alex On Mar 11, 2009, at 3:28 PM, Stephan Beal wrote: > > Hi, all! > > When i create/set up a new JS class (e.g. a Function/ctor object), can > i then add *that instance* of the ctor to objects from any context, or > is *that* instance of the ctor only usable in the Context under which > it was constructed? > > Background: i've found that when wrapping classes, the classes are > difficult to "reach" from external code which doesn't have access to > the actual native wrappings. i would like to provide shared instances > of my wrappers so that external code (e.g. plugins) can get native- > side access to those wrappers. The primary reason for this is so that > i can pass arguments around between various plugins which have > knowledge of the base native types but no direct knowledge of the > actual bindings code. This is probably best explained with an example: > > Let's say we've got PluginOne which has this function: > > function doSomethingOne( OneType ); > > Now we have PluginTwo with: > > function doSomethingTwo( TwoType ); > > > i would like to be able to do, from PluginTwo: > > function doSomethingThree( OneType, TwoType ); > > The native implementation would need to be able to convert both types, > and the OneType is provided by a different plugin. Obviously, > PluginTwo would need to be linked to the same base classes used with > PluginOne, but PluginTwo may not have direct access to the > FunctionTemplate from which PluginOne's type(s) (e.g. OneType) are > created. > > i have the basic framework for that in place (the conversions to/from > native/js), but what i'm trying to do will only work (i think) for > this particular case if i can use shared instances of my class > wrappers (or at least the FunctionTemplate ctors) across different > Contexts. > > :-? > > Alex Iskander, TPSi --~--~---------~--~----~------------~-------~--~----~ v8-users mailing list [email protected] http://groups.google.com/group/v8-users -~----------~----~----~----~------~----~------~--~---
