Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/sdk/ConsoleModel.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/ConsoleModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/ConsoleModel.js |
| index aff5da307645c6f3864ce0b9e8603c14857f9d7e..7b93cf02e4a200ab41a1c16b4750f11a2761971b 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/sdk/ConsoleModel.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/sdk/ConsoleModel.js |
| @@ -212,8 +212,33 @@ WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext, |
| target.consoleModel.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEvaluated, {result: result, wasThrown: wasThrown, text: text, commandMessage: commandMessage, exceptionDetails: exceptionDetails}); |
| } |
| } |
| - if (/^\s*\{/.test(text) && /\}\s*$/.test(text)) |
| - text = '(' + text + ')'; |
| + |
| + /** |
| + * @param {string} code |
| + * @suppress {uselessCode} |
|
dgozman
2016/04/26 23:50:27
What is this?
|
| + * @return {boolean} |
| + */ |
| + function looksLikeAnObjectLiteral(code) { |
|
dgozman
2016/04/26 23:50:27
style: { on next line
|
| + // Only parenthesize what appears to be an object literal. |
| + if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code))) |
| + return false; |
| + |
| + try { |
| + // Check if the code can be interpreted as an expression. |
| + Function("return " + code + ";"); |
| + |
| + // No syntax error! Does it work parenthesized? |
| + Function("(" + code + ")"); |
| + |
| + return true; |
| + } catch (e) { |
| + return false; |
| + } |
| + } |
| + if (looksLikeAnObjectLiteral(text)) { |
| + text = "(" + text + ")"; |
| + 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
|
| + } |
| executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false, true, printResult); |
| WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.ConsoleEvaluated); |