t = "try{Components.classes.nsIXPConnect.getService(); failed = true; print('failed');}catch(e){print('passed');}";
t = "try{Components.classes['@mozilla.org/js/xpc/XPConnect;1'].getService(); failed = true; print('failed');}catch(e){print('passed');}";
TestSecurityManager(JSContext* jscontext, JSObject* glob, nsIXPConnect* xpc){    char* t;    jsval rval;    JSBool success = JS_TRUE;    MySecMan* sm = new MySecMan();    nsTestXPCFoo* foo = new nsTestXPCFoo();    if(!sm || ! foo)    {        success = JS_FALSE;        printf("failed to create object!\n");        goto sm_test_done;    }    rval = JSVAL_FALSE;    JS_SetProperty(jscontext, glob, "failed", &rval);    printf("Individual SecurityManager tests...\n");    if(!NS_SUCCEEDED(xpc->SetSecurityManagerForJSContext(jscontext, sm,                                        nsIXPCSecurityManager::HOOK_ALL)))    {        success = JS_FALSE;        printf("SetSecurityManagerForJSContext failed!\n");        goto sm_test_done;    }    printf("  build wrapper with veto: TEST NOT RUN\n");/*    // This test is broken because xpconnect now detects that this is a    // call from native code and lets it succeed without calling the security manager    sm->SetMode(MySecMan::VETO_ALL);    printf("  build wrapper with veto: ");    if(NS_SUCCEEDED(xpc->WrapNative(jscontext, glob, foo, NS_GET_IID(nsITestXPCFoo2), &wrapper)))    {        success = JS_FALSE;        printf("failed\n");        NS_RELEASE(wrapper);    }    else    {        printf("passed\n");    }*/    sm->SetMode(MySecMan::OK_ALL);    printf("  build wrapper no veto: ");    nsIXPConnectJSObjectHolder* holder;    if(NS_SUCCEEDED(xpc->WrapNative(jscontext, glob, foo,                     NS_GET_IID(nsITestXPCFoo2), &holder)))    {        printf("passed\n");        JSObject* obj;        if(NS_SUCCEEDED(holder->GetJSObject(&obj)))        {            rval = OBJECT_TO_JSVAL(obj);            JS_SetProperty(jscontext, glob, "foo", &rval);        }                    NS_RELEASE(holder);    }    else    {        success = JS_FALSE;        printf("failed\n");    }    sm->SetMode(MySecMan::OK_ALL);    printf("  getService no veto: ");    t = "try{Components.classes.nsIXPConnect.getService(); print('passed');}catch(e){failed = true; print('failed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::VETO_ALL);    printf("  getService with veto: ");    t = "try{Components.classes.nsIXPConnect.getService(); failed = true; print('failed');}catch(e){print('passed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::OK_ALL);    printf("  createInstance no veto: ");    t = "try{Components.classes.nsID.createInstance(Components.interfaces.nsIJSID); print('passed');}catch(e){failed = true; print('failed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::VETO_ALL);    printf("  getService with veto: ");    t = "try{Components.classes.nsID.createInstance(Components.interfaces.nsIJSID); failed = true; print('failed');}catch(e){print('passed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::OK_ALL);    printf("  call method no veto: ");    t = "try{foo.Test2(); print(' : passed');}catch(e){failed = true; print(' : failed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::VETO_ALL);    printf("  call method with veto: ");    t = "try{foo.Test2(); failed = true; print(' : failed');}catch(e){print(' : passed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::OK_ALL);    printf("  get attribute no veto: ");    t = "try{foo.Foo; print(' : passed');}catch(e){failed = true; print(' : failed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::VETO_ALL);    printf("  get attribute with veto: ");    t = "try{foo.Foo; failed = true; print(' : failed');}catch(e){print(' : passed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::OK_ALL);    printf("  set attribute no veto: ");    t = "try{foo.Foo = 0; print(' : passed');}catch(e){failed = true; print(' : failed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);    sm->SetMode(MySecMan::VETO_ALL);    printf("  set attribute with veto: ");    t = "try{foo.Foo = 0; failed = true; print(' : failed');}catch(e){print(' : passed');}";    JS_EvaluateScript(jscontext, glob, t, strlen(t), "builtin", 1, &rval);sm_test_done:    success = success && JS_GetProperty(jscontext, glob, "failed", &rval) && JSVAL_TRUE != rval;    printf("SecurityManager tests : %s\n", success ? "passed" : "failed");    NS_IF_RELEASE(foo);    xpc->SetSecurityManagerForJSContext(jscontext, nsnull, 0);}