Bug 198578 - Implement ParentNode.prototype.replaceChildren
Summary: Implement ParentNode.prototype.replaceChildren
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tetsuharu Ohzeki [UTC+9]
URL:
Keywords: InRadar
Depends on:
Blocks: 212600 215600 217537
  Show dependency treegraph
 
Reported: 2019-06-05 13:54 PDT by Ryosuke Niwa
Modified: 2020-10-10 01:30 PDT (History)
10 users (show)

See Also:


Attachments
Patch (23.96 KB, patch)
2020-05-30 22:32 PDT, Tetsuharu Ohzeki [UTC+9]
no flags Details | Formatted Diff | Diff
Patch (22.99 KB, patch)
2020-06-01 08:48 PDT, Tetsuharu Ohzeki [UTC+9]
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 Anne van Kesteren 2020-03-29 23:46:42 PDT
Latest PR at https://github.com/whatwg/dom/pull/851. I'm going to assume y'all are still interested.
Comment 2 Chris Dumez 2020-03-30 08:18:45 PDT
(In reply to Anne van Kesteren from comment #1)
> Latest PR at https://github.com/whatwg/dom/pull/851. I'm going to assume
> y'all are still interested.

Sure.
Comment 3 Tetsuharu Ohzeki [UTC+9] 2020-05-29 06:05:53 PDT
May I take this?
Comment 4 Ryosuke Niwa 2020-05-29 14:10:59 PDT
(In reply to Tetsuharu Ohzeki from comment #3)
> May I take this?

You may!
Comment 5 Tetsuharu Ohzeki [UTC+9] 2020-05-30 22:32:04 PDT
Created attachment 400694 [details]
Patch
Comment 6 Darin Adler 2020-06-01 07:35:22 PDT
Comment on attachment 400694 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=400694&action=review

> Source/WebCore/dom/ContainerNode.cpp:674
> +// https://dom.spec.whatwg.org/#concept-node-replace-all
> +void ContainerNode::replaceAllChildrenNaively(Ref<Node>&& node)
> +{
> +    Ref<ContainerNode> protectedThis(*this);
> +    ChildListMutationScope mutation(*this);
> +    removeAllChildrenWithScriptAssertion(ChildChangeSource::API, DeferChildrenChanged::Yes);
> +
> +    // we assume that we check preinsertion validity on the caller side.
> +    auto result = appendChildWithoutPreInsertionValidityCheck(node);
> +    ASSERT_UNUSED(result, !result.hasException());
> +
> +    rebuildSVGExtensionsElementsIfNecessary();
> +    dispatchSubtreeModifiedEvent();
> +}

I don’t see the value in factoring this out as a named function. The pre-condition that you must already have checked pre-insertion validity makes it hard to use this correctly. I suggest just including this code in ContainerNode::replaceChildren for now, and factoring it out only if we find we have a good way to share code with other call sites.

I don’t understand why it is OK that this does not use executeNodeInsertionWithScriptAssertion.
Comment 7 Tetsuharu Ohzeki [UTC+9] 2020-06-01 08:24:02 PDT
(In reply to Darin Adler from comment #6)
> I don’t see the value in factoring this out as a named function. The
> pre-condition that you must already have checked pre-insertion validity
> makes it hard to use this correctly. I suggest just including this code in
> ContainerNode::replaceChildren for now, and factoring it out only if we find
> we have a good way to share code with other call sites.

Thank you review!
Okay. I'll change like that.


> I don’t understand why it is OK that this does not use
> executeNodeInsertionWithScriptAssertion.

As my understanding, ContainerNode::appendChildWithoutPreInsertionValidityCheck calls executeNodeInsertionWithScriptAssertion internally and appendChildWithoutPreInsertionValidityCheck has additional operations related to there is a parent.
Comment 8 Darin Adler 2020-06-01 08:26:07 PDT
(In reply to Tetsuharu Ohzeki from comment #7)
> (In reply to Darin Adler from comment #6)
> > I don’t understand why it is OK that this does not use
> > executeNodeInsertionWithScriptAssertion.
> 
> ContainerNode::appendChildWithoutPreInsertionValidityCheck calls
> executeNodeInsertionWithScriptAssertion internally

I see that now.
Comment 9 Tetsuharu Ohzeki [UTC+9] 2020-06-01 08:48:23 PDT
Created attachment 400735 [details]
Patch

I addressed the review comment.
Comment 10 EWS 2020-06-01 09:58:03 PDT
Committed r262381: <https://trac.webkit.org/changeset/262381>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 400735 [details].
Comment 11 Radar WebKit Bug Importer 2020-06-01 09:59:24 PDT
<rdar://problem/63833031>