Chromium Code Reviews| Index: Source/core/page/DOMSelection.cpp |
| diff --git a/Source/core/page/DOMSelection.cpp b/Source/core/page/DOMSelection.cpp |
| index f26d1faf09a2082e36b8c049893b594bad9be3a5..39d10d84158854f2493a4b6d814e72dcdd83ddac 100644 |
| --- a/Source/core/page/DOMSelection.cpp |
| +++ b/Source/core/page/DOMSelection.cpp |
| @@ -199,7 +199,7 @@ void DOMSelection::collapse(Node* node, int offset, ExceptionState& es) |
| return; |
| if (offset < 0) { |
| - es.throwDOMException(IndexSizeError); |
| + es.throwDOMException(IndexSizeError, "Failed to execute 'collapse' on a 'Selection' object: " + String::number(offset) + " is not a valid offset."); |
| return; |
| } |
| @@ -218,7 +218,7 @@ void DOMSelection::collapseToEnd(ExceptionState& es) |
| const VisibleSelection& selection = m_frame->selection()->selection(); |
| if (selection.isNone()) { |
| - es.throwDOMException(InvalidStateError); |
| + es.throwDOMException(InvalidStateError, "Failed to execute 'collapseToEnd' on a 'Selection' object: there is no selection."); |
|
arv (Not doing code reviews)
2013/08/13 13:57:31
I feel like we are repeating ourselves a lot. Mayb
Mike West
2013/08/13 14:00:17
I can do that. I have vague performance reluctance
arv (Not doing code reviews)
2013/08/13 14:07:49
Yeah, I don't think we need to optimize for the ex
|
| return; |
| } |
| @@ -233,7 +233,7 @@ void DOMSelection::collapseToStart(ExceptionState& es) |
| const VisibleSelection& selection = m_frame->selection()->selection(); |
| if (selection.isNone()) { |
| - es.throwDOMException(InvalidStateError); |
| + es.throwDOMException(InvalidStateError, "Failed to execute 'collapseToStart' on a 'Selection' object: there is no selection."); |
| return; |
| } |
| @@ -252,8 +252,13 @@ void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extent |
| if (!m_frame) |
| return; |
| - if (baseOffset < 0 || extentOffset < 0) { |
| - es.throwDOMException(IndexSizeError); |
| + if (baseOffset < 0) { |
| + es.throwDOMException(IndexSizeError, "Failed to execute 'setBaseAndExtent' on a 'Selection' object: " + String::number(baseOffset) + " is not a valid base offset."); |
| + return; |
| + } |
| + |
| + if (extentOffset < 0) { |
| + es.throwDOMException(IndexSizeError, "Failed to execute 'setBaseAndExtent' on a 'Selection' object: " + String::number(extentOffset) + " is not a valid extent offset."); |
| return; |
| } |
| @@ -272,7 +277,7 @@ void DOMSelection::setPosition(Node* node, int offset, ExceptionState& es) |
| if (!m_frame) |
| return; |
| if (offset < 0) { |
| - es.throwDOMException(IndexSizeError); |
| + es.throwDOMException(IndexSizeError, "Failed to execute 'setPosition' on a 'Selection' object: " + String::number(offset) + " is not a valid offset."); |
| return; |
| } |
| @@ -339,12 +344,16 @@ void DOMSelection::extend(Node* node, int offset, ExceptionState& es) |
| return; |
| if (!node) { |
| - es.throwDOMException(TypeMismatchError); |
| + es.throwDOMException(TypeMismatchError, "Failed to execute 'extend' on a 'Selection' object: The node provided is invalid."); |
| return; |
| } |
| - if (offset < 0 || offset > (node->offsetInCharacters() ? caretMaxOffset(node) : (int)node->childNodeCount())) { |
| - es.throwDOMException(IndexSizeError); |
| + if (offset < 0) { |
| + es.throwDOMException(IndexSizeError, "Failed to execute 'extend' on a 'Selection' object: " + String::number(offset) + " is not a valid offset."); |
| + return; |
| + } |
| + if (offset > (node->offsetInCharacters() ? caretMaxOffset(node) : (int)node->childNodeCount())) { |
| + es.throwDOMException(IndexSizeError, "Failed to execute 'extend' on a 'Selection' object: " + String::number(offset) + " is larger than the given node's length."); |
| return; |
| } |
| @@ -361,7 +370,7 @@ PassRefPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState& es) |
| return 0; |
| if (index < 0 || index >= rangeCount()) { |
| - es.throwDOMException(IndexSizeError); |
| + es.throwDOMException(IndexSizeError, "Failed to execute 'getRangeAt' on a 'Selection' object: " + String::number(index) + " is not a valid index."); |
| return 0; |
| } |