Skip to content

Commit

Permalink
Unreviewed, reverting 267565@main.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261766

caused text to go missing on GitHub PR pages

Reverted changeset:

"Add mutation events tests for ContainerNode::replaceChildren and refactor the code"
https://bugs.webkit.org/show_bug.cgi?id=261016
https://commits.webkit.org/267565@main

Canonical link: https://commits.webkit.org/268143@main
  • Loading branch information
webkit-commit-queue authored and aestes committed Sep 19, 2023
1 parent c58657f commit 0b931b3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 79 deletions.
14 changes: 0 additions & 14 deletions LayoutTests/fast/dom/replace-children-mutation-events-expected.txt

This file was deleted.

31 changes: 0 additions & 31 deletions LayoutTests/fast/dom/replace-children-mutation-events.html

This file was deleted.

33 changes: 14 additions & 19 deletions Source/WebCore/dom/ContainerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,32 +1086,27 @@ ExceptionOr<void> ContainerNode::prepend(FixedVector<NodeOrString>&& vector)
// https://dom.spec.whatwg.org/#dom-parentnode-replacechildren
ExceptionOr<void> ContainerNode::replaceChildren(FixedVector<NodeOrString>&& vector)
{
auto targets = convertNodesOrStringsIntoNodeVector(WTFMove(vector));
for (auto& node : targets) {
if (auto result = ensurePreInsertionValidity(node, nullptr); result.hasException())
return result.releaseException();
if (auto result = node->remove(); result.hasException())
return result.releaseException();
// step 1
auto result = convertNodesOrStringsIntoNode(WTFMove(vector));
if (result.hasException())
return result.releaseException();
auto node = result.releaseReturnValue();

// step 2
if (node) {
if (auto checkResult = ensurePreInsertionValidity(*node, nullptr); checkResult.hasException())
return checkResult;
}

// step 3
Ref protectedThis { *this };
ChildListMutationScope mutation(*this);
NodeVector removedChildren;
auto didRemoveElements = removeAllChildrenWithScriptAssertion(ChildChange::Source::API, removedChildren, DeferChildrenChanged::Yes);
auto replacedAllChildren = (targets.size() && is<Element>(targets[0]))
|| didRemoveElements == DidRemoveElements::Yes ? ReplacedAllChildren::YesIncludingElements : ReplacedAllChildren::YesNotIncludingElements;
removeAllChildrenWithScriptAssertion(ChildChange::Source::API, removedChildren, DeferChildrenChanged::No);

for (auto& child : targets) {
if (child->parentNode())
break; // Exit early if mutation event listeners inserted child to elsewhere.

executeNodeInsertionWithScriptAssertion(*this, child, nullptr, ChildChange::Source::API, replacedAllChildren, [&] {
InspectorInstrumentation::willInsertDOMNode(document(), *this);
child->setTreeScopeRecursively(treeScope());
appendChildCommon(child);
});
replacedAllChildren = ReplacedAllChildren::No;
if (node) {
if (auto appendResult = appendChildWithoutPreInsertionValidityCheck(*node); appendResult.hasException())
return appendResult;
}

rebuildSVGExtensionsElementsIfNecessary();
Expand Down
20 changes: 6 additions & 14 deletions Source/WebCore/dom/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ static RefPtr<Node> firstFollowingSiblingNotInNodeSet(Node& context, const HashS
return nullptr;
}

Vector<Ref<Node>, 1> Node::convertNodesOrStringsIntoNodeVector(FixedVector<NodeOrString>&& nodeOrStringVector)
ExceptionOr<RefPtr<Node>> Node::convertNodesOrStringsIntoNode(FixedVector<NodeOrString>&& nodeOrStringVector)
{
if (nodeOrStringVector.isEmpty())
return { };
return nullptr;

Vector<Ref<Node>, 1> nodes;
Vector<Ref<Node>> nodes;
nodes.reserveInitialCapacity(nodeOrStringVector.size());
for (auto& variant : nodeOrStringVector) {
WTF::switchOn(variant,
Expand All @@ -589,19 +589,11 @@ Vector<Ref<Node>, 1> Node::convertNodesOrStringsIntoNodeVector(FixedVector<NodeO
);
}

return nodes;
}

ExceptionOr<RefPtr<Node>> Node::convertNodesOrStringsIntoNode(FixedVector<NodeOrString>&& nodeOrStringVector)
{
auto nodeVector = convertNodesOrStringsIntoNodeVector(WTFMove(nodeOrStringVector));
if (nodeVector.isEmpty())
return nullptr;
if (nodeVector.size() == 1)
return RefPtr<Node> { WTFMove(nodeVector[0]) };
if (nodes.size() == 1)
return RefPtr<Node> { WTFMove(nodes.first()) };

auto nodeToReturn = DocumentFragment::create(document());
for (auto& node : nodeVector) {
for (auto& node : nodes) {
auto appendResult = nodeToReturn->appendChild(node);
if (appendResult.hasException())
return appendResult.releaseException();
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/dom/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ class Node : public EventTarget {
void updateAncestorsForStyleRecalc();
void markAncestorsForInvalidatedStyle();

Vector<Ref<Node>, 1> convertNodesOrStringsIntoNodeVector(FixedVector<NodeOrString>&&);
ExceptionOr<RefPtr<Node>> convertNodesOrStringsIntoNode(FixedVector<NodeOrString>&&);

private:
Expand Down

0 comments on commit 0b931b3

Please sign in to comment.