rv = NS_InitXPCOM(NULL, NULL, NULL);
rv = NS_InitXPCOM(NULL, NULL);
main(int argc, char **argv){    JSRuntime *rt;    JSContext *jscontext;    JSObject *glob;    int result;    nsresult rv;    gErrFile = stderr;    gOutFile = stdout;    rv = NS_InitXPCOM(NULL, NULL, NULL);    NS_ASSERTION( NS_SUCCEEDED(rv), "NS_InitXPCOM failed" );    SetupRegistry();    NS_WITH_SERVICE(nsIJSRuntimeService, rtsvc, "nsJSRuntimeService", &rv);    // get the JSRuntime from the runtime svc, if possible    if (NS_FAILED(rv) ||        NS_FAILED(rtsvc->GetRuntime(&rt))) {        rtsvc = NULL;        rt = JS_NewRuntime(8L * 1024L * 1024L);    }    if (!rt)        return 1;    jscontext = JS_NewContext(rt, 8192);    if (!jscontext)        return 1;    JS_SetErrorReporter(jscontext, my_ErrorReporter);/*    JS_SetVersion(jscontext, JSVERSION_1_4); */    nsIXPConnect* xpc = GetXPConnect();    if(!xpc)    {        printf("GetXPConnect() returned NULL!\n");        return 1;    }    NS_WITH_SERVICE(nsIJSContextStack, cxstack, "nsThreadJSContextStack", &rv);    if(NS_FAILED(rv))    {        printf("failed to get the nsThreadJSContextStack service!\n");        return 1;    }    if(NS_FAILED(cxstack->Push(jscontext)))    {        printf("failed to get push the current jscontext on the nsThreadJSContextStack service!\n");        return 1;    }    glob = JS_NewObject(jscontext, &global_class, NULL, NULL);    if (!glob)        return 1;    if (!JS_InitStandardClasses(jscontext, glob))        return 1;    if (!JS_DefineFunctions(jscontext, glob, glob_functions))        return 1;    if (NS_FAILED(xpc->InitClasses(jscontext, glob)))        return 1;    argc--;    argv++;    result = ProcessArgs(jscontext, glob, argv, argc);    JS_ClearScope(jscontext, glob);    js_ForceGC(jscontext);    JSContext *oldcx;    cxstack->Pop(&oldcx);    NS_ASSERTION(oldcx == jscontext, "JS thread context push/pop mismatch");    js_ForceGC(jscontext);    JS_DestroyContext(jscontext);    xpc->SyncJSContexts();    xpc->DebugDump(4);    NS_RELEASE(xpc);    if (!rtsvc) {        /* no runtime service, so we have to handle shutdown */        JS_DestroyRuntime(rt);        JS_ShutDown();    }    rv = NS_ShutdownXPCOM( NULL );    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");    return result;}