I've got a C++ XPCOM component that works great if I instantiate it
from JavaScript by using the technique of:
var myobj = Components.classes["my_contract_id"].
createInstance(Components.interfaces[Components.interfaces.myInterface]);
However, I'd like to attach this object to the Global so that I'll be
able to instantiate it like this instead:
var myobj = new MyObj();
I've placed put in some code that does the following (err checking
removed for brevity):
nsCOMPtr<myInterface> myobj = do_CreateInstance(MY_CONTRACTID);
nsIXPConnect *xpc = nsContentUtils::XPConnect();
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
rv = xpc->WrapNative(mContext, aGlobalObj, myobj,
NS_GET_IID(myInterface),
getter_AddRefs(wrapper));
JSObject* ourJSObject;
rv = wrapper->GetJSObject(&ourJSObject);
if(!JS_DefineProperty(mContext,
aGlobalObj,
"MyObj",
OBJECT_TO_JSVAL(ourJSObject),
nsnull, nsnull,
JSPROP_PERMANENT | JSPROP_READONLY ))
return NS_ERROR_FAILURE;
When I execute the following JavaScript:
var obj = new MyObj();
I get the following error:
JavaScript Error: "MyObj is not a constructor"
So JS knows the object is there, but I'm missing something related to
constructor-ness.
Can anyone point me to examples of how this is done?
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom