Bug 1451940: Don't reparse stylesheets when assigning empty string to empty element. r=bz

Per spec, assinging an empty string to textContent or innerHTML should not
trigger any mutation observers, and therefore should not trigger a stylesheet
reparse, when the element is already empty.

Since we need to apply some special handling to innerHTML and textContent
assignments to <style> nodes, and therefore re-parse directly in the setter
rather than in response to mutation observers, we need to special-case this
scenario.

MozReview-Commit-ID: KdOYFs8ayT7
This commit is contained in:
Kris Maglione
2018-04-10 11:06:26 -07:00
parent 6503ea7980
commit 9d59747c13
3 changed files with 79 additions and 0 deletions

View File

@@ -173,6 +173,16 @@ HTMLStyleElement::SetTextContentInternal(const nsAString& aTextContent,
nsIPrincipal* aScriptedPrincipal,
ErrorResult& aError)
{
// Per spec, if we're setting text content to an empty string and don't
// already have any children, we should not trigger any mutation observers, or
// re-parse the stylesheet.
if (aTextContent.IsEmpty() && !GetFirstChild()) {
nsIPrincipal* principal = mTriggeringPrincipal ? mTriggeringPrincipal.get() : NodePrincipal();
if (principal == aScriptedPrincipal) {
return;
}
}
SetEnableUpdates(false);
aError = nsContentUtils::SetNodeTextContent(this, aTextContent, true);