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

Unified Diff: third_party/WebKit/Source/core/editing/DOMSelection.cpp

Issue 2693813002: Selection API: Some functions should throw InvalidNodeTypeError and IndexSizeError. (Closed)
Patch Set: adjust 2 more tests Created 3 years, 10 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
Index: third_party/WebKit/Source/core/editing/DOMSelection.cpp
diff --git a/third_party/WebKit/Source/core/editing/DOMSelection.cpp b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
index 51727bb61623b756fa56932170375529f905591e..20b6dfd4de3acc5c7105b96853e749e006df6086 100644
--- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
@@ -197,13 +197,13 @@ void DOMSelection::collapse(Node* node,
IndexSizeError, String::number(offset) + " is not a valid offset.");
return;
}
-
- if (!isValidForPosition(node))
- return;
Range::checkNodeWOffset(node, offset, exceptionState);
if (exceptionState.hadException())
return;
+ if (!isValidForPosition(node))
+ return;
+
frame()->selection().setSelection(
SelectionInDOMTree::Builder()
.collapse(Position(node, offset))
@@ -285,6 +285,15 @@ void DOMSelection::setBaseAndExtent(Node* baseNode,
extentOffset = 0;
}
+ Range::checkNodeWOffset(baseNode, baseOffset, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ if (extentNode) {
+ Range::checkNodeWOffset(extentNode, extentOffset, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ }
+
if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
return;
@@ -380,12 +389,9 @@ void DOMSelection::extend(Node* node,
IndexSizeError, String::number(offset) + " is not a valid offset.");
return;
}
- if (static_cast<unsigned>(offset) > node->lengthOfContents()) {
- exceptionState.throwDOMException(
- IndexSizeError,
- String::number(offset) + " is larger than the given node's length.");
+ Range::checkNodeWOffset(node, offset, exceptionState);
+ if (exceptionState.hadException())
return;
- }
if (!isValidForPosition(node))
return;

Powered by Google App Engine
This is Rietveld 408576698