rv = xpc->InitClasses(cx, sandbox); if (NS_SUCCEEDED(rv) && !JS_DefineFunctions(cx, sandbox, SandboxFunctions)) { rv = NS_ERROR_FAILURE; } if (NS_FAILED(rv)) return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
nsXPCComponents_ID::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,                                    JSContext * cx, JSObject * obj,                                    PRUint32 argc, jsval * argv,                                    jsval * vp, PRBool *_retval){    // make sure we have at least one arg    if(!argc)        return ThrowAndFail(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx, _retval);    XPCCallContext ccx(JS_CALLER, cx);    if(!ccx.IsValid())        return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);    XPCContext* xpcc = ccx.GetXPCContext();    // Do the security check if necessary    nsIXPCSecurityManager* sm =            xpcc->GetAppropriateSecurityManager(                        nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);    if(sm && NS_FAILED(sm->CanCreateInstance(cx, nsJSID::GetCID())))    {        // the security manager vetoed. It should have set an exception.        *_retval = JS_FALSE;        return NS_OK;    }    // convert the first argument into a string and see if it looks like an id    JSString* jsstr;    const char* str;    nsID id;    if(!(jsstr = JS_ValueToString(cx, argv[0])) ||       !(str = JS_GetStringBytes(jsstr)) ||       ! id.Parse(str))    {        return ThrowAndFail(NS_ERROR_XPC_BAD_ID_STRING, cx, _retval);    }    // make the new object and return it.    JSObject* newobj = xpc_NewIDObject(cx, obj, id);    if(vp)        *vp = OBJECT_TO_JSVAL(newobj);    return NS_OK;}