Bug 1489437 - Part 2: HTML parser should invoke custom element's callbacks before appending child nodes if it is not created for fragment; r=smaug

See https://github.com/whatwg/html/issues/4025.

Depends on D10226

Differential Revision: https://phabricator.services.mozilla.com/D10228
This commit is contained in:
Edgar Chen 2021-01-05 21:40:26 +00:00
Родитель 3a7902f2c4
Коммит 030aaf9626
5 изменённых файлов: 37 добавлений и 9 удалений

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

@ -305,6 +305,13 @@ class CustomElementReactionsStack {
MOZ_ASSERT_IF(!mRecursionDepth, mReactionsStack.IsEmpty());
}
bool IsElementQueuePushedForCurrentRecursionDepth() {
MOZ_ASSERT_IF(mIsElementQueuePushedForCurrentRecursionDepth,
!mReactionsStack.IsEmpty() &&
!mReactionsStack.LastElement()->IsEmpty());
return mIsElementQueuePushedForCurrentRecursionDepth;
}
private:
~CustomElementReactionsStack() = default;
;

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

@ -134,13 +134,13 @@ key4 = Key 4
</script>
</head>
<body>
<p id="lightLabel"></p>
<template id="fluent-widget-template">
<div id="shadowDiv">
<p id="shadowLabel"></p>
</div>
</template>
<fluent-widget id="widget1"></fluent-widget>
<p id="lightLabel"></p>
</body>
</html>

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

@ -259,7 +259,21 @@ nsresult nsHtml5TreeOperation::Append(nsIContent* aNode, nsIContent* aParent,
nsresult nsHtml5TreeOperation::Append(nsIContent* aNode, nsIContent* aParent,
mozilla::dom::FromParser aFromParser,
nsHtml5DocumentBuilder* aBuilder) {
return Append(aNode, aParent, aBuilder);
Maybe<nsHtml5AutoPauseUpdate> autoPause;
Maybe<dom::AutoCEReaction> autoCEReaction;
dom::DocGroup* docGroup = aParent->OwnerDoc()->GetDocGroup();
if (docGroup && aFromParser != mozilla::dom::FROM_PARSER_FRAGMENT) {
autoCEReaction.emplace(docGroup->CustomElementReactionsStack(), nullptr);
}
nsresult rv = Append(aNode, aParent, aBuilder);
// Pause the parser only when there are reactions to be invoked to avoid
// pausing parsing too aggressive.
if (autoCEReaction.isSome() && docGroup &&
docGroup->CustomElementReactionsStack()
->IsElementQueuePushedForCurrentRecursionDepth()) {
autoPause.emplace(aBuilder);
}
return rv;
}
nsresult nsHtml5TreeOperation::AppendToDocument(

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

@ -1,4 +0,0 @@
[parser-sets-attributes-and-children.html]
[HTML parser should call connectedCallback before appending child nodes.]
expected: FAIL

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

@ -14,10 +14,16 @@
<div id="log"></div>
<script>
class MyCustomElement extends HTMLElement { }
var numberOfChildNodesInConnectedCallback = 0;
class MyCustomElement extends HTMLElement {
connectedCallback() {
numberOfChildNodesInConnectedCallback = this.childNodes.length;
}
}
customElements.define('my-custom-element', MyCustomElement);
document.write('<my-custom-element></my-custom-element>');
document.write('<my-custom-element>hello <b>world</b></my-custom-element>');
test(function () {
var instance = document.querySelector('my-custom-element');
@ -27,6 +33,11 @@ test(function () {
}, 'HTML parser must instantiate custom elements inside document.write');
test(function () {
assert_equals(numberOfChildNodesInConnectedCallback, 0);
}, 'HTML parser should call connectedCallback before appending child nodes inside document.write');
</script>
</body>
</html>