Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Unified Diff: Source/core/dom/Range.cpp

Issue 23071006: Make Range::selectNode() and Range::surroundContents() to work with detached node (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 2013-08-22T18:44:46 Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/dom/Range/surroundContents-for-detached-node-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « LayoutTests/fast/dom/Range/surroundContents-for-detached-node-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698