This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27887 - "Mutation method macro" should handle empty nodes
Summary: "Mutation method macro" should handle empty nodes
Status: RESOLVED MOVED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-23 19:18 UTC by Joshua Bell
Modified: 2015-06-12 13:02 UTC (History)
3 users (show)

See Also:


Attachments

Description Joshua Bell 2015-01-23 19:18:15 UTC
https://dom.spec.whatwg.org/#mutation-method-macro (as of rev b7563aa)

Given one of the operations that references it, e.g.:

void prepend((Node or DOMString)... nodes);

Per Web IDL, the variadic argument can be omitted entirely, so e.g. myDiv.prepend() should not throw (unless specified to in prose).

The various operations don't specify special handling when called with no arguments. They execute the mutation method macro, which has:

1. Let /node/ be null.
2. Replace each string in /nodes/ with a Text node whose data is the string value.
3. If /nodes/ contains more than one node, set /node/ to a new DocumentFragment and append each node in /nodes/ to it. Rethrow any exceptions.
Otherwise, set /node/ to the single node /nodes/ contains.

Step 3 doesn't appear to handle the case if /nodes/ contains zero nodes. It's not more than one, but yet not a single node.

Proposed fix:

Replace "contains more than one node" with "contains exactly one node".

This would result in an empty DocumentFragment, which turns most of the ParentNode/ChildNode operations into no-ops when called with no argument except `replaceWith` which acts like `remove`.
Comment 1 Joshua Bell 2015-01-23 19:21:06 UTC
Oops, not "contains exactly one" since that inverts the meaning of the test.

"Contains more or less than one node", or flip the then/otherwise clauses, or explicitly handle 0. Whatevs.
Comment 2 Anne 2015-06-12 13:02:45 UTC
This is now https://github.com/whatwg/dom/issues/44 since it got reported again and GitHub is somewhat nicer. I like your suggestion.