diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-04-25 01:01:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-25 01:01:08 +0200 |
commit | a203f449bbc01f97564b7c5e2272b06a9569d7b4 (patch) | |
tree | 7193ae9ea7a77fcbd2c73ce0a9622b9fa836a013 /dom/base/nsDocument.cpp | |
parent | acd4eee44eb04fe01b0063818b492390f463ccec (diff) | |
parent | eae8d21428acdb3fb842df091ded0eb276bcaaaa (diff) | |
download | UXP-a203f449bbc01f97564b7c5e2272b06a9569d7b4.tar UXP-a203f449bbc01f97564b7c5e2272b06a9569d7b4.tar.gz UXP-a203f449bbc01f97564b7c5e2272b06a9569d7b4.tar.lz UXP-a203f449bbc01f97564b7c5e2272b06a9569d7b4.tar.xz UXP-a203f449bbc01f97564b7c5e2272b06a9569d7b4.zip |
Merge pull request #262 from janekptacijarabaci/js_dom_overflow_1
moebius#138: Optimize operations on root of deeply-nested frame tree
Diffstat (limited to 'dom/base/nsDocument.cpp')
-rw-r--r-- | dom/base/nsDocument.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index d5954a62c..fd3b52948 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2054,10 +2054,17 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup, mFirstChild = content->GetNextSibling(); } mChildren.RemoveChildAt(i); + if (content == mCachedRootElement) { + // Immediately clear mCachedRootElement, now that it's been removed + // from mChildren, so that GetRootElement() will stop returning this + // now-stale value. + mCachedRootElement = nullptr; + } nsNodeUtils::ContentRemoved(this, content, i, previousSibling); content->UnbindFromTree(); } - mCachedRootElement = nullptr; + MOZ_ASSERT(!mCachedRootElement, + "After removing all children, there should be no root elem"); } mInUnlinkOrDeletion = oldVal; @@ -3913,8 +3920,18 @@ nsDocument::RemoveChildAt(uint32_t aIndex, bool aNotify) DestroyElementMaps(); } - doRemoveChildAt(aIndex, aNotify, oldKid, mChildren); + // Preemptively clear mCachedRootElement, since we may be about to remove it + // from our child list, and we don't want to return this maybe-obsolete value + // from any GetRootElement() calls that happen inside of doRemoveChildAt(). + // (NOTE: for this to be useful, doRemoveChildAt() must NOT trigger any + // GetRootElement() calls until after it's removed the child from mChildren. + // Any call before that point would restore this soon-to-be-obsolete cached + // answer, and our clearing here would be fruitless.) mCachedRootElement = nullptr; + doRemoveChildAt(aIndex, aNotify, oldKid, mChildren); + MOZ_ASSERT(mCachedRootElement != oldKid, + "Stale pointer in mCachedRootElement, after we tried to clear it " + "(maybe somebody called GetRootElement() too early?)"); } void |