XPCAutoLock lock(rt->GetMapLock()); iface = map->Find(*iid); }  if(iface) return iface;  iface = NewInstance(ccx, info); if(!iface) return nsnull;
XPCAutoLock lock(mapLock); wrapper = map->Find(identity); if(wrapper) wrapper->AddRef(); }  if(wrapper) { if(!wrapper->FindTearOff(ccx, Interface, JS_FALSE, &rv)) { NS_RELEASE(wrapper); NS_ASSERTION(NS_FAILED(rv), "returning NS_OK on failure"); return rv; } DEBUG_CheckWrapperThreadSafety(wrapper); *resultWrapper = wrapper; return NS_OK; }           nsCOMPtr<nsIClassInfo> info(do_QueryInterface(identity));     JSBool isClassInfo = Interface->GetIID()->Equals(NS_GET_IID(nsIClassInfo));  XPCNativeScriptableCreateInfo sciProto; XPCNativeScriptableCreateInfo sciWrapper;  if(NS_FAILED(GatherScriptableCreateInfo(identity, isClassInfo ? nsnull : info.get(), &sciProto, &sciWrapper))) return NS_ERROR_FAILURE;  JSObject* parent = Scope->GetGlobalJSObject();  if(sciWrapper.GetFlags().WantPreCreate()) { JSObject* plannedParent = parent; nsresult rv = sciWrapper.GetCallback()->PreCreate(identity, ccx, parent, &parent); if(NS_FAILED(rv)) return rv;  if(parent != plannedParent) { XPCWrappedNativeScope* betterScope = XPCWrappedNativeScope::FindInJSObjectScope(ccx, parent); if(betterScope != Scope) return GetNewOrUsed(ccx, Object, betterScope, Interface, resultWrapper); }      { XPCAutoLock lock(mapLock); wrapper = map->Find(identity); if(wrapper) wrapper->AddRef(); }  if(wrapper) { if(!wrapper->FindTearOff(ccx, Interface, JS_FALSE, &rv)) { NS_RELEASE(wrapper); NS_ASSERTION(NS_FAILED(rv), "returning NS_OK on failure"); return rv; } DEBUG_CheckWrapperThreadSafety(wrapper); *resultWrapper = wrapper; return NS_OK; } }  AutoMarkingWrappedNativeProtoPtr proto(ccx);       if(info) { proto = XPCWrappedNativeProto::GetNewOrUsed(ccx, Scope, info, &sciProto, isClassInfo); if(!proto) return NS_ERROR_FAILURE;  wrapper = new XPCWrappedNative(identity, proto); if(!wrapper) return NS_ERROR_FAILURE; } else { AutoMarkingNativeSetPtr set(ccx); set = XPCNativeSet::GetNewOrUsed(ccx, nsnull, Interface, 0);  if(!set) return NS_ERROR_FAILURE;  wrapper = new XPCWrappedNative(identity, Scope, set); if(!wrapper) return NS_ERROR_FAILURE;  DEBUG_ReportShadowedMembers(set, wrapper, nsnull); }  if(!wrapper->Init(ccx, parent, &sciWrapper)) {  if(!wrapper->GetFlatJSObject()) wrapper->Release(); wrapper->Release(); return NS_ERROR_FAILURE; }  if(!wrapper->FindTearOff(ccx, Interface, JS_FALSE, &rv)) {  wrapper->Release(); NS_ASSERTION(NS_FAILED(rv), "returning NS_OK on failure"); return rv; }   XPCWrappedNative* wrapperToKill = nsnull;
XPCNativeInterface::GetNewOrUsed(XPCCallContext& ccx, nsIInterfaceInfo* info){    AutoMarkingNativeInterfacePtr iface(ccx);    const nsIID* iid;    if(NS_FAILED(info->GetIIDShared(&iid)) || !iid)        return nsnull;    XPCJSRuntime* rt = ccx.GetRuntime();    IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap();    if(!map)        return nsnull;    {   // scoped lock        XPCAutoLock lock(rt->GetMapLock());        iface = map->Find(*iid);    }    if(iface)        return iface;    iface = NewInstance(ccx, info);    if(!iface)        return nsnull;    {   // scoped lock        XPCAutoLock lock(rt->GetMapLock());        XPCNativeInterface* iface2 = map->Add(iface);        if(!iface2)        {            NS_ERROR("failed to add our interface!");            DestroyInstance(ccx, rt, iface);            iface = nsnull;        }        else if(iface2 != iface)        {            DestroyInstance(ccx, rt, iface);            iface = iface2;        }    }    return iface;}