diff options
Diffstat (limited to 'WebCore/inspector/front-end/ConsoleView.js')
-rw-r--r-- | WebCore/inspector/front-end/ConsoleView.js | 165 |
1 files changed, 106 insertions, 59 deletions
diff --git a/WebCore/inspector/front-end/ConsoleView.js b/WebCore/inspector/front-end/ConsoleView.js index d4693b7..6851eea 100644 --- a/WebCore/inspector/front-end/ConsoleView.js +++ b/WebCore/inspector/front-end/ConsoleView.js @@ -175,7 +175,7 @@ WebInspector.ConsoleView.prototype = { clearMessages: function(clearInspectorController) { if (clearInspectorController) - InspectorController.clearMessages(false); + InspectorController.clearMessages(); if (WebInspector.panels.resources) WebInspector.panels.resources.clearMessages(); @@ -212,42 +212,10 @@ WebInspector.ConsoleView.prototype = { return; var reportCompletions = this._reportCompletions.bind(this, bestMatchOnly, completionsReadyCallback, dotNotation, bracketNotation, prefix); - // Collect comma separated object properties for the completion. - - if (!expressionString) { - if (WebInspector.panels.scripts && WebInspector.panels.scripts.paused) { - // Evaluate into properties in scope of the selected call frame. - reportCompletions(WebInspector.panels.scripts.variablesInSelectedCallFrame()); - return; - } else { - expressionString = "this"; - } - } - - function parsingCallback(result, isException) - { - if (!isException) - result = JSON.parse(result); - reportCompletions(result, isException); - } - - this._evalInInspectedWindow( - "(function() {" + - "var props = {};" + - "for (var prop in (" + expressionString + ")) props[prop] = true;" + - ((!dotNotation && !bracketNotation) ? - "for (var prop in window._inspectorCommandLineAPI)" + - "if (prop.charAt(0) !== '_') props[prop] = true;" - : "") + - "return JSON.stringify(props);" + - "})()", - parsingCallback); + this._evalInInspectedWindow(expressionString, reportCompletions); }, - _reportCompletions: function(bestMatchOnly, completionsReadyCallback, dotNotation, bracketNotation, prefix, result, isException) { - if (isException) - return; - + _reportCompletions: function(bestMatchOnly, completionsReadyCallback, dotNotation, bracketNotation, prefix, result) { if (bracketNotation) { if (prefix.length && prefix[0] === "'") var quoteUsed = "'"; @@ -256,7 +224,16 @@ WebInspector.ConsoleView.prototype = { } var results = []; - var properties = Object.sortedProperties(result); + var properties = Object.properties(result); + if (!dotNotation && !bracketNotation && result._inspectorCommandLineAPI) { + var commandLineAPI = Object.properties(result._inspectorCommandLineAPI); + for (var i = 0; i < commandLineAPI.length; ++i) { + var property = commandLineAPI[i]; + if (property.charAt(0) !== "_") + properties.push(property); + } + } + properties.sort(); for (var i = 0; i < properties.length; ++i) { var property = properties[i]; @@ -311,7 +288,7 @@ WebInspector.ConsoleView.prototype = { if (!link || !link.representedNode) return; - WebInspector.updateFocusedNode(link.representedNode.id); + WebInspector.updateFocusedNode(link.representedNode); event.stopPropagation(); event.preventDefault(); }, @@ -336,6 +313,74 @@ WebInspector.ConsoleView.prototype = { this.doEvalInWindow(expression, callback); }, + _ensureCommandLineAPIInstalled: function(inspectedWindow) + { + if (!inspectedWindow._inspectorCommandLineAPI) { + inspectedWindow.eval("window._inspectorCommandLineAPI = { \ + $: function() { return document.getElementById.apply(document, arguments) }, \ + $$: function() { return document.querySelectorAll.apply(document, arguments) }, \ + $x: function(xpath, context) { \ + var nodes = []; \ + try { \ + var doc = context || document; \ + var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); \ + var node; \ + while (node = results.iterateNext()) nodes.push(node); \ + } catch (e) {} \ + return nodes; \ + }, \ + dir: function() { return console.dir.apply(console, arguments) }, \ + dirxml: function() { return console.dirxml.apply(console, arguments) }, \ + keys: function(o) { var a = []; for (var k in o) a.push(k); return a; }, \ + values: function(o) { var a = []; for (var k in o) a.push(o[k]); return a; }, \ + profile: function() { return console.profile.apply(console, arguments) }, \ + profileEnd: function() { return console.profileEnd.apply(console, arguments) }, \ + _inspectedNodes: [], \ + get $0() { return _inspectorCommandLineAPI._inspectedNodes[0] }, \ + get $1() { return _inspectorCommandLineAPI._inspectedNodes[1] }, \ + get $2() { return _inspectorCommandLineAPI._inspectedNodes[2] }, \ + get $3() { return _inspectorCommandLineAPI._inspectedNodes[3] }, \ + get $4() { return _inspectorCommandLineAPI._inspectedNodes[4] } \ + };"); + + inspectedWindow._inspectorCommandLineAPI.clear = InspectorController.wrapCallback(this.clearMessages.bind(this)); + inspectedWindow._inspectorCommandLineAPI.inspect = InspectorController.wrapCallback(inspectObject.bind(this)); + + function inspectObject(o) + { + if (arguments.length === 0) + return; + + InspectorController.inspectedWindow().console.log(o); + if (Object.type(o, InspectorController.inspectedWindow()) === "node") { + WebInspector.showElementsPanel(); + WebInspector.panels.elements.treeOutline.revealAndSelectNode(o); + } else { + switch (Object.describe(o)) { + case "Database": + WebInspector.showDatabasesPanel(); + WebInspector.panels.databases.selectDatabase(o); + break; + case "Storage": + WebInspector.showDatabasesPanel(); + WebInspector.panels.databases.selectDOMStorage(o); + break; + } + } + } + } + }, + + addInspectedNode: function(node) + { + var inspectedWindow = InspectorController.inspectedWindow(); + this._ensureCommandLineAPIInstalled(inspectedWindow); + var inspectedNodes = inspectedWindow._inspectorCommandLineAPI._inspectedNodes; + inspectedNodes.unshift(node); + if (inspectedNodes.length >= 5) + inspectedNodes.pop(); + }, + doEvalInWindow: function(expression, callback) { if (!expression) { @@ -343,15 +388,22 @@ WebInspector.ConsoleView.prototype = { 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 + " } }"; + var self = this; - function evalCallback(result) + function delayedEvaluation() { - if (result.exception) - callback(result.exception, true); - else - callback(result.value, false); - }; - InspectorController.evaluate(expression, evalCallback); + var inspectedWindow = InspectorController.inspectedWindow(); + self._ensureCommandLineAPIInstalled(inspectedWindow); + try { + callback(inspectedWindow.eval(expression)); + } catch (e) { + callback(e, true); + } + } + setTimeout(delayedEvaluation, 0); }, _enterKeyPressed: function(event) @@ -384,10 +436,13 @@ WebInspector.ConsoleView.prototype = { _format: function(output, forceObjectFormat) { + var inspectedWindow = InspectorController.inspectedWindow(); if (forceObjectFormat) var type = "object"; + else if (output instanceof inspectedWindow.NodeList) + var type = "array"; else - var type = Object.proxyType(output); + var type = Object.type(output, inspectedWindow); // We don't perform any special formatting on these types, so we just // pass them through the simple _formatvalue function. @@ -396,6 +451,8 @@ WebInspector.ConsoleView.prototype = { "null": 1, "boolean": 1, "number": 1, + "date": 1, + "function": 1, }; var formatter; @@ -422,16 +479,6 @@ WebInspector.ConsoleView.prototype = { elem.appendChild(document.createTextNode(val)); }, - _formatfunction: function(func, elem) - { - elem.appendChild(document.createTextNode(func.description)); - }, - - _formatdate: function(date, elem) - { - elem.appendChild(document.createTextNode(date.description)); - }, - _formatstring: function(str, elem) { elem.appendChild(document.createTextNode("\"" + str + "\"")); @@ -439,7 +486,7 @@ WebInspector.ConsoleView.prototype = { _formatregexp: function(re, elem) { - var formatted = String(re.description).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/, "$1").substring(1); + var formatted = String(re).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/, "$1").substring(1); elem.appendChild(document.createTextNode(formatted)); }, @@ -454,10 +501,10 @@ WebInspector.ConsoleView.prototype = { elem.appendChild(document.createTextNode("]")); }, - _formatnode: function(object, elem) + _formatnode: function(node, elem) { var treeOutline = new WebInspector.ElementsTreeOutline(); - treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(object.nodeId); + treeOutline.rootDOMNode = node; treeOutline.element.addStyleClass("outline-disclosure"); if (!treeOutline.children[0].hasChildren) treeOutline.element.addStyleClass("single-node"); @@ -466,7 +513,7 @@ WebInspector.ConsoleView.prototype = { _formatobject: function(obj, elem) { - elem.appendChild(new WebInspector.ObjectPropertiesSection(obj, obj.description, null, true).element); + elem.appendChild(new WebInspector.ObjectPropertiesSection(new WebInspector.ObjectProxy(obj), Object.describe(obj, true), null, null, true).element); }, _formaterror: function(obj, elem) |