WebCore:
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Jan 2009 17:24:04 +0000 (17:24 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Jan 2009 17:24:04 +0000 (17:24 +0000)
2009-01-27  Mads Ager  <ager@chromium.org>

        Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=23300
        Follow Firefox in throwing exceptions when using selection
        functions on HTMLInputElements that cannot have selection.

        This requires custom setSelectionRange, setSelectionStart and
        setSelectionEnd implementations, but it gets rid of the custom
        getOwnPropertySlot.

        * bindings/js/JSHTMLInputElementCustom.cpp:
        (WebCore::JSHTMLInputElement::selectionStart):
        (WebCore::JSHTMLInputElement::selectionEnd):
        (WebCore::JSHTMLInputElement::setSelectionRange):
        * html/HTMLInputElement.idl:

LayoutTests:

2009-01-27  Mads Ager  <ager@chromium.org>

        Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=23300
        Update test of selection functions on HTMLInputElements to expect
        the selection functions to throw exceptions when used on buttons.
        This is consistent with the Firefox behavior.

        * fast/forms/selection-functions-expected.txt:
        * fast/forms/selection-functions.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@40293 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/selection-functions-expected.txt
LayoutTests/fast/forms/selection-functions.html
WebCore/ChangeLog
WebCore/bindings/js/JSHTMLInputElementCustom.cpp
WebCore/html/HTMLInputElement.idl

index ab79a817d531fc4f393061753f98b0b5f2c79def..f4cce266d061347af00ad7468771d6d559167892 100644 (file)
@@ -1,3 +1,15 @@
+2009-01-27  Mads Ager  <ager@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        https://bugs.webkit.org/show_bug.cgi?id=23300
+        Update test of selection functions on HTMLInputElements to expect
+        the selection functions to throw exceptions when used on buttons.
+        This is consistent with the Firefox behavior.
+
+        * fast/forms/selection-functions-expected.txt:
+        * fast/forms/selection-functions.html:
+
 2009-01-26  David Kilzer  <ddkilzer@apple.com>
 
         Fix misspelling of "lowercase" in font-face-locally-installed.html
index 3531c9e8b590f330426fe71ee57f96003c85620f..2a84d1898d9ba952428be4c44de8fb224e58c2f6 100644 (file)
@@ -45,4 +45,10 @@ selectionEnd:
 0, 48
 7, 7
 
-
+===button===
+button.selectionStart threw exception
+button.selectionStart = 0 threw exception
+button.selectionEnd threw exception
+button.selectionEnd = 0 threw exception
+button.setSelectionRange defined
+button.setSelectionRange(0,0) threw exception
index 6b6b4e02ed0048476289f12f821d066e762097b7..68c8e7a3d85dcd4b8816577a8d1c9068c36db0cd 100644 (file)
                 testElt(elt);
 
                 print("");
+                print("===button===");
 
-                // Make sure selectionStart, selectionEnd and setSelectionRange are undefined on the button
+                // Make sure that accessing selectionStart and selectionEnd on
+                // the button throws exceptions.
                 elt = document.getElementById("button");
-                if (elt.selectionStart != undefined) {
-                    print("Button.selectionStart defined");
-                }
-                if (elt.selectionEnd != undefined) {
-                    print("Button.selectionStart defined");
-                }
+                testButtonSelectionAccess(elt, ".selectionStart");
+                testButtonSelectionAccess(elt, ".selectionStart = 0");
+                testButtonSelectionAccess(elt, ".selectionEnd");
+                testButtonSelectionAccess(elt, ".selectionEnd = 0");
+                // Make sure that setSelectionRange is defined on the button element,
+                // but throws an exception if called.
                 if (elt.setSelectionRange != undefined) {
-                    print("Button.setSelectionRange defined");
+                    print("button.setSelectionRange defined");
+                    testButtonSelectionAccess(elt, ".setSelectionRange(0,0)");
                 }
             }
             function testElt(elt)
                 
                 elt.value = "";
             }
+            function testButtonSelectionAccess(button, access)
+            {
+                var source = "button" + access;
+                try {
+                    eval(source);
+                    print(source + " did not throw exception");
+                } catch(e) {
+                    print(source + " threw exception");
+                }
+            }
             function display(elt)
             {
                 var actStart = elt.selectionStart;
index 317f73ed04b8a373fd12396d8436831cbe412bb5..8923373f58f08de6e41a4b73e7680f00e5de4a08 100644 (file)
@@ -1,3 +1,21 @@
+2009-01-27  Mads Ager  <ager@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        https://bugs.webkit.org/show_bug.cgi?id=23300
+        Follow Firefox in throwing exceptions when using selection
+        functions on HTMLInputElements that cannot have selection.
+
+        This requires custom setSelectionRange, setSelectionStart and
+        setSelectionEnd implementations, but it gets rid of the custom
+        getOwnPropertySlot.
+
+        * bindings/js/JSHTMLInputElementCustom.cpp:
+        (WebCore::JSHTMLInputElement::selectionStart):
+        (WebCore::JSHTMLInputElement::selectionEnd):
+        (WebCore::JSHTMLInputElement::setSelectionRange):
+        * html/HTMLInputElement.idl:
+
 2009-01-27  Evan Stade  <estade@chromium.org>
 
         Reviewed by Nikolas Zimmermann.
index d59ef92a0104f997677039748267f0d5f116edd7..d43587053bc4ea1d02127679a0d5443f4b158091 100644 (file)
@@ -32,41 +32,53 @@ using namespace JSC;
 
 namespace WebCore {
 
-bool JSHTMLInputElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+JSValuePtr JSHTMLInputElement::selectionStart(ExecState* exec) const
 {
     HTMLInputElement* input = static_cast<HTMLInputElement*>(impl());
-    if (input->canHaveSelection())
-        return false;
-
-    const HashEntry* entry = JSHTMLInputElementPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
-    if (entry) {
-        if (entry->attributes() & Function) {
-            if (entry->function() == jsHTMLInputElementPrototypeFunctionSetSelectionRange) {
-                slot.setUndefined();
-                return true;
-            }
-        }
-    }
+    if (!input->canHaveSelection())
+        return throwError(exec, TypeError);
 
-    return false;
+    return jsNumber(exec, input->selectionStart());
 }
 
-JSValuePtr JSHTMLInputElement::selectionStart(ExecState* exec) const
+void JSHTMLInputElement::setSelectionStart(ExecState* exec, JSValuePtr value)
 {
     HTMLInputElement* input = static_cast<HTMLInputElement*>(impl());
     if (!input->canHaveSelection())
-        return jsUndefined();
+        throwError(exec, TypeError);
 
-    return jsNumber(exec, input->selectionStart());
+    input->setSelectionStart(value->toInt32(exec));
 }
 
 JSValuePtr JSHTMLInputElement::selectionEnd(ExecState* exec) const
 {
     HTMLInputElement* input = static_cast<HTMLInputElement*>(impl());
     if (!input->canHaveSelection())
-        return jsUndefined();
+        return throwError(exec, TypeError);
 
     return jsNumber(exec, input->selectionEnd());
 }
 
+void JSHTMLInputElement::setSelectionEnd(ExecState* exec, JSValuePtr value)
+{
+    HTMLInputElement* input = static_cast<HTMLInputElement*>(impl());
+    if (!input->canHaveSelection())
+        throwError(exec, TypeError);
+
+    input->setSelectionEnd(value->toInt32(exec));
+}
+
+JSValuePtr JSHTMLInputElement::setSelectionRange(ExecState* exec, const ArgList& args)
+{
+    HTMLInputElement* input = static_cast<HTMLInputElement*>(impl());
+    if (!input->canHaveSelection())
+        return throwError(exec, TypeError);
+
+    int start = args.at(exec, 0)->toInt32(exec);
+    int end = args.at(exec, 1)->toInt32(exec);
+
+    input->setSelectionRange(start, end);
+    return jsUndefined();
+}
+
 } // namespace WebCore
index a9b6d2cb44c290ff021cdf999f3b82f158d50534..dce1319390719cb92d3b5385afe0dbde9814666c 100644 (file)
@@ -21,7 +21,6 @@
 module html {
 
     interface [
-        CustomGetOwnPropertySlot,
         GenerateConstructor,
         InterfaceUUID=8f388ea3-1c31-4cca-8edd-449d14e222e1,
         ImplementationUUID=aeb56b87-a90e-4d9d-a4d5-7eec3687c338
@@ -58,9 +57,9 @@ module html {
 
         // WinIE & FireFox extension:
 
-                 attribute [CustomGetter] long selectionStart;
-                 attribute [CustomGetter] long selectionEnd;
-        void               setSelectionRange(in long start, in long end);
+                 attribute [Custom] long selectionStart;
+                 attribute [Custom] long selectionEnd;
+        [Custom] void setSelectionRange(in long start, in long end);
 
 #if defined(LANGUAGE_OBJECTIVE_C)
         // Objective-C extension: