This is a two parter. First of all, as part of an extension I have an
xpcom component that wants to talk with Spidermonkey. I assume I can
use the currently running instance that already lives in Mozilla, and
in this case, how to I get a usable JSContext? I've tried:
// error handling removed
nsCOMPtr<nsIXPConnect> xpc = do_GetService("@mozilla.org/js/xpc/
XPConnect;1");
if (xpc)
{
nsCOMPtr<nsIXPCNativeCallContext> call;
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(call));
if (call)
{
JSContext * cx;
call->GetJSContext(&cx);
return cx;
and also:
nsCOMPtr<nsIJSContextStack> cxstack = do_GetService("@mozilla.org/
js/xpc/ContextStack;1");
if (cxstack)
{
JSContext * cx;
cxstack->Peek(&cx);
return cx;
Are either of these okay?
Secondly, assuming I have a good JSContext, I want to take
nsIDOMElement pointers from Gecko and wrap them in JSObjects so that I
can do javascript things to them, like looking up properties. I'm
trying this:
JSClass global_class = {
"global",0,
JS_PropertyStub,JS_PropertyStub,
JS_PropertyStub,JS_PropertyStub,
JS_EnumerateStub,JS_ResolveStub,
JS_ConvertStub,JS_FinalizeStub
};
JSObject * Wrap(JSContext * cx, nsISupports * supports)
{
JSObject * glob = JS_GetGlobalObject(cx);
if (glob)
{
made = JS_NewObject(cx, &global_class, glob, NULL);
if (made)
{
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc = do_GetService("@mozilla.org/js/xpc/
XPConnect;1");
if (xpc)
{
nsCOMPtr<nsIXPConnectJSObjectHolder> jshold;
rv = xpc->WrapNative(cx, made, supports, NS_GET_IID(nsISupports),
getter_AddRefs(jshold));
But this always returns NS_ERROR_XPC_BAD_CONVERT_NATIVE. Is this due
to making my JSContext incorrectly, or could I be doing something else
wrong?
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom