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} | |
| 219 * @return {boolean} | |
| 220 */ | |
| 221 function looksLikeAnObjectLiteral(code) { | |
| 222 // Only parenthesize what appears to be an object literal. | |
| 223 if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code))) { | |
| 224 return false; | |
| 225 } | |
| 226 | |
| 227 try { | |
| 228 // Check if the code can be interpreted as an expression. | |
| 229 Function("return " + code + ";"); | |
|
kozy
2016/04/11 19:17:32
We can't execute user code in frontend. It can pro
| |
| 230 } | |
| 231 catch (e) { | |
| 232 return false; | |
| 233 } | |
| 234 | |
| 235 // No syntax error! Does it work parenthesized? | |
| 236 try { | |
| 237 Function("(" + code + ")"); | |
| 238 return true; | |
| 239 } | |
| 240 catch (e) { | |
| 241 return false; | |
| 242 } | |
| 243 } | |
| 244 if (looksLikeAnObjectLiteral(text)) { | |
| 245 text = "(" + text + ")"; | |
| 246 WebInspector.console.warn("Evaluating input as an object literal."); | |
| 247 } | |
| 217 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false , true, printResult); | 248 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false , true, printResult); |
| 218 | 249 |
| 219 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console Evaluated); | 250 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console Evaluated); |
| 220 } | 251 } |
| 221 | 252 |
| 222 WebInspector.ConsoleModel.clearConsole = function() | 253 WebInspector.ConsoleModel.clearConsole = function() |
| 223 { | 254 { |
| 224 var targets = WebInspector.targetManager.targets(); | 255 var targets = WebInspector.targetManager.targets(); |
| 225 for (var i = 0; i < targets.length; ++i) | 256 for (var i = 0; i < targets.length; ++i) |
| 226 targets[i].consoleModel.requestClearMessages(); | 257 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); | 634 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data); |
| 604 }, | 635 }, |
| 605 | 636 |
| 606 __proto__: WebInspector.Object.prototype | 637 __proto__: WebInspector.Object.prototype |
| 607 } | 638 } |
| 608 | 639 |
| 609 /** | 640 /** |
| 610 * @type {!WebInspector.MultitargetConsoleModel} | 641 * @type {!WebInspector.MultitargetConsoleModel} |
| 611 */ | 642 */ |
| 612 WebInspector.multitargetConsoleModel; | 643 WebInspector.multitargetConsoleModel; |
| OLD | NEW |