nsIJSContext* xpccx = XPC_NewJSContext(cx); nsIJSObject* xpcglob = XPC_NewJSObject(xpccx, glob);  xpc->InitJSContext(xpccx, xpcglob);
xpc->InitJSContext(cx, glob);
int main(){    JSRuntime *rt;    JSContext *cx;    JSObject *glob;    gOutFile = stdout;    rt = JS_NewRuntime(8L * 1024L * 1024L);    if (!rt)        return 1;    cx = JS_NewContext(rt, 8192);    if (!cx)        return 1;    JS_SetErrorReporter(cx, my_ErrorReporter);    glob = JS_NewObject(cx, &global_class, NULL, NULL);    if (!glob)        return 1;    if (!JS_InitStandardClasses(cx, glob))        return 1;    if (!JS_DefineFunctions(cx, glob, glob_functions))        return 1;    nsIXPConnect* xpc = XPC_GetXPConnect();    nsIJSContext* xpccx = XPC_NewJSContext(cx);    nsIJSObject* xpcglob = XPC_NewJSObject(xpccx, glob);    xpc->InitJSContext(xpccx, xpcglob);    nsTestXPCFoo* foo = new nsTestXPCFoo();//    nsXPCVarient v[2];//    v[0].type = nsXPCType::T_I32; v[0].val.i32 = 1;//    v[1].type = nsXPCType::T_I32; v[1].val.i32 = 2;//    XPC_TestInvoke(foo, 3, 2, v);//    XPC_TestInvoke(foo, 4, 0, NULL);    nsIXPConnectWrappedNative* wrapper;    nsIXPConnectWrappedNative* wrapper2;    if(NS_SUCCEEDED(xpc->WrapNative(xpccx, foo, kIFooIID, &wrapper)))    {        if(NS_SUCCEEDED(xpc->WrapNative(xpccx, foo, kIFoo2IID, &wrapper2)))        {            JSObject* jsobj;            nsIJSObject* obj;            nsISupports* com_obj;            jsval rval;            xpc->GetJSObjectOfWrappedNative(wrapper2, &obj);            xpc->GetNativeOfWrappedNative(wrapper2, &com_obj);            obj->GetNative(&jsobj);            jsval v;            v = OBJECT_TO_JSVAL(jsobj);            JS_SetProperty(cx, glob, "foo", &v);            char* txt[] = {                "print('foo = '+foo);",                "foo.toString = new Function('return \"foo_baby\";')",                "print('foo = '+foo);",                "print('foo.toString() = '+foo.toString());",                "print('foo.five = '+ foo.five);",                "print('foo.six = '+ foo.six);",                "print('foo.bogus = '+ foo.bogus);",                "foo.bogus = 5;",                "print('foo.bogus = '+ foo.bogus);",                "print('foo.Test(10,20) returned: '+foo.Test(10,20));",                "function Test(p1, p2){print('test called in JS with p1 = '+p1+' and p2 = '+p2);return p1+p2;}",                "bar = new Object();",                "bar.Test = Test;",//                "bar.Test(5,7);",                "function QI(iid){print('QueryInterface called in JS with iid = '+iid); return  this;}",                "bar.QueryInterface = QI;",                "print('foo properties:');",                "for(i in foo)print('  foo.'+i+' = '+foo[i]);",                0,            };            for(char** p = txt; *p; p++)                JS_EvaluateScript(cx, glob, *p, strlen(*p), "builtin", 1, &rval);            if(JS_GetProperty(cx, glob, "bar", &v) && JSVAL_IS_OBJECT(v))            {                JSObject* bar = JSVAL_TO_OBJECT(v);                nsIXPConnectWrappedJS* wrapper;                if(NS_SUCCEEDED(xpc->WrapJS(xpccx,                                       XPC_NewJSObject(xpccx, JSVAL_TO_OBJECT(v)),                                       kIFooIID, &wrapper)))                {                    nsITestXPCFoo* ptr = (nsITestXPCFoo*)wrapper;                    int result;                    ptr->Test(11, 13, &result);                    printf("call to ptr->Test returned %d\n", result);                    NS_RELEASE(wrapper);                }            }            NS_RELEASE(obj);            NS_RELEASE(com_obj);            NS_RELEASE(wrapper2);        }        NS_RELEASE(wrapper);    }    NS_RELEASE(foo);    JS_GC(cx);    JS_DestroyContext(cx);    JS_DestroyRuntime(rt);    JS_ShutDown();    return 0;}