Index: Source/core/page/DOMSelection.cpp |
diff --git a/Source/core/page/DOMSelection.cpp b/Source/core/page/DOMSelection.cpp |
index f26d1faf09a2082e36b8c049893b594bad9be3a5..2bc803c05bb1612a3fe270c66354e2c65505ef97 100644 |
--- a/Source/core/page/DOMSelection.cpp |
+++ b/Source/core/page/DOMSelection.cpp |
@@ -31,6 +31,7 @@ |
#include "config.h" |
#include "core/page/DOMSelection.h" |
+#include "bindings/v8/ExceptionMessages.h" |
#include "bindings/v8/ExceptionState.h" |
#include "bindings/v8/ExceptionStatePlaceholder.h" |
#include "core/dom/Document.h" |
@@ -199,7 +200,7 @@ void DOMSelection::collapse(Node* node, int offset, ExceptionState& es) |
return; |
if (offset < 0) { |
- es.throwDOMException(IndexSizeError); |
+ es.throwDOMException(IndexSizeError, ExceptionMessages::failedToExecute("collapse", "Selection", String::number(offset) + " is not a valid offset.")); |
return; |
} |
@@ -218,7 +219,7 @@ void DOMSelection::collapseToEnd(ExceptionState& es) |
const VisibleSelection& selection = m_frame->selection()->selection(); |
if (selection.isNone()) { |
- es.throwDOMException(InvalidStateError); |
+ es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecute("collapseToEnd", "Selection", "there is no selection.")); |
return; |
} |
@@ -233,7 +234,7 @@ void DOMSelection::collapseToStart(ExceptionState& es) |
const VisibleSelection& selection = m_frame->selection()->selection(); |
if (selection.isNone()) { |
- es.throwDOMException(InvalidStateError); |
+ es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecute("collapseToStart", "Selection", "there is no selection.")); |
return; |
} |
@@ -252,8 +253,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, ExceptionMessages::failedToExecute("setBaseAndExtent", "Selection", String::number(baseOffset) + " is not a valid base offset.")); |
+ return; |
+ } |
+ |
+ if (extentOffset < 0) { |
+ es.throwDOMException(IndexSizeError, ExceptionMessages::failedToExecute("setBaseAndExtent", "Selection", String::number(extentOffset) + " is not a valid extent offset.")); |
return; |
} |
@@ -272,7 +278,7 @@ void DOMSelection::setPosition(Node* node, int offset, ExceptionState& es) |
if (!m_frame) |
return; |
if (offset < 0) { |
- es.throwDOMException(IndexSizeError); |
+ es.throwDOMException(IndexSizeError, ExceptionMessages::failedToExecute("setPosition", "Selection", String::number(offset) + " is not a valid offset.")); |
return; |
} |
@@ -339,12 +345,16 @@ void DOMSelection::extend(Node* node, int offset, ExceptionState& es) |
return; |
if (!node) { |
- es.throwDOMException(TypeMismatchError); |
+ es.throwDOMException(TypeMismatchError, ExceptionMessages::failedToExecute("extend", "Selection", "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, ExceptionMessages::failedToExecute("extend", "Selection", String::number(offset) + " is not a valid offset.")); |
+ return; |
+ } |
+ if (offset > (node->offsetInCharacters() ? caretMaxOffset(node) : (int)node->childNodeCount())) { |
+ es.throwDOMException(IndexSizeError, ExceptionMessages::failedToExecute("extend", "Selection", String::number(offset) + " is larger than the given node's length.")); |
return; |
} |
@@ -361,7 +371,7 @@ PassRefPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState& es) |
return 0; |
if (index < 0 || index >= rangeCount()) { |
- es.throwDOMException(IndexSizeError); |
+ es.throwDOMException(IndexSizeError, ExceptionMessages::failedToExecute("getRangeAt", "Selection", String::number(index) + " is not a valid index.")); |
return 0; |
} |