Hi, all!
As i understand it, we should not create Handles and such on the heap.
In fact, we cannot because their API won't allow it. But is it legal
to do this:
struct Foo
{
Handle<...> foo;
Handle<...> bar;
...
};
....
static Foo * shared = new Foo;
if( shared->foo.IsEmpty() )
{
... initialize shared object ...
}
:-?
My instinct tells me it's a bad idea, in particular if the Foo class
ever wants to use the v8 API internally (it could theoretically do so
after v8::IsDead(), post-main()).
Without the ability to share instances of JS-related data around
within an app, it becomes next to impossible for disparate C++ code to
instantiate new JS instances of a given class. e.g. if i bind MyClass
to JS, that binding necessarily creates a ctor function JS-side. So
far i have found no safe way to pass that Function handle amongst
native code in my application. i tried using a static instance of my
binder class, but that segfaults in v8 when static initialization
calls the default ctor. The only workaround i've come up with so far
(but untested) is to abuse the global object and store my private
ctors there using silly names which client code hopefully won't use.
If i can safely creating the object using 'new', even though it
contains an arbitrary amount of Handles and such, i might be able to
use a slightly less ugly hack to share my ctors (and to do so type-
safely, so the callers don't have to do so much error checking).
:-?
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---