| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (!result) | 141 if (!result) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 Common.console.showPromise().then(() => { | 144 Common.console.showPromise().then(() => { |
| 145 this.dispatchEventToListeners( | 145 this.dispatchEventToListeners( |
| 146 ConsoleModel.ConsoleModel.Events.CommandEvaluated, | 146 ConsoleModel.ConsoleModel.Events.CommandEvaluated, |
| 147 {result: result, text: requestedText, commandMessage: commandMessage
, exceptionDetails: exceptionDetails}); | 147 {result: result, text: requestedText, commandMessage: commandMessage
, exceptionDetails: exceptionDetails}); |
| 148 }); | 148 }); |
| 149 } | 149 } |
| 150 | 150 |
| 151 /** | 151 text = SDK.RuntimeModel.wrapObjectLiteralExpressionIfNeeded(text); |
| 152 * @param {string} code | |
| 153 * @suppress {uselessCode} | |
| 154 * @return {boolean} | |
| 155 */ | |
| 156 function looksLikeAnObjectLiteral(code) { | |
| 157 // Only parenthesize what appears to be an object literal. | |
| 158 if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code))) | |
| 159 return false; | |
| 160 | |
| 161 try { | |
| 162 // Check if the code can be interpreted as an expression. | |
| 163 Function('return ' + code + ';'); | |
| 164 | |
| 165 // No syntax error! Does it work parenthesized? | |
| 166 Function('(' + code + ')'); | |
| 167 | |
| 168 return true; | |
| 169 } catch (e) { | |
| 170 return false; | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 if (looksLikeAnObjectLiteral(text)) | |
| 175 text = '(' + text + ')'; | |
| 176 | |
| 177 executionContext.evaluate(text, 'console', useCommandLineAPI, false, false,
true, true, printResult.bind(this)); | 152 executionContext.evaluate(text, 'console', useCommandLineAPI, false, false,
true, true, printResult.bind(this)); |
| 178 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConsoleEvaluated); | 153 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConsoleEvaluated); |
| 179 } | 154 } |
| 180 | 155 |
| 181 /** | 156 /** |
| 182 * @param {!ConsoleModel.ConsoleMessage} msg | 157 * @param {!ConsoleModel.ConsoleMessage} msg |
| 183 */ | 158 */ |
| 184 addMessage(msg) { | 159 addMessage(msg) { |
| 185 if (msg.source === ConsoleModel.ConsoleMessage.MessageSource.Worker && SDK.t
argetManager.targetById(msg.workerId)) | 160 if (msg.source === ConsoleModel.ConsoleMessage.MessageSource.Worker && SDK.t
argetManager.targetById(msg.workerId)) |
| 186 return; | 161 return; |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 return 2; | 657 return 2; |
| 683 return 3; | 658 return 3; |
| 684 }; | 659 }; |
| 685 | 660 |
| 686 ConsoleModel.ConsoleModel._events = Symbol('ConsoleModel.ConsoleModel.events'); | 661 ConsoleModel.ConsoleModel._events = Symbol('ConsoleModel.ConsoleModel.events'); |
| 687 | 662 |
| 688 /** | 663 /** |
| 689 * @type {!ConsoleModel.ConsoleModel} | 664 * @type {!ConsoleModel.ConsoleModel} |
| 690 */ | 665 */ |
| 691 ConsoleModel.consoleModel; | 666 ConsoleModel.consoleModel; |
| OLD | NEW |