| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 }, | 180 }, |
| 181 | 181 |
| 182 _getPropertyNames: function(object, resultSet) | 182 _getPropertyNames: function(object, resultSet) |
| 183 { | 183 { |
| 184 var propertyNameSet = {}; | 184 var propertyNameSet = {}; |
| 185 this._populatePropertyNames(object, propertyNameSet); | 185 this._populatePropertyNames(object, propertyNameSet); |
| 186 return Object.keys(propertyNameSet); | 186 return Object.keys(propertyNameSet); |
| 187 }, | 187 }, |
| 188 | 188 |
| 189 getCompletions: function(expression, includeInspectorCommandLineAPI) | 189 getCompletions: function(expression, includeCommandLineAPI) |
| 190 { | 190 { |
| 191 var props = {}; | 191 var props = {}; |
| 192 try { | 192 try { |
| 193 if (!expression) | 193 if (!expression) |
| 194 expression = "this"; | 194 expression = "this"; |
| 195 var expressionResult = this._evaluateOn(inspectedWindow.eval, inspec
tedWindow, expression, false); | 195 var expressionResult = this._evaluateOn(inspectedWindow.eval, inspec
tedWindow, expression, false, false); |
| 196 | 196 |
| 197 if (typeof expressionResult === "object") | 197 if (typeof expressionResult === "object") |
| 198 this._populatePropertyNames(expressionResult, props); | 198 this._populatePropertyNames(expressionResult, props); |
| 199 | 199 |
| 200 if (includeInspectorCommandLineAPI) { | 200 if (includeCommandLineAPI) { |
| 201 for (var prop in this._commandLineAPI) | 201 for (var prop in this._commandLineAPI) |
| 202 props[prop] = true; | 202 props[prop] = true; |
| 203 } | 203 } |
| 204 } catch(e) { | 204 } catch(e) { |
| 205 } | 205 } |
| 206 return props; | 206 return props; |
| 207 }, | 207 }, |
| 208 | 208 |
| 209 getCompletionsOnCallFrame: function(callFrameId, expression, includeInspecto
rCommandLineAPI) | 209 getCompletionsOnCallFrame: function(callFrameId, expression, includeCommandL
ineAPI) |
| 210 { | 210 { |
| 211 var props = {}; | 211 var props = {}; |
| 212 try { | 212 try { |
| 213 var callFrame = this._callFrameForId(callFrameId); | 213 var callFrame = this._callFrameForId(callFrameId); |
| 214 if (!callFrame) | 214 if (!callFrame) |
| 215 return props; | 215 return props; |
| 216 | 216 |
| 217 if (expression) { | 217 if (expression) { |
| 218 var expressionResult = this._evaluateOn(callFrame.evaluate, call
Frame, expression, true); | 218 var expressionResult = this._evaluateOn(callFrame.evaluate, call
Frame, expression, true, false); |
| 219 if (typeof expressionResult === "object") | 219 if (typeof expressionResult === "object") |
| 220 this._populatePropertyNames(expressionResult, props); | 220 this._populatePropertyNames(expressionResult, props); |
| 221 } else { | 221 } else { |
| 222 // Evaluate into properties in scope of the selected call frame. | 222 // Evaluate into properties in scope of the selected call frame. |
| 223 var scopeChain = callFrame.scopeChain; | 223 var scopeChain = callFrame.scopeChain; |
| 224 for (var i = 0; i < scopeChain.length; ++i) | 224 for (var i = 0; i < scopeChain.length; ++i) |
| 225 this._populatePropertyNames(scopeChain[i], props); | 225 this._populatePropertyNames(scopeChain[i], props); |
| 226 } | 226 } |
| 227 | 227 |
| 228 if (includeInspectorCommandLineAPI) { | 228 if (includeCommandLineAPI) { |
| 229 for (var prop in this._commandLineAPI) | 229 for (var prop in this._commandLineAPI) |
| 230 props[prop] = true; | 230 props[prop] = true; |
| 231 } | 231 } |
| 232 } catch(e) { | 232 } catch(e) { |
| 233 } | 233 } |
| 234 return props; | 234 return props; |
| 235 }, | 235 }, |
| 236 | 236 |
| 237 evaluate: function(expression, objectGroup) | 237 evaluate: function(expression, objectGroup, injectCommandLineAPI) |
| 238 { | 238 { |
| 239 return this._evaluateAndWrap(inspectedWindow.eval, inspectedWindow, expr
ession, objectGroup, false); | 239 return this._evaluateAndWrap(inspectedWindow.eval, inspectedWindow, expr
ession, objectGroup, false, injectCommandLineAPI); |
| 240 }, | 240 }, |
| 241 | 241 |
| 242 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is
EvalOnCallFrame) | 242 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is
EvalOnCallFrame, injectCommandLineAPI) |
| 243 { | 243 { |
| 244 try { | 244 try { |
| 245 return this._wrapObject(this._evaluateOn(evalFunction, object, expre
ssion, isEvalOnCallFrame), objectGroup); | 245 return this._wrapObject(this._evaluateOn(evalFunction, object, expre
ssion, isEvalOnCallFrame, injectCommandLineAPI), objectGroup); |
| 246 } catch (e) { | 246 } catch (e) { |
| 247 return InjectedScript.RemoteObject.fromException(e); | 247 return InjectedScript.RemoteObject.fromException(e); |
| 248 } | 248 } |
| 249 }, | 249 }, |
| 250 | 250 |
| 251 _evaluateOn: function(evalFunction, object, expression, isEvalOnCallFrame) | 251 _evaluateOn: function(evalFunction, object, expression, isEvalOnCallFrame, i
njectCommandLineAPI) |
| 252 { | 252 { |
| 253 // Only install command line api object for the time of evaluation. | 253 // Only install command line api object for the time of evaluation. |
| 254 // Surround the expression in with statements to inject our command line
API so that | 254 // Surround the expression in with statements to inject our command line
API so that |
| 255 // the window object properties still take more precedent than our API f
unctions. | 255 // the window object properties still take more precedent than our API f
unctions. |
| 256 inspectedWindow.console._commandLineAPI = this._commandLineAPI; | 256 inspectedWindow.console._commandLineAPI = this._commandLineAPI; |
| 257 | 257 |
| 258 // We don't want local variables to be shadowed by global ones when eval
uating on CallFrame. | 258 // We don't want local variables to be shadowed by global ones when eval
uating on CallFrame. |
| 259 if (!isEvalOnCallFrame) | 259 if (!isEvalOnCallFrame) |
| 260 expression = "with (window) {\n" + expression + "\n} "; | 260 expression = "with (window) {\n" + expression + "\n} "; |
| 261 expression = "with (window ? window.console._commandLineAPI : {}) {\n" +
expression + "\n}"; | 261 if (injectCommandLineAPI) |
| 262 expression = "with (window ? window.console._commandLineAPI : {}) {\
n" + expression + "\n}"; |
| 262 var value = evalFunction.call(object, expression); | 263 var value = evalFunction.call(object, expression); |
| 263 | 264 |
| 264 delete inspectedWindow.console._commandLineAPI; | 265 delete inspectedWindow.console._commandLineAPI; |
| 265 | 266 |
| 266 // When evaluating on call frame error is not thrown, but returned as a
value. | 267 // When evaluating on call frame error is not thrown, but returned as a
value. |
| 267 if (this._type(value) === "error") | 268 if (this._type(value) === "error") |
| 268 throw value.toString(); | 269 throw value.toString(); |
| 269 | 270 |
| 270 return value; | 271 return value; |
| 271 }, | 272 }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 284 injectedScript.releaseWrapperObjectGroup("backtrace"); | 285 injectedScript.releaseWrapperObjectGroup("backtrace"); |
| 285 var result = []; | 286 var result = []; |
| 286 var depth = 0; | 287 var depth = 0; |
| 287 do { | 288 do { |
| 288 result.push(new InjectedScript.CallFrameProxy(depth++, callFrame)); | 289 result.push(new InjectedScript.CallFrameProxy(depth++, callFrame)); |
| 289 callFrame = callFrame.caller; | 290 callFrame = callFrame.caller; |
| 290 } while (callFrame); | 291 } while (callFrame); |
| 291 return result; | 292 return result; |
| 292 }, | 293 }, |
| 293 | 294 |
| 294 evaluateOnCallFrame: function(callFrameId, code, objectGroup) | 295 evaluateOnCallFrame: function(callFrameId, expression, objectGroup, injectCo
mmandLineAPI) |
| 295 { | 296 { |
| 296 var callFrame = this._callFrameForId(callFrameId); | 297 var callFrame = this._callFrameForId(callFrameId); |
| 297 if (!callFrame) | 298 if (!callFrame) |
| 298 return false; | 299 return false; |
| 299 return this._evaluateAndWrap(callFrame.evaluate, callFrame, code, object
Group, true); | 300 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression,
objectGroup, true, injectCommandLineAPI); |
| 300 }, | 301 }, |
| 301 | 302 |
| 302 _callFrameForId: function(callFrameId) | 303 _callFrameForId: function(callFrameId) |
| 303 { | 304 { |
| 304 var parsedCallFrameId = eval("(" + callFrameId + ")"); | 305 var parsedCallFrameId = eval("(" + callFrameId + ")"); |
| 305 var ordinal = parsedCallFrameId.ordinal; | 306 var ordinal = parsedCallFrameId.ordinal; |
| 306 var callFrame = InjectedScriptHost.currentCallFrame(); | 307 var callFrame = InjectedScriptHost.currentCallFrame(); |
| 307 while (--ordinal >= 0 && callFrame) | 308 while (--ordinal >= 0 && callFrame) |
| 308 callFrame = callFrame.caller; | 309 callFrame = callFrame.caller; |
| 309 return callFrame; | 310 return callFrame; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 clear: function() | 719 clear: function() |
| 719 { | 720 { |
| 720 InjectedScriptHost.clearConsoleMessages(); | 721 InjectedScriptHost.clearConsoleMessages(); |
| 721 } | 722 } |
| 722 } | 723 } |
| 723 | 724 |
| 724 injectedScript._commandLineAPI = new CommandLineAPI(); | 725 injectedScript._commandLineAPI = new CommandLineAPI(); |
| 725 return injectedScript; | 726 return injectedScript; |
| 726 }) | 727 }) |
| 727 | 728 |
| OLD | NEW |