Exemplo n.º 1
0
// static
XPCNativeSet*
XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, const nsIID* iid)
{
    AutoMarkingNativeSetPtr set(ccx);

    AutoMarkingNativeInterfacePtr iface(ccx);
    iface = XPCNativeInterface::GetNewOrUsed(ccx, iid);
    if(!iface)
        return nsnull;

    XPCNativeSetKey key(nsnull, iface, 0);

    XPCJSRuntime* rt = ccx.GetRuntime();
    NativeSetMap* map = rt->GetNativeSetMap();
    if(!map)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        set = map->Find(&key);
    }

    if(set)
        return set;

    // hacky way to get a XPCNativeInterface** using the AutoPtr
    XPCNativeInterface* temp[] = {iface}; 
    set = NewInstance(ccx, temp, 1);
    if(!set)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        XPCNativeSet* set2 = map->Add(&key, set);
        if(!set2)
        {
            NS_ERROR("failed to add our set!");
            DestroyInstance(set);
            set = nsnull;
        }
        else if(set2 != set)
        {
            DestroyInstance(set);
            set = set2;
        }
    }

    return set;
}
Exemplo n.º 2
0
// static
XPCNativeSet*
XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx,
                           XPCNativeSet* otherSet,
                           XPCNativeInterface* newInterface,
                           PRUint16 position)
{
    AutoMarkingNativeSetPtr set(ccx);
    XPCJSRuntime* rt = ccx.GetRuntime();
    NativeSetMap* map = rt->GetNativeSetMap();
    if(!map)
        return nsnull;

    XPCNativeSetKey key(otherSet, newInterface, position);

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        set = map->Find(&key);
    }

    if(set)
        return set;

    if(otherSet)
        set = NewInstanceMutate(otherSet, newInterface, position);
    else
        set = NewInstance(ccx, &newInterface, 1);

    if(!set)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        XPCNativeSet* set2 = map->Add(&key, set);
        if(!set2)
        {
            NS_ERROR("failed to add our set!");
            DestroyInstance(set);
            set = nsnull;
        }
        else if(set2 != set)
        {
            DestroyInstance(set);
            set = set2;
        }
    }

    return set;
}
// static
XPCNativeSet*
XPCNativeSet::GetNewOrUsed(const nsIID* iid)
{
    AutoJSContext cx;
    AutoMarkingNativeSetPtr set(cx);

    AutoMarkingNativeInterfacePtr iface(cx);
    iface = XPCNativeInterface::GetNewOrUsed(iid);
    if (!iface)
        return nullptr;

    XPCNativeSetKey key(nullptr, iface, 0);

    XPCJSRuntime* rt = XPCJSRuntime::Get();
    NativeSetMap* map = rt->GetNativeSetMap();
    if (!map)
        return nullptr;

    set = map->Find(&key);

    if (set)
        return set;

    // hacky way to get a XPCNativeInterface** using the AutoPtr
    XPCNativeInterface* temp[] = {iface};
    set = NewInstance(temp, 1);
    if (!set)
        return nullptr;

    XPCNativeSet* set2 = map->Add(&key, set);
    if (!set2) {
        NS_ERROR("failed to add our set!");
        DestroyInstance(set);
        set = nullptr;
    } else if (set2 != set) {
        DestroyInstance(set);
        set = set2;
    }

    return set;
}
// static
XPCNativeSet*
XPCNativeSet::GetNewOrUsed(XPCNativeSet* otherSet,
                           XPCNativeInterface* newInterface,
                           uint16_t position)
{
    AutoJSContext cx;
    AutoMarkingNativeSetPtr set(cx);
    XPCJSRuntime* rt = XPCJSRuntime::Get();
    NativeSetMap* map = rt->GetNativeSetMap();
    if (!map)
        return nullptr;

    XPCNativeSetKey key(otherSet, newInterface, position);

    set = map->Find(&key);

    if (set)
        return set;

    if (otherSet)
        set = NewInstanceMutate(otherSet, newInterface, position);
    else
        set = NewInstance(&newInterface, 1);

    if (!set)
        return nullptr;

    XPCNativeSet* set2 = map->Add(&key, set);
    if (!set2) {
        NS_ERROR("failed to add our set!");
        DestroyInstance(set);
        set = nullptr;
    } else if (set2 != set) {
        DestroyInstance(set);
        set = set2;
    }

    return set;
}