Title: [189190] trunk/Source/WebInspectorUI
Revision
189190
Author
[email protected]
Date
2015-08-31 15:49:40 -0700 (Mon, 31 Aug 2015)

Log Message

Web Inspector: Debugger Popovers should work for object literal shorthand variables
https://bugs.webkit.org/show_bug.cgi?id=148603

Patch by Joseph Pecoraro <[email protected]> on 2015-08-31
Reviewed by Timothy Hatcher.

* UserInterface/Controllers/CodeMirrorTokenTrackingController.js:
(WebInspector.CodeMirrorTokenTrackingController.prototype._processJavaScriptExpression):
Allow debugger popovers for object property shorthands, because they
are actually variables that have values. Previously we ignored property
name literals, because they were just property names until ES6.

* UserInterface/Views/CodeMirrorAdditions.js:
Add a helper for walking through token types from a start position. It may be useful elsewhere.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (189189 => 189190)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-08-31 22:39:30 UTC (rev 189189)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-08-31 22:49:40 UTC (rev 189190)
@@ -1,3 +1,19 @@
+2015-08-31  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: Debugger Popovers should work for object literal shorthand variables
+        https://bugs.webkit.org/show_bug.cgi?id=148603
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Controllers/CodeMirrorTokenTrackingController.js:
+        (WebInspector.CodeMirrorTokenTrackingController.prototype._processJavaScriptExpression):
+        Allow debugger popovers for object property shorthands, because they
+        are actually variables that have values. Previously we ignored property
+        name literals, because they were just property names until ES6.
+
+        * UserInterface/Views/CodeMirrorAdditions.js:
+        Add a helper for walking through token types from a start position. It may be useful elsewhere.
+
 2015-08-31  Matt Baker  <[email protected]>
 
         Web Inspector: Move the Popover code out of the Breakpoint model object

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorTokenTrackingController.js (189189 => 189190)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorTokenTrackingController.js	2015-08-31 22:39:30 UTC (rev 189189)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorTokenTrackingController.js	2015-08-31 22:49:40 UTC (rev 189190)
@@ -452,11 +452,27 @@
         if (!isProperty && !isKeyword && type.indexOf("variable") === -1 && type.indexOf("def") === -1)
             return null;
 
-        // Not object literal properties.
-        var state = this._hoveredTokenInfo.innerMode.state;
-        if (isProperty && state.lexical && state.lexical.type === "}")
-            return null;
+        // Not object literal property names, but yes if an object literal shorthand property, which is a variable.
+        let state = this._hoveredTokenInfo.innerMode.state;
+        if (isProperty && state.lexical && state.lexical.type === "}") {
+            // Peek ahead to see if the next token is "}" or ",". If it is, we are a shorthand and therefore a variable.
+            let shorthand = false;
+            let mode = this._hoveredTokenInfo.innerMode.mode;
+            let position =  {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.end};
+            WebInspector.walkTokens(this._codeMirror, mode, position, function(tokenType, string) {
+                if (tokenType)
+                    return false;
+                if (string === "," || string === "}") {
+                    shorthand = true;
+                    return false;
+                }
+                return true;
+            });
 
+            if (!shorthand)
+                return null;
+        }
+
         // Only the "this" keyword.
         if (isKeyword && this._hoveredTokenInfo.token.string !== "this")
             return null;
@@ -465,7 +481,7 @@
         var _expression_ = this._hoveredTokenInfo.token.string;
         var expressionStartPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.start};
         while (true) {
-            var token = this._codeMirror.getTokenAt(expressionStartPosition);            
+            var token = this._codeMirror.getTokenAt(expressionStartPosition);
             if (!token)
                 break;
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js (189189 => 189190)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js	2015-08-31 22:39:30 UTC (rev 189189)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js	2015-08-31 22:49:40 UTC (rev 189190)
@@ -552,3 +552,30 @@
     var bColumn = "ch" in b ? b.ch : Number.MAX_VALUE;
     return aColumn - bColumn;
 };
+
+WebInspector.walkTokens = function(cm, mode, initialPosition, callback)
+{
+    let state = CodeMirror.copyState(mode, cm.getTokenAt(initialPosition).state);
+    let lineCount = cm.lineCount();
+
+    let abort = false;
+    for (lineNumber = initialPosition.line; !abort && lineNumber < lineCount; ++lineNumber) {
+        let line = cm.getLine(lineNumber);
+        let stream = new CodeMirror.StringStream(line);
+        if (lineNumber === initialPosition.line)
+            stream.start = stream.pos = initialPosition.ch;
+
+        while (!stream.eol()) {
+            let innerMode = CodeMirror.innerMode(mode, state);
+            let tokenType = mode.token(stream, state);
+            if (!callback(tokenType, stream.current())) {
+                abort = true;
+                break;
+            }
+            stream.start = stream.pos;
+        }
+    }
+
+    if (!abort)
+        callback(null);
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to