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

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

Issue 2135853002: [DevTools] Better heuristic for detecting object literals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 { 206 {
207 if (!result) 207 if (!result)
208 return; 208 return;
209 209
210 WebInspector.console.showPromise().then(reportUponEvaluation); 210 WebInspector.console.showPromise().then(reportUponEvaluation);
211 function reportUponEvaluation() 211 function reportUponEvaluation()
212 { 212 {
213 target.consoleModel.dispatchEventToListeners(WebInspector.ConsoleMod el.Events.CommandEvaluated, {result: result, wasThrown: wasThrown, text: request edText, commandMessage: commandMessage, exceptionDetails: exceptionDetails}); 213 target.consoleModel.dispatchEventToListeners(WebInspector.ConsoleMod el.Events.CommandEvaluated, {result: result, wasThrown: wasThrown, text: request edText, commandMessage: commandMessage, exceptionDetails: exceptionDetails});
214 } 214 }
215 } 215 }
216 if (/^\s*\{/.test(text) && /\}\s*$/.test(text)) 216
217 /**
218 * @param {string} code
219 * @suppress {uselessCode}
220 * @return {boolean}
221 */
222 function looksLikeAnObjectLiteral(code)
223 {
224 // Only parenthesize what appears to be an object literal.
225 if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code)))
226 return false;
227
228 try {
229 // Check if the code can be interpreted as an expression.
230 Function("return " + code + ";");
231
232 // No syntax error! Does it work parenthesized?
233 Function("(" + code + ")");
234
235 return true;
236 } catch (e) {
237 return false;
238 }
239 }
240
241 if (looksLikeAnObjectLiteral(text))
217 text = "(" + text + ")"; 242 text = "(" + text + ")";
243
218 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false , true, true, printResult); 244 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false , true, true, printResult);
219
220 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console Evaluated); 245 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console Evaluated);
221 } 246 }
222 247
223 WebInspector.ConsoleModel.clearConsole = function() 248 WebInspector.ConsoleModel.clearConsole = function()
224 { 249 {
225 var targets = WebInspector.targetManager.targets(); 250 var targets = WebInspector.targetManager.targets();
226 for (var i = 0; i < targets.length; ++i) 251 for (var i = 0; i < targets.length; ++i)
227 targets[i].consoleModel.requestClearMessages(); 252 targets[i].consoleModel.requestClearMessages();
228 } 253 }
229 254
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data); 630 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data);
606 }, 631 },
607 632
608 __proto__: WebInspector.Object.prototype 633 __proto__: WebInspector.Object.prototype
609 } 634 }
610 635
611 /** 636 /**
612 * @type {!WebInspector.MultitargetConsoleModel} 637 * @type {!WebInspector.MultitargetConsoleModel}
613 */ 638 */
614 WebInspector.multitargetConsoleModel; 639 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