Fixes a bug where error bubbles in JavaScript resources would
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Aug 2008 16:53:30 +0000 (16:53 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Aug 2008 16:53:30 +0000 (16:53 +0000)
        be clobbered by the syntax highlighter.

        https://bugs.webkit.org/show_bug.cgi?id=20345

        Reviewed by Adam Roben.

        * manual-tests/inspector/resources/script-error.js: Added.
        * manual-tests/inspector/styled-error-bubbles-in-scripts.html: Added.
        * page/inspector/SourceFrame.js:
        (WebInspector.SourceFrame.prototype._addMessageToSource):
        Check the nodeType and not the nodeName, this is less fragile.
        (WebInspector.SourceFrame.prototype._syntaxHighlightJavascriptLine):
        Check if the lastChild is an error bubble, if so remove it before
        getting the line's textContent. Add the error bubble back at the end.

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

WebCore/ChangeLog
WebCore/manual-tests/inspector/resources/script-error.js [new file with mode: 0644]
WebCore/manual-tests/inspector/styled-error-bubbles-in-scripts.html [new file with mode: 0644]
WebCore/page/inspector/SourceFrame.js

index e4b59a6..d6e2075 100644 (file)
@@ -1 +1,19 @@
+2008-08-11  Timothy Hatcher  <timothy@apple.com>
+
+        Fixes a bug where error bubbles in JavaScript resources would
+        be clobbered by the syntax highlighter.
+
+        https://bugs.webkit.org/show_bug.cgi?id=20345
+
+        Reviewed by Adam Roben.
+
+        * manual-tests/inspector/resources/script-error.js: Added.
+        * manual-tests/inspector/styled-error-bubbles-in-scripts.html: Added.
+        * page/inspector/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype._addMessageToSource):
+        Check the nodeType and not the nodeName, this is less fragile.
+        (WebInspector.SourceFrame.prototype._syntaxHighlightJavascriptLine):
+        Check if the lastChild is an error bubble, if so remove it before
+        getting the line's textContent. Add the error bubble back at the end.
+
 == Rolled over to ChangeLog-2008-08-10 ==
diff --git a/WebCore/manual-tests/inspector/resources/script-error.js b/WebCore/manual-tests/inspector/resources/script-error.js
new file mode 100644 (file)
index 0000000..c8be5ea
--- /dev/null
@@ -0,0 +1,6 @@
+var test = document.body;
+this.will.be.an.error = 1;
+
+function test() {
+    return 42;
+}
diff --git a/WebCore/manual-tests/inspector/styled-error-bubbles-in-scripts.html b/WebCore/manual-tests/inspector/styled-error-bubbles-in-scripts.html
new file mode 100644 (file)
index 0000000..0049cef
--- /dev/null
@@ -0,0 +1,6 @@
+<script src="resources/script-error.js"></script>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=20345">Bug 19065:
+Error bubbles are clobbered when syntax highlighting JavaScript resources</a>.</p>
+<p>To test, open the Inspector. There should be a red bubble with the number "1"
+in it next to the the only script resource in the Resources panel. Clicking the
+resource should show syntax highlighted JavaScript with a red error bubble.</p>
index 3282029..e81a40f 100644 (file)
@@ -333,7 +333,7 @@ WebInspector.SourceFrame.prototype = {
             return;
 
         var errorDiv = cell.lastChild;
-        if (!errorDiv || errorDiv.nodeName.toLowerCase() !== "div" || !errorDiv.hasStyleClass("webkit-html-message-bubble")) {
+        if (!errorDiv || errorDiv.nodeType !== Node.ELEMENT_NODE || !errorDiv.hasStyleClass("webkit-html-message-bubble")) {
             errorDiv = this.element.contentDocument.createElement("div");
             errorDiv.className = "webkit-html-message-bubble";
             cell.appendChild(errorDiv);
@@ -472,8 +472,16 @@ WebInspector.SourceFrame.prototype = {
     _syntaxHighlightJavascriptLine: function(line, prevLine)
     {
         var previousMatchLength = 0;
+
+        var messageBubble = line.lastChild;
+        if (messageBubble && messageBubble.nodeType === Node.ELEMENT_NODE && messageBubble.hasStyleClass("webkit-html-message-bubble"))
+            line.removeChild(messageBubble);
+        else
+            messageBubble = null;
+
         var code = line.textContent;
-        while (line.hasChildNodes())
+
+        while (line.firstChild)
             line.removeChild(line.firstChild);
 
         function createSpan(content, className)
@@ -593,6 +601,9 @@ WebInspector.SourceFrame.prototype = {
 
         if (tmp < code.length)
             line.appendChild(document.createTextNode(code.substring(tmp, i)));
+
+        if (messageBubble)
+            line.appendChild(messageBubble);
     },
 
     syntaxHighlightJavascript: function()