2009-07-06 Pavel Feldman <pfeldman@chromium.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Jul 2009 20:47:32 +0000 (20:47 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Jul 2009 20:47:32 +0000 (20:47 +0000)
        Reviewed by Timothy Hatcher.

        WebInspector: suggest global properties based on async evaluation.

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

        Before this change, empty string was evaluated to the global object
        (or scope chain object) synchronously. This is now fixed and global
        object is evaluated using the same control flow.

        * inspector/front-end/Console.js:
        (WebInspector.Console.prototype.completions):
        (WebInspector.Console.prototype._evalInInspectedWindow):
        * inspector/front-end/ScriptsPanel.js:
        (WebInspector.ScriptsPanel.prototype._variablesInScope):

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

WebCore/ChangeLog
WebCore/inspector/front-end/Console.js
WebCore/inspector/front-end/ScriptsPanel.js

index b06c5043d4639ccaf5d41be91dbc3dcb40d15137..0771995203440a8dcd3fd160dc16d9aa1b6c9381 100644 (file)
@@ -1,3 +1,21 @@
+2009-07-06  Pavel Feldman  <pfeldman@chromium.org>
+
+        Reviewed by Timothy Hatcher.
+
+        WebInspector: suggest global properties based on async evaluation.
+
+        https://bugs.webkit.org/show_bug.cgi?id=26976
+
+        Before this change, empty string was evaluated to the global object
+        (or scope chain object) synchronously. This is now fixed and global
+        object is evaluated using the same control flow.
+
+        * inspector/front-end/Console.js:
+        (WebInspector.Console.prototype.completions):
+        (WebInspector.Console.prototype._evalInInspectedWindow):
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel.prototype._variablesInScope):
+
 2009-07-06  Ojan Vafai  <ojan@chromium.org>
 
         Reviewed by Eric Seidel.
index bce1784388f2ffbe074751c2eba4d61ae4176f0c..b34061e5fe6aa95861c9ea012b44c80f9c3d0531 100644 (file)
@@ -260,16 +260,7 @@ WebInspector.Console.prototype = {
             return;
 
         var reportCompletions = this._reportCompletions.bind(this, bestMatchOnly, completionsReadyCallback, dotNotation, bracketNotation, prefix);
-        if (expressionString) {
-            this._evalInInspectedWindow(expressionString, reportCompletions);
-        } else {
-            // There is no expressionString, so the completion should happen against global properties.
-            // Or if the debugger is paused, against properties in scope of the selected call frame.
-            if (WebInspector.panels.scripts && WebInspector.panels.scripts.paused)
-                reportCompletions(WebInspector.panels.scripts.variablesInScopeForSelectedCallFrame());
-            else
-                reportCompletions(InspectorController.inspectedWindow());
-        }
+        this._evalInInspectedWindow(expressionString, reportCompletions);
     },
     
     _reportCompletions: function(bestMatchOnly, completionsReadyCallback, dotNotation, bracketNotation, prefix, result) {
@@ -397,7 +388,6 @@ WebInspector.Console.prototype = {
             WebInspector.panels.scripts.evaluateInSelectedCallFrame(expression, false, callback);
             return;
         }
-
         this.doEvalInWindow(expression, callback);
     },
     
@@ -431,6 +421,11 @@ WebInspector.Console.prototype = {
     
     doEvalInWindow: function(expression, callback)
     {
+        if (!expression) {
+            // There is no expression, so the completion should happen against global properties.
+            expression = "this";
+        }
+
         // Surround the expression in with statements to inject our command line API so that
         // the window object properties still take more precedent than our API functions.
         expression = "with (window._inspectorCommandLineAPI) { with (window) { " + expression + " } }";
index f3f453f61a162c0d17df93938fe87c9e3fbb6015..56b70cf69e8df9a90ff49a361455a9e834cbbf1b 100644 (file)
@@ -370,8 +370,14 @@ WebInspector.ScriptsPanel.prototype = {
 
     doEvalInCallFrame: function(callFrame, code, callback)
     {
+        var panel = this;
         function delayedEvaluation()
         {
+            if (!code) {
+                // Evaluate into properties in scope of the selected call frame.
+                callback(panel._variablesInScope(callFrame));
+                return;
+            }
             try {
                 callback(callFrame.evaluate(code));
             } catch (e) {
@@ -381,20 +387,15 @@ WebInspector.ScriptsPanel.prototype = {
         setTimeout(delayedEvaluation, 0);
     },
 
-    variablesInScopeForSelectedCallFrame: function()
+    _variablesInScope: function(callFrame)
     {
-        var selectedCallFrame = this.sidebarPanes.callstack.selectedCallFrame;
-        if (!this._paused || !selectedCallFrame)
-            return {};
-
         var result = {};
-        var scopeChain = selectedCallFrame.scopeChain;
+        var scopeChain = callFrame.scopeChain;
         for (var i = 0; i < scopeChain.length; ++i) {
             var scopeObject = scopeChain[i];
             for (var property in scopeObject)
                 result[property] = true;
         }
-
         return result;
     },