mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
8a6eb144ac
- Bug 1126544 - Update sixgill to handle more constructs and manage memory better (e487a0cd05) - Bug 1182407 - Use unpack feature of tooltool wherever possible. r=mshal (6bde76a413) - Bug 1123386 - Part 4: Update the tooltool manifests for the OSX and Linux static analysis builds in order to upgrade clang; r=rail (517ae90efa) - Bug 1204722 - Make sure that unboxed arrays created from literals are compatible with the type of the literal's elements, r=jandem. (400663edb4) - Bug 1117259 - Disable the no-unused-local-typedef warning if clang supports it; r=gps (16e2e49fc6) - Bug 1126813 - Turn on the -Wrange-loop-analysis warning if available; r=gps (1c783e1ed2) - Bug 1191688 - Add -nologo option to rc.exe. r=ted (9c5dbe2b89) - Bug 1150312 - Remove MOZ_SHARK. r=glandium (ba6db939d4) - Bug 1186636 - Add a pref to configure -moz prefixed gradients support. r=dholbert (9c41ae7460) - missing parts of Bug 1077282: Cleanup uses of GreD vs GreBinD, introcuded by v2 signature changes on OSX. Based on initial patch by rstrong. r=bsmedberg (af60bfc743) - de-palemoon (d8b7bae74f) - Bug 932100 - Part 1: Remove load-time dependency on user32. r=bsmedberg (9864a0ed0c) - missing part of Bug 932100 - Part 2: Move DLL blocklist code to mozglue. r=bsmedberg, r=glandium (6497ad86bd) - Bug 1194890 - Ensure that any user32 imports to mozglue are delay loaded; r=glandium (afa0a8d14e) - Bug 1082792 - Build firefox.exe with -MD in ASAN builds; r=glandium (89771bb4c0) - missing VPX/WEBM stuff (ec425938c9) - Bug 1184452 - Correctly reject @font-face descriptors that have garbage after them. r=heycam (f530fc858e) - Bug 1189922. Add a preference to enable global whitelisting of the CSSUnprefixingService. r=dholbert (e2997cb125) - Bug 1198732 - IonMonkey: MIPS32: Fix calculate frame size in generateEnterJIT. r=nbp (454d75946d) - Bug 1199057 - IonMonkey: MIPS32: Plumb new.target on the stack and make it accessible to JSNatives. r=nbp (01d5cb04c2) - Bug 1204306 - IonMonkey: MIPS32: Clean up MacroAssembler functions that aliased to Assembler. r=arai (600dc73280) - Bug 1199080 - IonMonkey: MIPS32: Fix treating saved frame bit as part# o the frame type. r=nbp (5e4e5ba250) - Bug 1099448 - Don't accept box properties with invalid calc() or rgb() etc. function values. r=dbaron (5737e8c300) - Bug 1203142 - Insert /**/ separate between two adjacent '-' symbols when serializing token streams. r=simon.sapin (06fb613d6c) - Bug 1057680 - Add support for font-stretch values in the font shorthand. r=jdaggett (8d8e24751d) - Bug 1155485 - Mark nsFrameManagerBase::mPresShell as MOZ_NON_OWNING_REF; r=roc (e79e28bbd0) - Bug 1121760 (part 5) - Remove PL_DHashMarkTableImmutable(). r=poiru. (8d8c7d9d65) - Bug 1121760 (part 6) - Move all remaining PL_DHash*() functions into PLDHashTable. r=poiru. (d36ec167cc)
343 lines
10 KiB
C++
343 lines
10 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
|
|
* described herein are Copyright (c) International Business Machines Corporation, 2000.
|
|
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
|
|
*
|
|
* Date Modified by Description of modification
|
|
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
|
|
*/
|
|
|
|
/**
|
|
* nsPropertyTable allows a set of arbitrary key/value pairs to be stored
|
|
* for any number of nodes, in a global hashtable rather than on the nodes
|
|
* themselves. Nodes can be any type of object; the hashtable keys are
|
|
* nsIAtom pointers, and the values are void pointers.
|
|
*/
|
|
|
|
#include "nsPropertyTable.h"
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
#include "pldhash.h"
|
|
#include "nsError.h"
|
|
#include "nsIAtom.h"
|
|
|
|
struct PropertyListMapEntry : public PLDHashEntryHdr {
|
|
const void *key;
|
|
void *value;
|
|
};
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
class nsPropertyTable::PropertyList {
|
|
public:
|
|
PropertyList(nsIAtom* aName,
|
|
NSPropertyDtorFunc aDtorFunc,
|
|
void* aDtorData,
|
|
bool aTransfer);
|
|
~PropertyList();
|
|
|
|
// Removes the property associated with the given object, and destroys
|
|
// the property value
|
|
bool DeletePropertyFor(nsPropertyOwner aObject);
|
|
|
|
// Destroy all remaining properties (without removing them)
|
|
void Destroy();
|
|
|
|
bool Equals(nsIAtom *aPropertyName)
|
|
{
|
|
return mName == aPropertyName;
|
|
}
|
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
|
|
|
nsCOMPtr<nsIAtom> mName; // property name
|
|
PLDHashTable mObjectValueMap; // map of object/value pairs
|
|
NSPropertyDtorFunc mDtorFunc; // property specific value dtor function
|
|
void* mDtorData; // pointer to pass to dtor
|
|
bool mTransfer; // whether to transfer in
|
|
// TransferOrDeleteAllPropertiesFor
|
|
|
|
PropertyList* mNext;
|
|
};
|
|
|
|
void
|
|
nsPropertyTable::DeleteAllProperties()
|
|
{
|
|
while (mPropertyList) {
|
|
PropertyList* tmp = mPropertyList;
|
|
|
|
mPropertyList = mPropertyList->mNext;
|
|
tmp->Destroy();
|
|
delete tmp;
|
|
}
|
|
}
|
|
|
|
void
|
|
nsPropertyTable::DeleteAllPropertiesFor(nsPropertyOwner aObject)
|
|
{
|
|
for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) {
|
|
prop->DeletePropertyFor(aObject);
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
nsPropertyTable::TransferOrDeleteAllPropertiesFor(nsPropertyOwner aObject,
|
|
nsPropertyTable *aOtherTable)
|
|
{
|
|
nsresult rv = NS_OK;
|
|
for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) {
|
|
if (prop->mTransfer) {
|
|
auto entry = static_cast<PropertyListMapEntry*>
|
|
(prop->mObjectValueMap.Search(aObject));
|
|
if (entry) {
|
|
rv = aOtherTable->SetProperty(aObject, prop->mName,
|
|
entry->value, prop->mDtorFunc,
|
|
prop->mDtorData, prop->mTransfer);
|
|
if (NS_FAILED(rv)) {
|
|
DeleteAllPropertiesFor(aObject);
|
|
aOtherTable->DeleteAllPropertiesFor(aObject);
|
|
|
|
break;
|
|
}
|
|
|
|
prop->mObjectValueMap.RemoveEntry(entry);
|
|
}
|
|
}
|
|
else {
|
|
prop->DeletePropertyFor(aObject);
|
|
}
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
void
|
|
nsPropertyTable::Enumerate(nsPropertyOwner aObject,
|
|
NSPropertyFunc aCallback, void *aData)
|
|
{
|
|
PropertyList* prop;
|
|
for (prop = mPropertyList; prop; prop = prop->mNext) {
|
|
auto entry = static_cast<PropertyListMapEntry*>
|
|
(prop->mObjectValueMap.Search(aObject));
|
|
if (entry) {
|
|
aCallback(const_cast<void*>(aObject.get()), prop->mName, entry->value,
|
|
aData);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
nsPropertyTable::EnumerateAll(NSPropertyFunc aCallBack, void* aData)
|
|
{
|
|
for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) {
|
|
for (auto iter = prop->mObjectValueMap.Iter(); !iter.Done(); iter.Next()) {
|
|
auto entry = static_cast<PropertyListMapEntry*>(iter.Get());
|
|
aCallBack(const_cast<void*>(entry->key), prop->mName, entry->value,
|
|
aData);
|
|
}
|
|
}
|
|
}
|
|
|
|
void*
|
|
nsPropertyTable::GetPropertyInternal(nsPropertyOwner aObject,
|
|
nsIAtom *aPropertyName,
|
|
bool aRemove,
|
|
nsresult *aResult)
|
|
{
|
|
NS_PRECONDITION(aPropertyName && aObject, "unexpected null param");
|
|
nsresult rv = NS_PROPTABLE_PROP_NOT_THERE;
|
|
void *propValue = nullptr;
|
|
|
|
PropertyList* propertyList = GetPropertyListFor(aPropertyName);
|
|
if (propertyList) {
|
|
auto entry = static_cast<PropertyListMapEntry*>
|
|
(propertyList->mObjectValueMap.Search(aObject));
|
|
if (entry) {
|
|
propValue = entry->value;
|
|
if (aRemove) {
|
|
// don't call propertyList->mDtorFunc. That's the caller's job now.
|
|
propertyList->mObjectValueMap.RemoveEntry(entry);
|
|
}
|
|
rv = NS_OK;
|
|
}
|
|
}
|
|
|
|
if (aResult)
|
|
*aResult = rv;
|
|
|
|
return propValue;
|
|
}
|
|
|
|
nsresult
|
|
nsPropertyTable::SetPropertyInternal(nsPropertyOwner aObject,
|
|
nsIAtom *aPropertyName,
|
|
void *aPropertyValue,
|
|
NSPropertyDtorFunc aPropDtorFunc,
|
|
void *aPropDtorData,
|
|
bool aTransfer,
|
|
void **aOldValue)
|
|
{
|
|
NS_PRECONDITION(aPropertyName && aObject, "unexpected null param");
|
|
|
|
PropertyList* propertyList = GetPropertyListFor(aPropertyName);
|
|
|
|
if (propertyList) {
|
|
// Make sure the dtor function and data and the transfer flag match
|
|
if (aPropDtorFunc != propertyList->mDtorFunc ||
|
|
aPropDtorData != propertyList->mDtorData ||
|
|
aTransfer != propertyList->mTransfer) {
|
|
NS_WARNING("Destructor/data mismatch while setting property");
|
|
return NS_ERROR_INVALID_ARG;
|
|
}
|
|
|
|
} else {
|
|
propertyList = new PropertyList(aPropertyName, aPropDtorFunc,
|
|
aPropDtorData, aTransfer);
|
|
propertyList->mNext = mPropertyList;
|
|
mPropertyList = propertyList;
|
|
}
|
|
|
|
// The current property value (if there is one) is replaced and the current
|
|
// value is destroyed
|
|
nsresult result = NS_OK;
|
|
auto entry = static_cast<PropertyListMapEntry*>
|
|
(propertyList->mObjectValueMap.Add(aObject, mozilla::fallible));
|
|
if (!entry)
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
// A nullptr entry->key is the sign that the entry has just been allocated
|
|
// for us. If it's non-nullptr then we have an existing entry.
|
|
if (entry->key) {
|
|
if (aOldValue)
|
|
*aOldValue = entry->value;
|
|
else if (propertyList->mDtorFunc)
|
|
propertyList->mDtorFunc(const_cast<void*>(entry->key), aPropertyName,
|
|
entry->value, propertyList->mDtorData);
|
|
result = NS_PROPTABLE_PROP_OVERWRITTEN;
|
|
}
|
|
else if (aOldValue) {
|
|
*aOldValue = nullptr;
|
|
}
|
|
entry->key = aObject;
|
|
entry->value = aPropertyValue;
|
|
|
|
return result;
|
|
}
|
|
|
|
nsresult
|
|
nsPropertyTable::DeleteProperty(nsPropertyOwner aObject,
|
|
nsIAtom *aPropertyName)
|
|
{
|
|
NS_PRECONDITION(aPropertyName && aObject, "unexpected null param");
|
|
|
|
PropertyList* propertyList = GetPropertyListFor(aPropertyName);
|
|
if (propertyList) {
|
|
if (propertyList->DeletePropertyFor(aObject))
|
|
return NS_OK;
|
|
}
|
|
|
|
return NS_PROPTABLE_PROP_NOT_THERE;
|
|
}
|
|
|
|
nsPropertyTable::PropertyList*
|
|
nsPropertyTable::GetPropertyListFor(nsIAtom* aPropertyName) const
|
|
{
|
|
PropertyList* result;
|
|
|
|
for (result = mPropertyList; result; result = result->mNext) {
|
|
if (result->Equals(aPropertyName)) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsPropertyTable::PropertyList::PropertyList(nsIAtom *aName,
|
|
NSPropertyDtorFunc aDtorFunc,
|
|
void *aDtorData,
|
|
bool aTransfer)
|
|
: mName(aName),
|
|
mObjectValueMap(PLDHashTable::StubOps(), sizeof(PropertyListMapEntry)),
|
|
mDtorFunc(aDtorFunc),
|
|
mDtorData(aDtorData),
|
|
mTransfer(aTransfer),
|
|
mNext(nullptr)
|
|
{
|
|
}
|
|
|
|
nsPropertyTable::PropertyList::~PropertyList()
|
|
{
|
|
}
|
|
|
|
void
|
|
nsPropertyTable::PropertyList::Destroy()
|
|
{
|
|
// Enumerate any remaining object/value pairs and destroy the value object.
|
|
if (mDtorFunc) {
|
|
for (auto iter = mObjectValueMap.Iter(); !iter.Done(); iter.Next()) {
|
|
auto entry = static_cast<PropertyListMapEntry*>(iter.Get());
|
|
mDtorFunc(const_cast<void*>(entry->key), mName, entry->value, mDtorData);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool
|
|
nsPropertyTable::PropertyList::DeletePropertyFor(nsPropertyOwner aObject)
|
|
{
|
|
auto entry =
|
|
static_cast<PropertyListMapEntry*>(mObjectValueMap.Search(aObject));
|
|
if (!entry)
|
|
return false;
|
|
|
|
void* value = entry->value;
|
|
mObjectValueMap.RemoveEntry(entry);
|
|
|
|
if (mDtorFunc)
|
|
mDtorFunc(const_cast<void*>(aObject.get()), mName, value, mDtorData);
|
|
|
|
return true;
|
|
}
|
|
|
|
size_t
|
|
nsPropertyTable::PropertyList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
|
{
|
|
size_t n = aMallocSizeOf(this);
|
|
n += mObjectValueMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
return n;
|
|
}
|
|
|
|
size_t
|
|
nsPropertyTable::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
{
|
|
size_t n = 0;
|
|
|
|
for (PropertyList *prop = mPropertyList; prop; prop = prop->mNext) {
|
|
n += prop->SizeOfIncludingThis(aMallocSizeOf);
|
|
}
|
|
|
|
return n;
|
|
}
|
|
|
|
size_t
|
|
nsPropertyTable::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
{
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
}
|
|
|
|
/* static */
|
|
void
|
|
nsPropertyTable::SupportsDtorFunc(void *aObject, nsIAtom *aPropertyName,
|
|
void *aPropertyValue, void *aData)
|
|
{
|
|
nsISupports *propertyValue = static_cast<nsISupports*>(aPropertyValue);
|
|
NS_IF_RELEASE(propertyValue);
|
|
}
|