Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ConsoleModel.js

Issue 1875903002: [DevTools] Better heuristic for detecting object literals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/console/console-eval-object-literal-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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;
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/console/console-eval-object-literal-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698