Title: [189062] trunk
Revision
189062
Author
[email protected]
Date
2015-08-27 15:33:40 -0700 (Thu, 27 Aug 2015)

Log Message

Range.compareBoundaryPoints() should throw a NotSupportedError for invalid compareHow values
https://bugs.webkit.org/show_bug.cgi?id=148483

Reviewed by Geoffrey Garen.

Source/WebCore:

Range.compareBoundaryPoints() should throw a NotSupportedError for
invalid compareHow values:
https://dom.spec.whatwg.org/#dom-range-compareboundarypoints (step 1)

Firefox and Chrome conform to the specification already.

Previously, WebKit would not throw and simply cast the value to our
internal CompareHow enum type. This patch aligns WebKit's behavior with
the DOM specificaiton and other browsers.

W3C test suite:
http://w3c-test.org/dom/ranges/Range-compareBoundaryPoints.html

Test: fast/dom/Range/compareBoundaryPoints-compareHow-exception.html

* bindings/scripts/CodeGenerator.pm:
* bindings/scripts/CodeGeneratorGObject.pm:
* bindings/scripts/CodeGeneratorJS.pm:
* bindings/scripts/CodeGeneratorObjC.pm:
Drop CompareHow special casing from bindings generator as we now use
unsigned short instead in the IDL.

* dom/Range.cpp:
(WebCore::Range::compareBoundaryPointsForBindings):
* dom/Range.h:
* dom/Range.idl:
Use "unsigned short" type instead of WebCore's CompareHow for the
parameter, as per the specification. On implementation side, we
now validate the compareHow value before casting it to a CompareHow
enum type. If the value is not value, we throw and abort early.

LayoutTests:

Add new layout test to confirm that Range.compareBoundaryPoints() throws
when passed in invalid compareHow values.

* fast/dom/Range/compareBoundaryPoints-compareHow-exception-expected.txt: Added.
* fast/dom/Range/compareBoundaryPoints-compareHow-exception.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (189061 => 189062)


--- trunk/LayoutTests/ChangeLog	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/LayoutTests/ChangeLog	2015-08-27 22:33:40 UTC (rev 189062)
@@ -1,3 +1,16 @@
+2015-08-27  Chris Dumez  <[email protected]>
+
+        Range.compareBoundaryPoints() should throw a NotSupportedError for invalid compareHow values
+        https://bugs.webkit.org/show_bug.cgi?id=148483
+
+        Reviewed by Geoffrey Garen.
+
+        Add new layout test to confirm that Range.compareBoundaryPoints() throws
+        when passed in invalid compareHow values.
+
+        * fast/dom/Range/compareBoundaryPoints-compareHow-exception-expected.txt: Added.
+        * fast/dom/Range/compareBoundaryPoints-compareHow-exception.html: Added.
+
 2015-08-27  Joseph Pecoraro  <[email protected]>
 
         Page does not update when <link> media attribute changes to no longer apply to page

Added: trunk/LayoutTests/fast/dom/Range/compareBoundaryPoints-compareHow-exception-expected.txt (0 => 189062)


--- trunk/LayoutTests/fast/dom/Range/compareBoundaryPoints-compareHow-exception-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Range/compareBoundaryPoints-compareHow-exception-expected.txt	2015-08-27 22:33:40 UTC (rev 189062)
@@ -0,0 +1,18 @@
+Checks that Range.compareBoundaryPoints() throw if the compareHow parameter is invalid
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS range.compareBoundaryPoints(Range.START_TO_START, sourceRange) is -1
+PASS range.compareBoundaryPoints(Range.START_TO_END, sourceRange) is -1
+PASS range.compareBoundaryPoints(Range.END_TO_END, sourceRange) is -1
+PASS range.compareBoundaryPoints(Range.END_TO_START, sourceRange) is -1
+PASS range.compareBoundaryPoints(65536, sourceRange) is -1
+PASS range.compareBoundaryPoints(-1, sourceRange) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS range.compareBoundaryPoints(4, sourceRange) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS range.compareBoundaryPoints(100, sourceRange) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS range.compareBoundaryPoints(65535, sourceRange) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Range/compareBoundaryPoints-compareHow-exception.html (0 => 189062)


--- trunk/LayoutTests/fast/dom/Range/compareBoundaryPoints-compareHow-exception.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Range/compareBoundaryPoints-compareHow-exception.html	2015-08-27 22:33:40 UTC (rev 189062)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div></div>
+<div></div>
+<script src=""
+<script>
+description("Checks that Range.compareBoundaryPoints() throw if the compareHow parameter is invalid");
+
+var range = document.createRange();
+range.selectNode(document.getElementsByTagName("div")[0]);
+var sourceRange = document.createRange();
+sourceRange.selectNode(document.getElementsByTagName("div")[1]);
+
+// Valid values.
+shouldBe("range.compareBoundaryPoints(Range.START_TO_START, sourceRange)", "-1");
+shouldBe("range.compareBoundaryPoints(Range.START_TO_END, sourceRange)", "-1");
+shouldBe("range.compareBoundaryPoints(Range.END_TO_END, sourceRange)", "-1");
+shouldBe("range.compareBoundaryPoints(Range.END_TO_START, sourceRange)", "-1");
+shouldBe("range.compareBoundaryPoints(65536, sourceRange)", "-1"); // 65536 should wrap around to 0.
+
+// Invalid values.
+shouldThrow("range.compareBoundaryPoints(-1, sourceRange)", "'Error: NotSupportedError: DOM Exception 9'");
+shouldThrow("range.compareBoundaryPoints(4, sourceRange)", "'Error: NotSupportedError: DOM Exception 9'");
+shouldThrow("range.compareBoundaryPoints(100, sourceRange)", "'Error: NotSupportedError: DOM Exception 9'");
+shouldThrow("range.compareBoundaryPoints(65535, sourceRange)", "'Error: NotSupportedError: DOM Exception 9'");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (189061 => 189062)


--- trunk/Source/WebCore/ChangeLog	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/ChangeLog	2015-08-27 22:33:40 UTC (rev 189062)
@@ -1,3 +1,41 @@
+2015-08-27  Chris Dumez  <[email protected]>
+
+        Range.compareBoundaryPoints() should throw a NotSupportedError for invalid compareHow values
+        https://bugs.webkit.org/show_bug.cgi?id=148483
+
+        Reviewed by Geoffrey Garen.
+
+        Range.compareBoundaryPoints() should throw a NotSupportedError for
+        invalid compareHow values:
+        https://dom.spec.whatwg.org/#dom-range-compareboundarypoints (step 1)
+
+        Firefox and Chrome conform to the specification already.
+
+        Previously, WebKit would not throw and simply cast the value to our
+        internal CompareHow enum type. This patch aligns WebKit's behavior with
+        the DOM specificaiton and other browsers.
+
+        W3C test suite:
+        http://w3c-test.org/dom/ranges/Range-compareBoundaryPoints.html
+
+        Test: fast/dom/Range/compareBoundaryPoints-compareHow-exception.html
+
+        * bindings/scripts/CodeGenerator.pm:
+        * bindings/scripts/CodeGeneratorGObject.pm:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        * bindings/scripts/CodeGeneratorObjC.pm:
+        Drop CompareHow special casing from bindings generator as we now use
+        unsigned short instead in the IDL.
+
+        * dom/Range.cpp:
+        (WebCore::Range::compareBoundaryPointsForBindings):
+        * dom/Range.h:
+        * dom/Range.idl:
+        Use "unsigned short" type instead of WebCore's CompareHow for the
+        parameter, as per the specification. On implementation side, we
+        now validate the compareHow value before casting it to a CompareHow
+        enum type. If the value is not value, we throw and abort early.
+
 2015-08-27  Joseph Pecoraro  <[email protected]>
 
         Page does not update when <link> media attribute changes to no longer apply to page

Modified: trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm (189061 => 189062)


--- trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm	2015-08-27 22:33:40 UTC (rev 189062)
@@ -57,14 +57,13 @@
 
 # WebCore types used directly in IDL files.
 my %webCoreTypeHash = (
-    "CompareHow" => 1,
     "SerializedScriptValue" => 1,
     "Dictionary" => 1
 );
 
 my %enumTypeHash = ();
 
-my %nonPointerTypeHash = ("DOMTimeStamp" => 1, "CompareHow" => 1);
+my %nonPointerTypeHash = ("DOMTimeStamp" => 1);
 
 my %svgAttributesInHTMLHash = ("class" => 1, "id" => 1, "onabort" => 1, "onclick" => 1,
                                "onerror" => 1, "onload" => 1, "onmousedown" => 1,

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm (189061 => 189062)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2015-08-27 22:33:40 UTC (rev 189062)
@@ -411,7 +411,6 @@
 
     my %types = ("DOMString", "gchar*",
                  "DOMTimeStamp", "guint32",
-                 "CompareHow", "gushort",
                  "SerializedScriptValue", "gchar*",
                  "float", "gfloat",
                  "unrestricted float", "gfloat",
@@ -1066,7 +1065,7 @@
                 $implIncludes{"WebKitDOM${paramIDLType}Private.h"} = 1;
             }
         }
-        if ($paramIsGDOMType || ($paramIDLType eq "DOMString") || ($paramIDLType eq "CompareHow")) {
+        if ($paramIsGDOMType || ($paramIDLType eq "DOMString")) {
             $paramName = "converted" . $codeGenerator->WK_ucfirst($paramName);
         }
         if ($paramIDLType eq "NodeFilter" || $paramIDLType eq "XPathNSResolver") {
@@ -1188,8 +1187,6 @@
         $convertedParamName = "converted" . $codeGenerator->WK_ucfirst($paramName);
         if ($paramIDLType eq "DOMString") {
             push(@cBody, "    WTF::String ${convertedParamName} = WTF::String::fromUTF8($paramName);\n");
-        } elsif ($paramIDLType eq "CompareHow") {
-            push(@cBody, "    WebCore::Range::CompareHow ${convertedParamName} = static_cast<WebCore::Range::CompareHow>($paramName);\n");
         } elsif ($paramIDLType eq "NodeFilter" || $paramIDLType eq "XPathNSResolver") {
             push(@cBody, "    RefPtr<WebCore::$paramIDLType> ${convertedParamName} = WebKit::core($paramName);\n");
         } elsif ($paramIsGDOMType) {

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (189061 => 189062)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-08-27 22:33:40 UTC (rev 189062)
@@ -3740,7 +3740,6 @@
 }
 
 my %nativeType = (
-    "CompareHow" => "Range::CompareHow",
     "DOMString" => "String",
     "NodeFilter" => "RefPtr<NodeFilter>",
     "SerializedScriptValue" => "RefPtr<SerializedScriptValue>",
@@ -3880,7 +3879,6 @@
     return "toUInt64(exec, $value, $intConversion)" if $type eq "unsigned long long";
 
     return "valueToDate(exec, $value)" if $type eq "Date";
-    return "static_cast<Range::CompareHow>($value.toInt32(exec))" if $type eq "CompareHow";
 
     if ($type eq "DOMString") {
         # FIXME: This implements [TreatNullAs=NullString] and [TreatUndefinedAs=NullString],

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm (189061 => 189062)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm	2015-08-27 22:33:40 UTC (rev 189062)
@@ -577,7 +577,6 @@
     return "float" if $type eq "unrestricted float";
     return "id <$name>" if IsProtocolType($type);
     return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
-    return "unsigned short" if $type eq "CompareHow";
     return $name if IsCoreFoundationType($name);
     return "$name *";
 }
@@ -594,7 +593,7 @@
     # FIXME: <rdar://problem/5049934> Consider using 'nonatomic' on the DOM @property declarations.
     if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
         push(@attributes, "copy");
-    } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow") {
+    } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp") {
         push(@attributes, "strong");
     }
 
@@ -616,7 +615,6 @@
 
     return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
     return $argName . "Node" if $type eq "EventTarget";
-    return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
     return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
     return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
     return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver";

Modified: trunk/Source/WebCore/dom/Range.cpp (189061 => 189062)


--- trunk/Source/WebCore/dom/Range.cpp	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/dom/Range.cpp	2015-08-27 22:33:40 UTC (rev 189062)
@@ -462,6 +462,15 @@
     return 0;
 }
 
+short Range::compareBoundaryPointsForBindings(unsigned short compareHow, const Range* sourceRange, ExceptionCode& ec) const
+{
+    if (compareHow > END_TO_START) {
+        ec = NOT_SUPPORTED_ERR;
+        return 0;
+    }
+    return compareBoundaryPoints(static_cast<CompareHow>(compareHow), sourceRange, ec);
+}
+
 short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode& ec)
 {
     ASSERT(containerA);

Modified: trunk/Source/WebCore/dom/Range.h (189061 => 189062)


--- trunk/Source/WebCore/dom/Range.h	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/dom/Range.h	2015-08-27 22:33:40 UTC (rev 189062)
@@ -80,6 +80,7 @@
     CompareResults compareNode(Node* refNode, ExceptionCode&) const;
     enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
     WEBCORE_EXPORT short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionCode&) const;
+    short compareBoundaryPointsForBindings(unsigned short compareHow, const Range* sourceRange, ExceptionCode&) const;
     static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode&);
     static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionCode&);
     WEBCORE_EXPORT bool boundaryPointsValid() const;

Modified: trunk/Source/WebCore/dom/Range.idl (189061 => 189062)


--- trunk/Source/WebCore/dom/Range.idl	2015-08-27 22:31:04 UTC (rev 189061)
+++ trunk/Source/WebCore/dom/Range.idl	2015-08-27 22:33:40 UTC (rev 189062)
@@ -50,7 +50,7 @@
     const unsigned short END_TO_END     = 2;
     const unsigned short END_TO_START   = 3;
 
-    [ObjCLegacyUnnamedParameters, RaisesException] short compareBoundaryPoints([Default=Undefined] optional CompareHow how,
+    [ObjCLegacyUnnamedParameters, RaisesException, ImplementedAs=compareBoundaryPointsForBindings] short compareBoundaryPoints([Default=Undefined] optional unsigned short how,
                                                [Default=Undefined] optional Range sourceRange);
 
     [RaisesException] void deleteContents();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to