Range.compareBoundaryPoints should throw a NotSupportedError when how has not expected value

SPEC: http://dom.spec.whatwg.org/#dom-range-compareboundarypoints

This CL also added interface type checking so appropriate TypeError will be thrown.
In addition, 714 failed cases will be passed in
http://w3c-test.org/dom/ranges/Range-compareBoundaryPoints.html

TEST=LayoutTests/fast/dom/Range/compareBoundaryPoints-error.html

Behavior in other browsers.
*)FF: PASS
*)IE: FAIL

Review URL: https://codereview.chromium.org/405083003

git-svn-id: svn://svn.chromium.org/blink/trunk@178610 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent bf490f69
PASS r1.compareBoundaryPoints(Range.START_TO_START) threw exception TypeError: Failed to execute 'compareBoundaryPoints' on 'Range': 2 arguments required, but only 1 present..
PASS r1.compareBoundaryPoints(-1, r2) threw exception NotSupportedError: Failed to execute 'compareBoundaryPoints' on 'Range': The comparison method provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'END_TO_START'..
PASS r1.compareBoundaryPoints(4, r2) threw exception NotSupportedError: Failed to execute 'compareBoundaryPoints' on 'Range': The comparison method provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'END_TO_START'..
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<title>Document.adoptNode</title>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>
var r1 = document.createRange();
var r2 = document.createRange();
shouldThrow("r1.compareBoundaryPoints(Range.START_TO_START)", '"TypeError: Failed to execute \'compareBoundaryPoints\' on \'Range\': 2 arguments required, but only 1 present."');
shouldThrow("r1.compareBoundaryPoints(-1, r2)", '"NotSupportedError: Failed to execute \'compareBoundaryPoints\' on \'Range\': The comparison method provided must be one of \'START_TO_START\', \'START_TO_END\', \'END_TO_END\', or \'END_TO_START\'."');
shouldThrow("r1.compareBoundaryPoints(4, r2)", '"NotSupportedError: Failed to execute \'compareBoundaryPoints\' on \'Range\': The comparison method provided must be one of \'START_TO_START\', \'START_TO_END\', \'END_TO_END\', or \'END_TO_START\'."');
</script>
</body>
</html>
......@@ -321,10 +321,10 @@ Range::CompareResults Range::compareNode(Node* refNode, ExceptionState& exceptio
return NODE_INSIDE; // ends inside the range
}
short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, ExceptionState& exceptionState) const
short Range::compareBoundaryPoints(CompareHow how, const PassRefPtrWillBeRawPtr<Range> sourceRange, ExceptionState& exceptionState) const
{
if (!sourceRange) {
exceptionState.throwDOMException(NotFoundError, "The source range provided was null.");
if (!(how == START_TO_START || how == START_TO_END || how == END_TO_END || how == END_TO_START)) {
exceptionState.throwDOMException(NotSupportedError, "The comparison method provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'END_TO_START'.");
return 0;
}
......@@ -357,7 +357,7 @@ short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, Exc
return compareBoundaryPoints(m_start, sourceRange->m_end, exceptionState);
}
exceptionState.throwDOMException(SyntaxError, "The comparison method provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'END_TO_START'.");
ASSERT_NOT_REACHED();
return 0;
}
......
......@@ -72,7 +72,7 @@ public:
enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE };
CompareResults compareNode(Node* refNode, ExceptionState&) const;
enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionState&) const;
short compareBoundaryPoints(CompareHow, const PassRefPtrWillBeRawPtr<Range> sourceRange, ExceptionState&) const;
static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionState&);
static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionState&);
bool boundaryPointsValid() const;
......
......@@ -48,7 +48,7 @@
const unsigned short END_TO_END = 2;
const unsigned short END_TO_START = 3;
[RaisesException] short compareBoundaryPoints(CompareHow how, Range sourceRange);
[RaisesException, TypeChecking=Interface] short compareBoundaryPoints(CompareHow how, Range sourceRange);
[RaisesException, CustomElementCallbacks] void deleteContents();
[RaisesException, CustomElementCallbacks] DocumentFragment extractContents();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment