Index: Source/core/dom/Range.cpp |
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp |
index e9ddce35a9d3be597cf984417d1f11f56220618c..0d4e26657ddccfdcb5e8e07810cdfb43528d139e 100644 |
--- a/Source/core/dom/Range.cpp |
+++ b/Source/core/dom/Range.cpp |
@@ -25,6 +25,7 @@ |
#include "config.h" |
#include "core/dom/Range.h" |
+#include "bindings/v8/ExceptionMessages.h" |
#include "bindings/v8/ExceptionState.h" |
#include "bindings/v8/ExceptionStatePlaceholder.h" |
#include "core/dom/ClientRect.h" |
@@ -1285,6 +1286,11 @@ void Range::selectNode(Node* refNode, ExceptionState& es) |
return; |
} |
+ if (!refNode->parentNode()) { |
+ es.throwDOMException(InvalidNodeTypeError, ExceptionMessages::failedToExecute("selectNode", "Range", "the given Node has no parent.")); |
+ return; |
+ } |
+ |
// InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Notation or |
// DocumentType node or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity, or Notation |
// node. |
@@ -1329,10 +1335,8 @@ void Range::selectNode(Node* refNode, ExceptionState& es) |
if (m_ownerDocument != refNode->document()) |
setDocument(refNode->document()); |
- setStartBefore(refNode, es); |
- if (es.hadException()) |
- return; |
- setEndAfter(refNode, es); |
+ setStart(refNode->parentNode(), refNode->nodeIndex()); |
+ setEnd(refNode->parentNode(), refNode->nodeIndex() + 1); |
} |
void Range::selectNodeContents(Node* refNode, ExceptionState& es) |