| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Javascript that is being injected into the inspectable page | 6 * @fileoverview Javascript that is being injected into the inspectable page |
| 7 * while debugging. | 7 * while debugging. |
| 8 */ | 8 */ |
| 9 goog.provide('devtools.Injected'); | 9 goog.provide('devtools.Injected'); |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return this.cachedConsoleObjects_[id]; | 56 return this.cachedConsoleObjects_[id]; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Returns array of properties for a given node on a given path. | 61 * Returns array of properties for a given node on a given path. |
| 62 * @param {number} nodeId Id of node to get prorotypes for. | 62 * @param {number} nodeId Id of node to get prorotypes for. |
| 63 * @param {Array.<string>} path Path to the nested object. | 63 * @param {Array.<string>} path Path to the nested object. |
| 64 * @param {number} protoDepth Depth of the actual proto to inspect. | 64 * @param {number} protoDepth Depth of the actual proto to inspect. |
| 65 * @return {Array.<Object>} Array where each property is represented | 65 * @return {Array.<Object>} Array where each property is represented |
| 66 * by the tree entries [{string} type, {string} name, {Object} value]. | 66 * by the four entries [{string} type, {string} name, {Object} value, |
| 67 * {string} objectClassNameOrFunctionSignature]. |
| 67 */ | 68 */ |
| 68 devtools.Injected.prototype.getProperties = | 69 devtools.Injected.prototype.getProperties = |
| 69 function(nodeId, path, protoDepth) { | 70 function(nodeId, path, protoDepth) { |
| 70 var result = []; | 71 var result = []; |
| 71 var obj = this.getObjectForId_(nodeId); | 72 var obj = this.getObjectForId_(nodeId); |
| 72 if (!obj) { | 73 if (!obj) { |
| 73 return []; | 74 return []; |
| 74 } | 75 } |
| 75 | 76 |
| 76 // Follow the path. | 77 // Follow the path. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 if (!obj) { | 91 if (!obj) { |
| 91 return []; | 92 return []; |
| 92 } | 93 } |
| 93 | 94 |
| 94 // Go over properties, prepare results. | 95 // Go over properties, prepare results. |
| 95 for (var name in obj) { | 96 for (var name in obj) { |
| 96 if (protoDepth != -1 && 'hasOwnProperty' in obj && | 97 if (protoDepth != -1 && 'hasOwnProperty' in obj && |
| 97 !obj.hasOwnProperty(name)) { | 98 !obj.hasOwnProperty(name)) { |
| 98 continue; | 99 continue; |
| 99 } | 100 } |
| 100 var type = typeof obj[name]; | 101 var value = obj[name]; |
| 102 var type = typeof value; |
| 101 result.push(type); | 103 result.push(type); |
| 102 result.push(name); | 104 result.push(name); |
| 103 if (type == 'string') { | 105 if (type == 'string') { |
| 104 var str = obj[name]; | 106 var str = value; |
| 105 result.push(str.length > 99 ? str.substr(0, 99) + '...' : str); | 107 result.push(str.length > 99 ? str.substr(0, 99) + '...' : str); |
| 106 } else if (type != 'object' && type != 'function') { | 108 result.push(undefined); |
| 107 result.push(obj[name]); | 109 } else if (type == 'function') { |
| 110 result.push(undefined); |
| 111 var str = Function.prototype.toString.call(value); |
| 112 // Cut function signature (everything before first ')'). |
| 113 var signatureLength = str.search(/\)/); |
| 114 str = str.substr(0, signatureLength + 1); |
| 115 // Collapse each group of consecutive whitespaces into one whitespaces |
| 116 // and add body brackets. |
| 117 str = str.replace(/\s+/g, ' ') + ' {}'; |
| 118 result.push(str); |
| 119 } else if (type == 'object') { |
| 120 result.push(undefined); |
| 121 result.push(this.getClassName_(value)); |
| 108 } else { | 122 } else { |
| 123 result.push(value); |
| 109 result.push(undefined); | 124 result.push(undefined); |
| 110 } | 125 } |
| 111 } | 126 } |
| 112 return result; | 127 return result; |
| 113 }; | 128 }; |
| 114 | 129 |
| 115 | 130 |
| 116 /** | 131 /** |
| 117 * Returns array of prototypes for a given node. | 132 * Returns array of prototypes for a given node. |
| 118 * @param {number} nodeId Id of node to get prorotypes for. | 133 * @param {number} nodeId Id of node to get prorotypes for. |
| 119 * @return {Array<string>} Array of proto names. | 134 * @return {Array<string>} Array of proto names. |
| 120 */ | 135 */ |
| 121 devtools.Injected.prototype.getPrototypes = function(nodeId) { | 136 devtools.Injected.prototype.getPrototypes = function(nodeId) { |
| 122 var node = DevToolsAgentHost.getNodeForId(nodeId); | 137 var node = DevToolsAgentHost.getNodeForId(nodeId); |
| 123 if (!node) { | 138 if (!node) { |
| 124 return []; | 139 return []; |
| 125 } | 140 } |
| 126 | 141 |
| 127 var result = []; | 142 var result = []; |
| 128 for (var prototype = node; prototype; prototype = prototype.__proto__) { | 143 for (var prototype = node; prototype; prototype = prototype.__proto__) { |
| 129 var description = Object.prototype.toString.call(prototype); | 144 result.push(this.getClassName_(prototype)); |
| 130 result.push(description.replace(/^\[object (.*)\]$/i, '$1')); | |
| 131 } | 145 } |
| 132 return result; | 146 return result; |
| 133 }; | 147 }; |
| 134 | 148 |
| 135 | 149 |
| 136 /** | 150 /** |
| 151 * @param {Object|Function|null} value An object whose class name to return. |
| 152 * @return {string} The value class name. |
| 153 */ |
| 154 devtools.Injected.prototype.getClassName_ = function(value) { |
| 155 return (value == null) ? 'null' : value.constructor.name; |
| 156 }; |
| 157 |
| 158 |
| 159 /** |
| 137 * Returns style information that is used in devtools.js. | 160 * Returns style information that is used in devtools.js. |
| 138 * @param {number} nodeId Id of node to get prorotypes for. | 161 * @param {number} nodeId Id of node to get prorotypes for. |
| 139 * @param {boolean} authorOnly Determines whether only author styles need to | 162 * @param {boolean} authorOnly Determines whether only author styles need to |
| 140 * be added. | 163 * be added. |
| 141 * @return {string} Style collection descriptor. | 164 * @return {string} Style collection descriptor. |
| 142 */ | 165 */ |
| 143 devtools.Injected.prototype.getStyles = function(nodeId, authorOnly) { | 166 devtools.Injected.prototype.getStyles = function(nodeId, authorOnly) { |
| 144 var node = DevToolsAgentHost.getNodeForId(nodeId); | 167 var node = DevToolsAgentHost.getNodeForId(nodeId); |
| 145 if (!node) { | 168 if (!node) { |
| 146 return {}; | 169 return {}; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 * @return {string} console object id. | 566 * @return {string} console object id. |
| 544 */ | 567 */ |
| 545 devtools.Injected.prototype.evaluate = function(expression) { | 568 devtools.Injected.prototype.evaluate = function(expression) { |
| 546 try { | 569 try { |
| 547 // Evaluate the expression in the global context of the inspected window. | 570 // Evaluate the expression in the global context of the inspected window. |
| 548 return [ this.wrapConsoleObject(contentWindow.eval(expression)), false ]; | 571 return [ this.wrapConsoleObject(contentWindow.eval(expression)), false ]; |
| 549 } catch (e) { | 572 } catch (e) { |
| 550 return [ e.toString(), true ]; | 573 return [ e.toString(), true ]; |
| 551 } | 574 } |
| 552 }; | 575 }; |
| OLD | NEW |