It is not really that clear to me from your question exactly what it is that you are asking.

nsDOMClassInfo is pretty much an internal DOM class. If you want to mess around with that stuff you should probably be talking to people on the DOM newsgroup.

The way to get xpconnect to call your Construct method on an implementation of nsIXPCScriptable is to OR the nsIXPCScriptable::WANT_CONSTRUCT with the other flags returned by your GetScriptableFlags method.

If you were not messing with the DOM stuff I'd suggest you use the macros in xpc_map_end.h to do this for you. There are plenty of examples of that. But, the DOM code has it's own way of managing the nsIXPCScriptable stuff.

And, FWIW, the most simple and generic way to expose a constructor method into JS is to execute a one line JS script using Components.Constructor to build the constructor method for you.

John.

DEIV wrote:
Thanks for your comments.

It looks like I was too busy with my question because now I have a problem
how to make JS-engine invoke method IXPCScriptable::Construct().
Actually I have helper class
class nsIntArraySH : public nsDOMClassInfo
with public method
NS_IMETHODIMP
Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                          JSObject *obj, PRUint32 argc, jsval *argv,
                          jsval *vp, PRBool *_retval)

The question is what is the right way to register this one?

Thanks

"John Bandhauer" <[EMAIL PROTECTED]> ???????/???????? ? ???????? ?????????: news:[EMAIL PROTECTED]
DEIV wrote:
there are some difficulties with using IXPCScriptable::Construct()...
I have a XPCOM class with constructor with one parameter. I would like
to write in my java scpirt something like this
var obj = new MyXPCOM(122);

how I should implement this function to provide this functionality?

  NS_IMETHOD Construct(nsIXPConnectWrappedNative *wrapper, JSContext *
cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool
*_retval)
{
???

return NS_OK;
}

Did you figure out how to do this?

There are a few instances of this that can be found in the mozilla tree using lxr.mozilla.org.

You might look at:
http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/src/xpccomponents.cpp#1207

This is nsXPCComponents_Exception::Construct. It is part of the internals of xpconnect. So, it has some aspects that would not make sense for other components. But, it is something to look at.

Basically, you: convert your JS argument(s). create your C++ object with whatever constructor or init method you need to call, use xpconnect to create a wrapper, get the JSObject* of the wrapper, return the JSObject*.

That code I referenced has things you would not want...

The " XPCCallContext" is an xpconnect internal thing. you would not need it.

You wouldn't need the nsIXPCSecurityManager either.

You can get a pointer to the nsIXPConnect object used for making the new wrapper from the 'XPConnect' attribute on the wrapper passed into the constructor.

As I said, there are other examples you might look at. I believe the DOM code uses IXPCScriptable::Construct too.

John.

Thanks



_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to