Chromium Code Reviews| 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} | |
|
dgozman
2016/04/26 23:50:27
What is this?
| |
| 219 * @return {boolean} | |
| 220 */ | |
| 221 function looksLikeAnObjectLiteral(code) { | |
|
dgozman
2016/04/26 23:50:27
style: { on next line
| |
| 222 // Only parenthesize what appears to be an object literal. | |
| 223 if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code))) | |
| 224 return false; | |
| 225 | |
| 226 try { | |
| 227 // Check if the code can be interpreted as an expression. | |
| 228 Function("return " + code + ";"); | |
| 229 | |
| 230 // No syntax error! Does it work parenthesized? | |
| 231 Function("(" + code + ")"); | |
| 232 | |
| 233 return true; | |
| 234 } catch (e) { | |
| 235 return false; | |
| 236 } | |
| 237 } | |
| 238 if (looksLikeAnObjectLiteral(text)) { | |
| 239 text = "(" + text + ")"; | |
| 240 WebInspector.console.warn("Evaluating input as an expression."); | |
|
dgozman
2016/04/26 23:50:27
I still don't agree with this. Let's extract this
| |
| 241 } | |
| 217 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false , true, printResult); | 242 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false , true, printResult); |
| 218 | 243 |
| 219 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console Evaluated); | 244 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console Evaluated); |
| 220 } | 245 } |
| 221 | 246 |
| 222 WebInspector.ConsoleModel.clearConsole = function() | 247 WebInspector.ConsoleModel.clearConsole = function() |
| 223 { | 248 { |
| 224 var targets = WebInspector.targetManager.targets(); | 249 var targets = WebInspector.targetManager.targets(); |
| 225 for (var i = 0; i < targets.length; ++i) | 250 for (var i = 0; i < targets.length; ++i) |
| 226 targets[i].consoleModel.requestClearMessages(); | 251 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); | 628 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data); |
| 604 }, | 629 }, |
| 605 | 630 |
| 606 __proto__: WebInspector.Object.prototype | 631 __proto__: WebInspector.Object.prototype |
| 607 } | 632 } |
| 608 | 633 |
| 609 /** | 634 /** |
| 610 * @type {!WebInspector.MultitargetConsoleModel} | 635 * @type {!WebInspector.MultitargetConsoleModel} |
| 611 */ | 636 */ |
| 612 WebInspector.multitargetConsoleModel; | 637 WebInspector.multitargetConsoleModel; |
| OLD | NEW |