w3c / selection-api

Selection API
http://w3c.github.io/selection-api/
Other
47 stars 30 forks source link

Throw InvalidNodeTypeError on DocumentType nodes #118

Closed pshaughn closed 1 week ago

pshaughn commented 4 years ago

Various methods that take a node and offset are specified as throwing IndexSizeError if the offset exceeds the node's length. By WPT tests and by analogy with Range methods, these also need to throw InvalidNodeTypeError if the node is a DocumentType, and InvalidNodeType is the condition to check first for cases where both apply.

rniwa commented 4 years ago

Do all major browsers currently throw InvalidNodeTypeError?

pshaughn commented 4 years ago

Chrome, Firefox, and Edge do; Safari might not. https://wpt.fyi/results/selection/selectAllChildren.html?label=experimental&label=master&aligned has many cases involving a doctype.

darinadler commented 4 years ago

The specification already requires throwing InvalidNodeTypeError. Not directly, but indirectly. The specification has steps that say things like “set the start of newRange” and those steps will throw InvalidNodeTypeError because that’s part of the set the start or end algorithm from the DOM specification.

darinadler commented 4 years ago

Regarding the ordering of the checks, see also my comments in #124.

darinadler commented 4 years ago

Just looked at the WPT test and unfortunately it makes does the DOCUMENT_TYPE_NODE check before making the document.contains check, so it expects behavior different from what the specification currently requires.