Reviewed by Maciej.
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Nov 2006 17:08:16 +0000 (17:08 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Nov 2006 17:08:16 +0000 (17:08 +0000)
        Bug 11525: [Drosera] function menu doesn't understand object.method = function() {} syntax
        http://bugs.webkit.org/show_bug.cgi?id=11525

        * Drosera/debugger.js: imporved the function name code

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

WebKitTools/ChangeLog
WebKitTools/Drosera/debugger.js

index 46520cd051687bfa462d667a6c45d8949b53b5f0..b49159fd6cf317ae302b4144ead4bbc864f30421 100644 (file)
@@ -1,3 +1,12 @@
+2006-11-05  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Maciej.
+
+        Bug 11525: [Drosera] function menu doesn't understand object.method = function() {} syntax
+        http://bugs.webkit.org/show_bug.cgi?id=11525
+
+        * Drosera/debugger.js: imporved the function name code
+
 2006-11-06  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Maciej.
index a4020b0e9c9476c6bb8cab25c5df3330b478a5c5..cfb2a1ca4c665ff2f978682550219b1a93b24df8 100644 (file)
@@ -800,43 +800,65 @@ function syntaxHighlight(code, file)
 
             if (keywords[keyword]) {
                 var functionName = "";
+                var functionIsAnonymous = false;
                 if (keyword == "function") {
                     var functionKeywordOffset = 8;
-                    var functionNameChar = "";
-                    
-                    if (code.charAt(i + functionKeywordOffset) == " ") { 
-                        functionNameChar = code.charAt(i + functionKeywordOffset + 1);
-                        functionKeywordOffset++;
-                    } else
-                        functionNameChar = code.charAt(i + functionKeywordOffset);
-                    
-                    if (functionNameChar == "(") {
-                        functionName = "function";
-                        file.functionNames.push(functionName);
-                    } else {
-                        while (functionNameChar != "(") {
-                            functionName += functionNameChar;                        
-                            functionKeywordOffset++;
-                            functionNameChar = code.charAt(i + functionKeywordOffset);
-                            if ((i + functionKeywordOffset) >= code.length || functionNameChar == " " || functionNameChar == "\n") break;
+                    for (var j = i + functionKeywordOffset; j < code.length; j++) {
+                        cj = code.charAt(j);
+                        if (cj == " ")
+                            continue;
+                        if (cj == "(")
+                            break;
+                        functionName += cj;
+                    }
+
+                    if (!functionName.length) {
+                        functionIsAnonymous = true;
+                        var functionAssignmentFound = false;
+                        var functionNameStart = -1;
+                        var functionNameEnd = -1;
+
+                        for (var j = i - 1; j >= 0; j--) {
+                            cj = code.charAt(j);
+                            if (cj == ":" || cj == "=") {
+                                functionAssignmentFound = true;
+                                continue;
+                            }
+
+                            var curCharIsSpace = (cj == " " || cj == "\t" || cj == "\n");
+                            if (functionAssignmentFound && functionNameEnd == -1 && !curCharIsSpace) {
+                                functionNameEnd = j + 1;
+                            } else if (!functionAssignmentFound && !curCharIsSpace) {
+                                break;
+                            } else if (functionNameEnd != -1 && curCharIsSpace) {
+                                functionNameStart = j;
+                                break;
+                            }
                         }
+
+                        if (functionNameStart != -1 && functionNameEnd != -1)
+                            functionName = code.substring(functionNameStart, functionNameEnd);
                     }
+
+                    if (!functionName.length)
+                        functionName = "function";
+
+                    file.functionNames.push(functionName);
                 }
 
                 var fileIndex = filesLookup[file.url];
 
-                if (functionName == "function") 
+                if (keyword == "function") 
                     result += "<span class=\"keyword\"><a name=\"function-" + fileIndex + "-" + file.functionNames.length + "\" id=\"" + fileIndex + "-" + file.functionNames.length + "\">" + keyword + "</a></span>";
                 else
                     result += "<span class=\"keyword\">" + keyword + "</span>";
-                
-                if (functionName.length > 0 && functionName != "function") {
-                    file.functionNames.push(functionName);
+
+                if (functionName.length && !functionIsAnonymous) {
                     result += " <a name=\"function-" + fileIndex + "-" + file.functionNames.length + "\" id=\"" + fileIndex + "-" + file.functionNames.length + "\">" + functionName + "</a>";
                     i += keyword.length + functionName.length;
                 } else
                     i += keyword.length - 1;
-                
+
                 continue;
             }
         }