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

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/RuntimeModel.js

Issue 2800573002: DevTools: editing property values should wrap object literals similar to console (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/RuntimeModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/RuntimeModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/RuntimeModel.js
index a6da9eb7ee813e98eefcccc42fcc39687ba2a142..61757727e9de09d930a791a71f7517190cdd1af7 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/RuntimeModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/RuntimeModel.js
@@ -52,6 +52,29 @@ SDK.RuntimeModel = class extends SDK.SDKModel {
}
/**
+ * @param {string} code
+ * @return {string}
+ */
+ static wrapObjectLiteralExpressionIfNeeded(code) {
+ // Only parenthesize what appears to be an object literal.
+ if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code)))
+ return code;
+
+ try {
+ // Check if the code can be interpreted as an expression.
+ Function('return ' + code + ';');
+
+ // No syntax error! Does it work parenthesized?
+ var wrappedCode = '(' + code + ')';
+ Function(wrappedCode);
+
+ return wrappedCode;
+ } catch (e) {
+ return code;
+ }
+ }
+
+ /**
* @return {!SDK.DebuggerModel}
*/
debuggerModel() {

Powered by Google App Engine
This is Rietveld 408576698