[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

darin at apple.com darin at apple.com
Thu Apr 8 01:10:58 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit d352c228357426ed52fc3d95a74c6d57a5ed2d11
Author: darin at apple.com <darin at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Jan 16 21:36:40 2010 +0000

    ValidityState can hold a stale pointer to control
    https://bugs.webkit.org/show_bug.cgi?id=33729
    rdar://problem/7545114
    
    Reviewed by Oliver Hunt and Alexey Proskuryakov.
    
    WebCore:
    
    Test: fast/forms/ValidityState-removed-control.html
    
    * html/HTMLFormControlElement.h: Use OwnPtr instead of
    RefPtr to point to the ValidityState object.
    
    * html/ValidityState.cpp: Use a constant instead of a
    macro for the email validation regular expression.
    (WebCore::ValidityState::validationMessage): Use
    m_control instead of control function; we don't need
    a function for this. Also marked const.
    (WebCore::ValidityState::typeMismatch): Ditto.
    Fixed some minor style problems.
    (WebCore::ValidityState::rangeUnderflow): Ditto.
    (WebCore::ValidityState::rangeOverflow): Ditto.
    (WebCore::ValidityState::stepMismatch): Ditto.
    (WebCore::ValidityState::valid): Ditto.
    (WebCore::ValidityState::isValidEmailAddress):
    Changed local variable names for clarity. Got rid of
    an unneeded global variable.
    
    * html/ValidityState.h: Removed RefCounted as a base
    class, deriving from Noncopyable instead. Changed
    creation to use PassOwnPtr instead of PassRefPtr.
    Eliminated unneeded control function. Added ref and
    deref functions that forward the reference counting
    to the control. Moved constructor here and made it
    inline.
    
    LayoutTests:
    
    * fast/forms/ValidityState-removed-control-expected.txt: Added.
    * fast/forms/ValidityState-removed-control.html: Added.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53364 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 42c7186..df7a333 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2010-01-16  Darin Adler  <darin at apple.com>
+
+        Reviewed by Oliver Hunt and Alexey Proskuryakov.
+
+        ValidityState can hold a stale pointer to control
+        https://bugs.webkit.org/show_bug.cgi?id=33729
+        rdar://problem/7545114
+
+        * fast/forms/ValidityState-removed-control-expected.txt: Added.
+        * fast/forms/ValidityState-removed-control.html: Added.
+
 2010-01-15  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Darin Adler.
diff --git a/LayoutTests/fast/forms/ValidityState-removed-control-expected.txt b/LayoutTests/fast/forms/ValidityState-removed-control-expected.txt
new file mode 100644
index 0000000..6a763a1
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-removed-control-expected.txt
@@ -0,0 +1,3 @@
+Tests the behavior of removing a control and then accessing its validity state afterward.
+
+Test has run: If no assertion or crash occurred, it passed.
diff --git a/LayoutTests/fast/forms/ValidityState-removed-control.html b/LayoutTests/fast/forms/ValidityState-removed-control.html
new file mode 100644
index 0000000..d517e5f
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-removed-control.html
@@ -0,0 +1,38 @@
+<head>
+
+<script>
+
+function gc()
+{
+    if (window.GCController)
+        return GCController.collect();
+
+    for (var i = 0; i < 10000; i++) { // > force garbage collection (FF requires about 9K allocations before a collect)
+        var s = new String("");
+    }
+}
+
+function runTest()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+    var validity = document.getElementById("control").validity;
+    document.body.removeChild(document.getElementById("control"));
+    gc();
+    validity.valueMissing;
+    document.getElementById("result").firstChild.data = "Test has run: If no assertion or crash occurred, it passed.";
+}
+
+</script>
+
+</head>
+
+<body onload="runTest()">
+
+<p>Tests the behavior of removing a control and then accessing its validity state afterward.</p>
+
+<select id="control"></select>
+
+<p id="result">TEST DID NOT RUN YET</p>
+
+</body>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 55a94c9..e29fcc2 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,39 @@
+2010-01-16  Darin Adler  <darin at apple.com>
+
+        Reviewed by Oliver Hunt and Alexey Proskuryakov.
+
+        ValidityState can hold a stale pointer to control
+        https://bugs.webkit.org/show_bug.cgi?id=33729
+        rdar://problem/7545114
+
+        Test: fast/forms/ValidityState-removed-control.html
+
+        * html/HTMLFormControlElement.h: Use OwnPtr instead of
+        RefPtr to point to the ValidityState object.
+
+        * html/ValidityState.cpp: Use a constant instead of a
+        macro for the email validation regular expression.
+        (WebCore::ValidityState::validationMessage): Use
+        m_control instead of control function; we don't need
+        a function for this. Also marked const.
+        (WebCore::ValidityState::typeMismatch): Ditto.
+        Fixed some minor style problems.
+        (WebCore::ValidityState::rangeUnderflow): Ditto.
+        (WebCore::ValidityState::rangeOverflow): Ditto.
+        (WebCore::ValidityState::stepMismatch): Ditto.
+        (WebCore::ValidityState::valid): Ditto.
+        (WebCore::ValidityState::isValidEmailAddress):
+        Changed local variable names for clarity. Got rid of
+        an unneeded global variable.
+
+        * html/ValidityState.h: Removed RefCounted as a base
+        class, deriving from Noncopyable instead. Changed
+        creation to use PassOwnPtr instead of PassRefPtr.
+        Eliminated unneeded control function. Added ref and
+        deref functions that forward the reference counting
+        to the control. Moved constructor here and made it
+        inline.
+
 2010-01-15  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/html/HTMLFormControlElement.h b/WebCore/html/HTMLFormControlElement.h
index 7105112..01a7684 100644
--- a/WebCore/html/HTMLFormControlElement.h
+++ b/WebCore/html/HTMLFormControlElement.h
@@ -129,7 +129,7 @@ private:
     virtual bool isValidFormControlElement();
 
     HTMLFormElement* m_form;
-    RefPtr<ValidityState> m_validityState;
+    OwnPtr<ValidityState> m_validityState;
     bool m_disabled : 1;
     bool m_readOnly : 1;
     bool m_required : 1;
diff --git a/WebCore/html/ValidityState.cpp b/WebCore/html/ValidityState.cpp
index e7df225..e154cb3 100644
--- a/WebCore/html/ValidityState.cpp
+++ b/WebCore/html/ValidityState.cpp
@@ -2,6 +2,7 @@
  * This file is part of the WebKit project.
  *
  * Copyright (C) 2009 Michelangelo De Simone <micdesim at gmail.com>
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -30,23 +31,18 @@
 #include "RegularExpression.h"
 #include <wtf/StdLibExtras.h>
 
-#define EMAIL_LOCALPART "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+"
-#define EMAIL_DOMAINPART "[a-z0-9-]+(\\.[a-z0-9-]+)+"
-#define EMAIL_PATTERN EMAIL_LOCALPART "@" EMAIL_DOMAINPART
-
 namespace WebCore {
 
 using namespace HTMLNames;
 
-ValidityState::ValidityState(HTMLFormControlElement* parent)
-    : m_control(parent)
-{
-    ASSERT(parent);
-}
+static const char emailPattern[] =
+    "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part
+    "@"
+    "[a-z0-9-]+(\\.[a-z0-9-]+)+"; // domain part
 
-String ValidityState::validationMessage()
+String ValidityState::validationMessage() const
 {
-    if (!control()->willValidate())
+    if (!m_control->willValidate())
         return String();
 
     if (customError())
@@ -69,12 +65,12 @@ String ValidityState::validationMessage()
     return String();
 }
 
-bool ValidityState::typeMismatch()
+bool ValidityState::typeMismatch() const
 {
-    if (!control()->hasTagName(inputTag))
+    if (!m_control->hasTagName(inputTag))
         return false;
 
-    HTMLInputElement* input = static_cast<HTMLInputElement*>(control());
+    HTMLInputElement* input = static_cast<HTMLInputElement*>(m_control);
     String value = input->value();
 
     if (value.isEmpty())
@@ -87,17 +83,15 @@ bool ValidityState::typeMismatch()
         return !HTMLInputElement::formStringToDouble(value, 0);
     case HTMLInputElement::URL:
         return !KURL(KURL(), value).isValid();
-    case HTMLInputElement::EMAIL:
-    {
+    case HTMLInputElement::EMAIL: {
         if (!input->multiple())
             return !isValidEmailAddress(value);
-            
-        Vector<String> email_list;
-        value.split(',', email_list);
-        for (unsigned i = 0; i < email_list.size(); ++i)
-            if (!isValidEmailAddress(email_list[i]))
+        Vector<String> addresses;
+        value.split(',', addresses);
+        for (unsigned i = 0; i < addresses.size(); ++i) {
+            if (!isValidEmailAddress(addresses[i]))
                 return true;
-
+        }
         return false;
     }
     case HTMLInputElement::DATE:
@@ -107,37 +101,52 @@ bool ValidityState::typeMismatch()
     case HTMLInputElement::TIME:
     case HTMLInputElement::WEEK:
         return !HTMLInputElement::formStringToISODateTime(input->inputType(), value, 0);
-    default:
+    case HTMLInputElement::BUTTON:
+    case HTMLInputElement::CHECKBOX:
+    case HTMLInputElement::FILE:
+    case HTMLInputElement::HIDDEN:
+    case HTMLInputElement::IMAGE:
+    case HTMLInputElement::ISINDEX:
+    case HTMLInputElement::PASSWORD:
+    case HTMLInputElement::RADIO:
+    case HTMLInputElement::RANGE:
+    case HTMLInputElement::RESET:
+    case HTMLInputElement::SEARCH:
+    case HTMLInputElement::SUBMIT:
+    case HTMLInputElement::TELEPHONE: // FIXME: Is there validation for <input type=telephone>?
+    case HTMLInputElement::TEXT:
         return false;
     }
+
+    ASSERT_NOT_REACHED();
+    return false;
 }
 
-bool ValidityState::rangeUnderflow()
+bool ValidityState::rangeUnderflow() const
 {
-    if (!control()->hasTagName(inputTag))
+    if (!m_control->hasTagName(inputTag))
         return false;
-    return static_cast<HTMLInputElement*>(control())->rangeUnderflow();
+    return static_cast<HTMLInputElement*>(m_control)->rangeUnderflow();
 }
 
-bool ValidityState::rangeOverflow()
+bool ValidityState::rangeOverflow() const
 {
-    if (!control()->hasTagName(inputTag))
+    if (!m_control->hasTagName(inputTag))
         return false;
-    return static_cast<HTMLInputElement*>(control())->rangeOverflow();
+    return static_cast<HTMLInputElement*>(m_control)->rangeOverflow();
 }
 
-bool ValidityState::stepMismatch()
+bool ValidityState::stepMismatch() const
 {
-    if (!control()->hasTagName(inputTag))
+    if (!m_control->hasTagName(inputTag))
         return false;
-    return static_cast<HTMLInputElement*>(control())->stepMismatch();
+    return static_cast<HTMLInputElement*>(m_control)->stepMismatch();
 }
 
-bool ValidityState::valid()
+bool ValidityState::valid() const
 {
-    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
-                       tooLong() || patternMismatch() || valueMissing() || customError();
-
+    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow()
+        || tooLong() || patternMismatch() || valueMissing() || customError();
     return !someError;
 }
 
@@ -154,19 +163,18 @@ bool ValidityState::isValidColorString(const String& value)
     return color.isValid() && !color.hasAlpha();
 }
 
-bool ValidityState::isValidEmailAddress(const String& email)
+bool ValidityState::isValidEmailAddress(const String& address)
 {
-    if (email.isEmpty())
+    int addressLength = address.length();
+    if (!addressLength)
         return false;
 
-    DEFINE_STATIC_LOCAL(AtomicString, emailPattern, (EMAIL_PATTERN));
-    DEFINE_STATIC_LOCAL(RegularExpression, regExp, (emailPattern, TextCaseInsensitive));
+    DEFINE_STATIC_LOCAL(const RegularExpression, regExp, (emailPattern, TextCaseInsensitive));
 
-    int matchLength = 0;
-    int emailLength = email.length();
-    int matchOffset = regExp.match(email, 0, &matchLength);
+    int matchLength;
+    int matchOffset = regExp.match(address, 0, &matchLength);
 
-    return matchOffset == 0 && matchLength == emailLength;
+    return matchOffset == 0 && matchLength == addressLength;
 }
 
 } // namespace
diff --git a/WebCore/html/ValidityState.h b/WebCore/html/ValidityState.h
index 7ae95d7..78238f1 100644
--- a/WebCore/html/ValidityState.h
+++ b/WebCore/html/ValidityState.h
@@ -2,6 +2,7 @@
  * This file is part of the WebKit project.
  *
  * Copyright (C) 2009 Michelangelo De Simone <micdesim at gmail.com>
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -24,41 +25,43 @@
 #define ValidityState_h
 
 #include "HTMLFormControlElement.h"
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
-    class ValidityState : public RefCounted<ValidityState> {
-    public:
-        static PassRefPtr<ValidityState> create(HTMLFormControlElement* owner)
-        {
-            return adoptRef(new ValidityState(owner));
-        }
+class ValidityState : public Noncopyable {
+public:
+    static PassOwnPtr<ValidityState> create(HTMLFormControlElement* control)
+    {
+        return new ValidityState(control);
+    }
 
-        HTMLFormControlElement* control() const { return m_control; }
+    void ref() { m_control->ref(); }
+    void deref() { m_control->deref(); }
 
-        String validationMessage();
-        void setCustomErrorMessage(const String& message) { m_customErrorMessage = message; }
+    String validationMessage() const;
 
-        bool valueMissing() { return control()->valueMissing(); }
-        bool typeMismatch();
-        bool patternMismatch() { return control()->patternMismatch(); }
-        bool tooLong() { return control()->tooLong(); }
-        bool rangeUnderflow();
-        bool rangeOverflow();
-        bool stepMismatch();
-        bool customError() { return !m_customErrorMessage.isEmpty(); }
-        bool valid();
+    void setCustomErrorMessage(const String& message) { m_customErrorMessage = message; }
 
-    private:
-        ValidityState(HTMLFormControlElement*);
-        HTMLFormControlElement* m_control;
-        String m_customErrorMessage;
+    bool valueMissing() const { return m_control->valueMissing(); }
+    bool typeMismatch() const;
+    bool patternMismatch() const { return m_control->patternMismatch(); }
+    bool tooLong() const { return m_control->tooLong(); }
+    bool rangeUnderflow() const;
+    bool rangeOverflow() const;
+    bool stepMismatch() const;
+    bool customError() const { return !m_customErrorMessage.isEmpty(); }
+    bool valid() const;
 
-        static bool isValidColorString(const String&);
-        bool isValidEmailAddress(const String&);
-    };
+private:
+    ValidityState(HTMLFormControlElement* control) : m_control(control) { }
+
+    static bool isValidColorString(const String&);
+    static bool isValidEmailAddress(const String&);
+
+    HTMLFormControlElement* m_control;
+    String m_customErrorMessage;
+};
 
 } // namespace WebCore
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list