I want to expose some classes to javascript so users can create
instances of them. From what I can piece together the code might look
something like so

Handle<FunctionTemplate> myObjectCtorFunction =
FunctionTemplate::New(MyObjectCtorCallback);
Handle<ObjectTemplate> myObjectInstanceTempl = myObjectCtorFunction-
>InstanceTemplate();
// setup properties and internal fields on myObjectInstanceTempl

// make ctor available to js
globals->Set("MyObject", myObjectCtorFunction);


Handle<Value> MyObjectCtorCallback(const Arguments& args)
{
    // args.IsConstructCall is true if used as ctor ?
    // args.Holder() is the already created instance?

    // so something like
    if (args.IsConstructCall()) {
        // create c++ object
        // set internal field of args.Holder() with c++ object
        return args.Holder()
    }

    return Undefined();
}


Is this correct? And what about destruction, how do I make sure I can
destroy my c++ object when the js object is collected?
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to