Exceptions logged to the JS console should use toString().
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Jul 2016 19:12:49 +0000 (19:12 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Jul 2016 19:12:49 +0000 (19:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159855

Reviewed by Darin Adler.

No new tests (No change in behavior).

* bindings/js/JSDOMBinding.cpp:
(WebCore::reportException):

* dom/DOMCoreException.h:
(WebCore::DOMCoreException::DOMCoreException):

* dom/ExceptionBase.cpp:
(WebCore::ExceptionBase::ExceptionBase):
(WebCore::ExceptionBase::toString):
(WebCore::ExceptionBase::consoleErrorMessage): Deleted.
* dom/ExceptionBase.h:
(WebCore::ExceptionBase::description): Deleted.

* svg/SVGException.h:

* xml/XPathException.h:
(WebCore::XPathException::XPathException):

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/dom/DOMCoreException.h
Source/WebCore/dom/ExceptionBase.cpp
Source/WebCore/dom/ExceptionBase.h
Source/WebCore/svg/SVGException.h
Source/WebCore/xml/XPathException.h

index edb6ab4..44e977c 100644 (file)
@@ -1,5 +1,32 @@
 2016-07-17  Brady Eidson  <beidson@apple.com>
 
+        Exceptions logged to the JS console should use toString().
+        https://bugs.webkit.org/show_bug.cgi?id=159855
+
+        Reviewed by Darin Adler.
+
+        No new tests (No change in behavior).
+
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::reportException):
+
+        * dom/DOMCoreException.h:
+        (WebCore::DOMCoreException::DOMCoreException):
+
+        * dom/ExceptionBase.cpp:
+        (WebCore::ExceptionBase::ExceptionBase):
+        (WebCore::ExceptionBase::toString):
+        (WebCore::ExceptionBase::consoleErrorMessage): Deleted.
+        * dom/ExceptionBase.h:
+        (WebCore::ExceptionBase::description): Deleted.
+
+        * svg/SVGException.h:
+
+        * xml/XPathException.h:
+        (WebCore::XPathException::XPathException):
+
+2016-07-17  Brady Eidson  <beidson@apple.com>
+
         Update DOMCoreException to use the description in toString().
         https://bugs.webkit.org/show_bug.cgi?id=159857
 
index 688e4ea..5e2af02 100644 (file)
@@ -200,7 +200,7 @@ void reportException(ExecState* exec, Exception* exception, CachedScript* cached
     String errorMessage;
     JSValue exceptionValue = exception->value();
     if (ExceptionBase* exceptionBase = toExceptionBase(exceptionValue))
-        errorMessage = exceptionBase->consoleErrorMessage();
+        errorMessage = exceptionBase->toString();
     else {
         // FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions
         // If this is a custom exception object, call toString on it to try and get a nice string representation for the exception.
index c0c6ca9..3429f3e 100644 (file)
@@ -44,7 +44,7 @@ public:
 
 protected:
     explicit DOMCoreException(const ExceptionCodeDescription& description)
-        : ExceptionBase(description, ExceptionBase::MessageSource::UseDescription)
+        : ExceptionBase(description)
     {
     }
 };
index c91d864..23ebca6 100644 (file)
 
 namespace WebCore {
 
-ExceptionBase::ExceptionBase(const ExceptionCodeDescription& description, MessageSource messageSource)
+ExceptionBase::ExceptionBase(const ExceptionCodeDescription& description)
     : m_code(description.code)
     , m_name(description.name)
-    , m_description(description.description)
+    , m_message(description.description)
     , m_typeName(description.typeName)
-    , m_messageSource(messageSource)
 {
-    if (messageSource == MessageSource::UseDescription) {
-        m_message = m_description;
-        return;
-    }
-
-    if (description.name)
-        m_message = m_name + ": " + description.typeName + " Exception " + String::number(description.code);
-    else
-        m_message = makeString(description.typeName, " Exception ", String::number(description.code));
-}
-
-String ExceptionBase::consoleErrorMessage() const
-{
-    if (m_messageSource == MessageSource::UseDescription)
-        return toString();
-
-    return makeString(m_message, ": ", m_description);
 }
 
 String ExceptionBase::toString() const
 {
-    if (m_messageSource != MessageSource::UseDescription)
-        return makeString("Error: ", m_message);
+    if (!m_toString.isEmpty())
+        return m_toString;
 
     String lastComponent;
-    if (!m_description.isEmpty())
-        lastComponent = makeString(": ", m_description);
+    if (!m_message.isEmpty())
+        lastComponent = makeString(": ", m_message);
 
     if (m_name.isEmpty())
-        return makeString(m_typeName, " Exception", m_code ? makeString(" ", String::number(m_code)) : "", lastComponent);
+        m_toString = makeString(m_typeName, " Exception", m_code ? makeString(" ", String::number(m_code)) : "", lastComponent);
+    else
+        m_toString = makeString(m_name, " (", m_typeName, " Exception", m_code ? makeString(" ", String::number(m_code)) : "", ")", lastComponent);
 
-    return makeString(m_name, " (", m_typeName, " Exception", m_code ? makeString(" ", String::number(m_code)) : "", ")", lastComponent);
+    return m_toString;
 }
 
 } // namespace WebCore
index 974e1a4..afdc937 100644 (file)
@@ -42,28 +42,18 @@ public:
     unsigned short code() const { return m_code; }
     String name() const { return m_name; }
     String message() const { return m_message; }
-    String description() const { return m_description; }
 
     String toString() const;
 
-    // FIXME: consoleErrorMessage is needed temporarily while bug 159822 is in progress.
-    // Once 159822 is complete, consoleErrorMessage can be dropped and its callers will use toString instead.
-    String consoleErrorMessage() const;
-
 protected:
-    enum class MessageSource {
-        ConstructMessage,
-        UseDescription,
-    };
-    explicit ExceptionBase(const ExceptionCodeDescription&, MessageSource = MessageSource::ConstructMessage);
+    explicit ExceptionBase(const ExceptionCodeDescription&);
 
 private:
     unsigned short m_code;
     String m_name;
     String m_message;
-    String m_description;
     String m_typeName;
-    MessageSource m_messageSource;
+    mutable String m_toString;
 };
 
 } // namespace WebCore
index b82e0e4..bbda606 100644 (file)
@@ -45,7 +45,7 @@ public:
 
 private:
     SVGException(const ExceptionCodeDescription& description)
-        : ExceptionBase(description, ExceptionBase::MessageSource::UseDescription)
+        : ExceptionBase(description)
     {
     }
 };
index 50fbb79..1cb3e74 100644 (file)
@@ -52,7 +52,7 @@ public:
 
 private:
     explicit XPathException(const ExceptionCodeDescription& description)
-        : ExceptionBase(description, ExceptionBase::MessageSource::UseDescription)
+        : ExceptionBase(description)
     {
     }
 };