Bug 615977: Make nsCSSValue::BufferFromString() return an already_AddRefed pointer. r=dbaron a=roc

--HG--
extra : rebase_source : b4048d8fbde522f05a01df693887e0e26a5afb97
This commit is contained in:
Daniel Holbert 2010-12-05 13:17:29 +00:00
Родитель 3a4a5091d6
Коммит 0a34a22927
6 изменённых файлов: 16 добавлений и 12 удалений

Просмотреть файл

@ -1957,16 +1957,15 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes,
// Note that this should generally succeed here, due to the way
// |spec| is created. Maybe we should just add an nsStringBuffer
// accessor on nsAttrValue?
nsStringBuffer* buffer = nsCSSValue::BufferFromString(spec);
if (NS_LIKELY(buffer != 0)) {
nsRefPtr<nsStringBuffer> buffer = nsCSSValue::BufferFromString(spec);
if (NS_LIKELY(buffer)) {
// XXXbz it would be nice to assert that doc->NodePrincipal() is
// the same as the principal of the node (which we'd need to store
// in the mapped attrs or something?)
nsCSSValue::Image *img =
new nsCSSValue::Image(uri, buffer, doc->GetDocumentURI(),
doc->NodePrincipal(), doc);
buffer->Release();
if (NS_LIKELY(img != 0)) {
if (NS_LIKELY(img)) {
nsCSSValueList* list =
aData->mColorData->mBackImage.SetListValue();
list->mValue.SetImageValue(img);

Просмотреть файл

@ -126,7 +126,8 @@ nsSMILMappedAttribute::SetAnimValue(const nsSMILValue& aValue)
}
// Set the string as this mapped attribute's animated value.
nsStringBuffer* valStrBuf = nsCSSValue::BufferFromString(nsString(valStr));
nsStringBuffer* valStrBuf =
nsCSSValue::BufferFromString(nsString(valStr)).get();
nsRefPtr<nsIAtom> attrName = GetAttrNameAtom();
nsresult rv = mElement->SetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
attrName, valStrBuf,

Просмотреть файл

@ -4653,15 +4653,16 @@ CSSParserImpl::SetValueToURL(nsCSSValue& aValue, const nsString& aURL)
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), aURL, nsnull, mBaseURI);
nsStringBuffer* buffer = nsCSSValue::BufferFromString(aURL);
nsRefPtr<nsStringBuffer> buffer(nsCSSValue::BufferFromString(aURL));
if (NS_UNLIKELY(!buffer)) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
return PR_FALSE;
}
// Note: urlVal retains its own reference to |buffer|.
nsCSSValue::URL *urlVal =
new nsCSSValue::URL(uri, buffer, mSheetURI, mSheetPrincipal);
buffer->Release();
if (NS_UNLIKELY(!urlVal)) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
return PR_FALSE;

Просмотреть файл

@ -81,7 +81,7 @@ nsCSSValue::nsCSSValue(const nsString& aValue, nsCSSUnit aUnit)
{
NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string value");
if (UnitHasStringValue()) {
mValue.mString = BufferFromString(aValue);
mValue.mString = BufferFromString(aValue).get();
if (NS_UNLIKELY(!mValue.mString)) {
// XXXbz not much we can do here; just make sure that our promise of a
// non-null mValue.mString holds for string units.
@ -356,7 +356,7 @@ void nsCSSValue::SetStringValue(const nsString& aValue,
mUnit = aUnit;
NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string unit");
if (UnitHasStringValue()) {
mValue.mString = BufferFromString(aValue);
mValue.mString = BufferFromString(aValue).get();
if (NS_UNLIKELY(!mValue.mString)) {
// XXXbz not much we can do here; just make sure that our promise of a
// non-null mValue.mString holds for string units.
@ -598,7 +598,7 @@ nsCSSValue::EqualsFunction(nsCSSKeyword aFunctionId) const
}
// static
nsStringBuffer*
already_AddRefed<nsStringBuffer>
nsCSSValue::BufferFromString(const nsString& aValue)
{
nsStringBuffer* buffer = nsStringBuffer::FromString(aValue);
@ -608,6 +608,8 @@ nsCSSValue::BufferFromString(const nsString& aValue)
}
PRUnichar length = aValue.Length();
// NOTE: Alloc prouduces a new, already-addref'd (refcnt = 1) buffer.
buffer = nsStringBuffer::Alloc((length + 1) * sizeof(PRUnichar));
if (NS_LIKELY(buffer != 0)) {
PRUnichar* data = static_cast<PRUnichar*>(buffer->Data());

Просмотреть файл

@ -440,7 +440,8 @@ public:
// Returns an already addrefed buffer. Can return null on allocation
// failure.
static nsStringBuffer* BufferFromString(const nsString& aValue);
static already_AddRefed<nsStringBuffer>
BufferFromString(const nsString& aValue);
struct URL {
// Methods are not inline because using an nsIPrincipal means requiring

Просмотреть файл

@ -2844,7 +2844,7 @@ nsStyleAnimation::Value::SetUnparsedStringValue(const nsString& aString)
{
FreeValue();
mUnit = eUnit_UnparsedString;
mValue.mString = nsCSSValue::BufferFromString(aString);
mValue.mString = nsCSSValue::BufferFromString(aString).get();
if (NS_UNLIKELY(!mValue.mString)) {
// not much we can do here; just make sure that our promise of a
// non-null mValue.mString holds for string units.