Bug 1378147. Hold strong refs to elements when calling various functions that can run script. r=mystor

This commit is contained in:
Boris Zbarsky 2017-07-13 23:46:59 -04:00
Родитель d821ab4d73
Коммит aad387a7cd
2 изменённых файлов: 8 добавлений и 3 удалений

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

@ -352,7 +352,9 @@ ImageDocument::ShrinkToFit()
// changed and we don't plan to adjust the image size to compensate. Since
// mImageIsResized it has a "height" attribute set, and we can just get the
// displayed image height by getting .height on the HTMLImageElement.
HTMLImageElement* img = HTMLImageElement::FromContent(mImageContent);
//
// Hold strong ref, because Height() can run script.
RefPtr<HTMLImageElement> img = HTMLImageElement::FromContent(mImageContent);
uint32_t imageHeight = img->Height();
nsDOMTokenList* classList = img->ClassList();
ErrorResult ignored;
@ -652,7 +654,9 @@ ImageDocument::UpdateSizeFromLayout()
return;
}
nsIFrame* contentFrame = mImageContent->GetPrimaryFrame(FlushType::Frames);
// Need strong ref, because GetPrimaryFrame can run script.
nsCOMPtr<Element> imageContent = mImageContent;
nsIFrame* contentFrame = imageContent->GetPrimaryFrame(FlushType::Frames);
if (!contentFrame) {
return;
}

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

@ -1797,7 +1797,8 @@ nsXULWindow::GetPrimaryTabParentSize(int32_t* aWidth,
int32_t* aHeight)
{
TabParent* tabParent = TabParent::GetFrom(mPrimaryTabParent);
Element* element = tabParent->GetOwnerElement();
// Need strong ref, since Client* can run script.
nsCOMPtr<Element> element = tabParent->GetOwnerElement();
NS_ENSURE_STATE(element);
*aWidth = element->ClientWidth();