| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 { | 205 { |
| 206 if (!result) | 206 if (!result) |
| 207 return; | 207 return; |
| 208 | 208 |
| 209 WebInspector.console.showPromise().then(reportUponEvaluation); | 209 WebInspector.console.showPromise().then(reportUponEvaluation); |
| 210 function reportUponEvaluation() | 210 function reportUponEvaluation() |
| 211 { | 211 { |
| 212 target.consoleModel.dispatchEventToListeners(WebInspector.ConsoleMod
el.Events.CommandEvaluated, {result: result, wasThrown: wasThrown, text: text, c
ommandMessage: commandMessage, exceptionDetails: exceptionDetails}); | 212 target.consoleModel.dispatchEventToListeners(WebInspector.ConsoleMod
el.Events.CommandEvaluated, {result: result, wasThrown: wasThrown, text: text, c
ommandMessage: commandMessage, exceptionDetails: exceptionDetails}); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 if (/^\s*\{/.test(text) && /\}\s*$/.test(text)) | 215 |
| 216 text = '(' + text + ')'; | 216 /** |
| 217 * @param {string} code |
| 218 * @suppress {uselessCode} |
| 219 * @return {boolean} |
| 220 */ |
| 221 function looksLikeAnObjectLiteral(code) |
| 222 { |
| 223 // Only parenthesize what appears to be an object literal. |
| 224 if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code))) |
| 225 return false; |
| 226 |
| 227 try { |
| 228 // Check if the code can be interpreted as an expression. |
| 229 Function("return " + code + ";"); |
| 230 |
| 231 // No syntax error! Does it work parenthesized? |
| 232 Function("(" + code + ")"); |
| 233 |
| 234 return true; |
| 235 } catch (e) { |
| 236 return false; |
| 237 } |
| 238 } |
| 239 |
| 240 if (looksLikeAnObjectLiteral(text)) |
| 241 text = "(" + text + ")"; |
| 242 |
| 217 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false
, true, printResult); | 243 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false
, true, printResult); |
| 218 | 244 |
| 219 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console
Evaluated); | 245 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console
Evaluated); |
| 220 } | 246 } |
| 221 | 247 |
| 222 WebInspector.ConsoleModel.clearConsole = function() | 248 WebInspector.ConsoleModel.clearConsole = function() |
| 223 { | 249 { |
| 224 var targets = WebInspector.targetManager.targets(); | 250 var targets = WebInspector.targetManager.targets(); |
| 225 for (var i = 0; i < targets.length; ++i) | 251 for (var i = 0; i < targets.length; ++i) |
| 226 targets[i].consoleModel.requestClearMessages(); | 252 targets[i].consoleModel.requestClearMessages(); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, event.data); | 629 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, event.data); |
| 604 }, | 630 }, |
| 605 | 631 |
| 606 __proto__: WebInspector.Object.prototype | 632 __proto__: WebInspector.Object.prototype |
| 607 } | 633 } |
| 608 | 634 |
| 609 /** | 635 /** |
| 610 * @type {!WebInspector.MultitargetConsoleModel} | 636 * @type {!WebInspector.MultitargetConsoleModel} |
| 611 */ | 637 */ |
| 612 WebInspector.multitargetConsoleModel; | 638 WebInspector.multitargetConsoleModel; |
| OLD | NEW |