If we call selection.removeAllRanges() or selection.getRangeAt(0).detach(), then perhaps selection.modify() should throw an exception, indicating that there's no selection to modify. selection.modify() currently silently fails in this case.
DOMException INVALID_STATE_ERR is used in HTML5 Selection when there's something wrong with the selection range: http://www.whatwg.org/specs/web-apps/current-work/#selection-0 and in DOM-Level-2-Traversal-Range when using a detached range: http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-idl so INVALID_STATE_ERR seems like the appropriate exception to use here.
I don't think we should do that. There is a significant chance that raising an exception where we didn't do that previously will break some pages - and the potential benefit is extremely minor.
I agree with Alexey. Throwing an exception at this point will break existing web pages. Does Firefox 4 throws an exception in such cases?
FYI, Bug 33509 had similar discussion and concludes not to throw an exception.
(In reply to comment #4) > FYI, Bug 33509 had similar discussion and concludes not to throw an exception. Ok. We should close these bugs as invalid.
Oops, I meant wontfix.
(In reply to comment #3) > I agree with Alexey. Throwing an exception at this point will break existing web pages. Does Firefox 4 throws an exception in such cases? We silently fail. +1 on the WONTFIX.