This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
Today, the Selection API spec seems to say that if selection.rangeCount is 0, then selection.extend should throw an error and abort. This is true in Firefox, but not Chrome. In Chrome, it appears that a new collapsed range is created at the position specified in selection.extend. Without an error, it's possible a site might end up creating a selection when they think they're extending it. But errors in JS should be used sparingly. Not sure which of these makes more sense.
Proposed text, based on the text for collapse(): void setBaseAndExtent (Node baseNode, unsigned long baseOffset, Node extentNode, unsigned long extentOffset); The method must throw an IndexSizeError exception if offset is negative or longer than node's length ([DOM4]). Otherwise, it must create a new range, set ([DOM4]) its start to (baseNode, baseOffset) and its and end to (extentNode, extentOffset), and set the context object's range to the newly-created range.
Ignore the last comment, Bugzilla was having login trouble that caused it to post to the wrong bug.
(In reply to Ben Peters from comment #0) > Today, the Selection API spec seems to say that if selection.rangeCount is > 0, then selection.extend should throw an error and abort. This is true in > Firefox, but not Chrome. In Chrome, it appears that a new collapsed range is > created at the position specified in selection.extend. Without an error, > it's possible a site might end up creating a selection when they think > they're extending it. But errors in JS should be used sparingly. Not sure > which of these makes more sense. This is taken care of by the first step in its definition: "If the context object is empty, throw an InvalidStateError exception and abort these steps." since the definition of "empty" is "Each selection can be associated with a single range (defined in [DOM4]). When there is no range associated with the selection, the selection is empty. The selection must be initially empty."