Bug 1205923: Make VectorImage::GetWidth/GetHeight leave outparam untouched on failure, to avoid returning -1 to callers that don't check error codes. r=seth

This commit is contained in:
Daniel Holbert 2015-09-18 15:33:43 -07:00
parent 9925581040
commit 04e45a605c
4 changed files with 50 additions and 14 deletions

View File

@ -497,14 +497,18 @@ NS_IMETHODIMP
VectorImage::GetWidth(int32_t* aWidth)
{
if (mError || !mIsFullyLoaded) {
*aWidth = -1;
} else {
SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
"loading without errors");
*aWidth = rootElem->GetIntrinsicWidth();
return NS_ERROR_FAILURE;
}
return *aWidth >= 0 ? NS_OK : NS_ERROR_FAILURE;
SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
"loading without errors");
nscoord rootElemWidth = rootElem->GetIntrinsicWidth();
if (rootElemWidth < 0) {
return NS_ERROR_FAILURE;
}
*aWidth = rootElemWidth;
return NS_OK;
}
//******************************************************************************
@ -561,14 +565,18 @@ NS_IMETHODIMP
VectorImage::GetHeight(int32_t* aHeight)
{
if (mError || !mIsFullyLoaded) {
*aHeight = -1;
} else {
SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
"loading without errors");
*aHeight = rootElem->GetIntrinsicHeight();
return NS_ERROR_FAILURE;
}
return *aHeight >= 0 ? NS_OK : NS_ERROR_FAILURE;
SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
"loading without errors");
nscoord rootElemHeight = rootElem->GetIntrinsicHeight();
if (rootElemHeight < 0) {
return NS_ERROR_FAILURE;
}
*aHeight = rootElemHeight;
return NS_OK;
}
//******************************************************************************

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html class="reftest-wait">
<body>
</body>
<script>
function createImage() {
var newImage = new Image;
newImage.id = "thepreviewimage";
newImage.setAttribute("src", "unsized-svg.svg");
physWidth = newImage.width || 0;
physHeight = newImage.height || 0;
document.documentElement.innerHTML += newImage.width + " x " + newImage.height + "<br>";
}
function createImageAndEnd() {
createImage();
document.documentElement.removeAttribute("class");
}
// Trigger image load:
createImage();
// Asynchronously trigger image load again (hitting cache this time):
setTimeout(createImageAndEnd, 0);
</script>
</html>

View File

@ -52,3 +52,5 @@ skip-if(AddressSanitizer) skip-if(B2G) load 944353.jpg
load invalid-disposal-method-1.gif
load invalid-disposal-method-2.gif
load invalid-disposal-method-3.gif
load 1205923-1.html

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg"></svg>

After

Width:  |  Height:  |  Size: 47 B