зеркало из https://github.com/mozilla/gecko-dev.git
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 --HG-- extra : rebase_source : 67b85174d08028c5200964800b657950aa2bffa2
This commit is contained in:
Родитель
833fe43cb6
Коммит
2475362f04
|
@ -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);
|
||||
|
|
|
@ -318231,6 +318231,12 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"css/cssom/css-style-reparse.html": [
|
||||
[
|
||||
"/css/cssom/css-style-reparse.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"css/cssom/cssimportrule.html": [
|
||||
[
|
||||
"/css/cssom/cssimportrule.html",
|
||||
|
@ -531800,6 +531806,10 @@
|
|||
"c169d758c1d91b75697b04cf72750f8ac1650e1a",
|
||||
"testharness"
|
||||
],
|
||||
"css/cssom/css-style-reparse.html": [
|
||||
"d83b1fde05df64628f67b7773757c12d213f566b",
|
||||
"testharness"
|
||||
],
|
||||
"css/cssom/cssimportrule.html": [
|
||||
"c7a70c7836b5a31631b12cc47f280d507542571d",
|
||||
"testharness"
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>CSS Test: DOM modification re-parsing test</title>
|
||||
<link rel="help" href="https://drafts.csswg.org/cssom/">
|
||||
<link rel="help" href="http://www.w3.org/TR/cssom-1/#the-cssrule-interface">
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<style>div { min-width: 0px; }</style>
|
||||
<style id="style-element"></style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="test-div"></div>
|
||||
<script type="text/javascript">
|
||||
var style = document.getElementById("style-element");
|
||||
var div = document.getElementById("test-div");
|
||||
|
||||
function testProperty(prop) {
|
||||
// Assigning an empty string to textContent or innerHTML should trigger a
|
||||
// reparse only if the element is not empty.
|
||||
style.sheet.insertRule("#test-div { min-width: 42px; }");
|
||||
assert_equals(getComputedStyle(div).minWidth, "42px");
|
||||
|
||||
style[prop] = "";
|
||||
assert_equals(getComputedStyle(div).minWidth, "42px");
|
||||
|
||||
style[prop] = " ";
|
||||
assert_equals(getComputedStyle(div).minWidth, "0px");
|
||||
|
||||
style.sheet.insertRule("#test-div { min-width: 42px; }");
|
||||
assert_equals(getComputedStyle(div).minWidth, "42px");
|
||||
|
||||
style[prop] = "";
|
||||
assert_equals(getComputedStyle(div).minWidth, "0px");
|
||||
|
||||
style.sheet.insertRule("#test-div { min-width: 42px; }");
|
||||
assert_equals(getComputedStyle(div).minWidth, "42px");
|
||||
|
||||
style.appendChild(document.createTextNode(""));
|
||||
assert_equals(getComputedStyle(div).minWidth, "0px");
|
||||
|
||||
style.sheet.insertRule("#test-div { min-width: 42px; }");
|
||||
assert_equals(getComputedStyle(div).minWidth, "42px");
|
||||
|
||||
style[prop] = "";
|
||||
assert_equals(getComputedStyle(div).minWidth, "0px");
|
||||
}
|
||||
|
||||
test(function() {
|
||||
testProperty("textContent");
|
||||
}, "style.textContent modification");
|
||||
|
||||
test(function() {
|
||||
testProperty("innerHTML");
|
||||
}, "style.innerHTML modification");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче