Changeset 52544 in webkit


Ignore:
Timestamp:
Dec 24, 2009 2:38:27 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2009-12-23 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.

Web Inspector: Console dumps strings in escaped form.

https://bugs.webkit.org/show_bug.cgi?id=32488

  • inspector/front-end/ConsoleView.js: (WebInspector.ConsoleMessage.prototype._formatIndividualValue):
  • inspector/console-format-expected.txt:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r52542 r52544  
     12009-12-23  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: Console dumps strings in escaped form.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=32488
     8
     9        * inspector/console-format-expected.txt:
     10
    1112009-12-23  Alexey Proskuryakov  <ap@apple.com>
    212
  • trunk/LayoutTests/inspector/console-format-expected.txt

    r51506 r52544  
    22CONSOLE MESSAGE: line 13: Message %s for %s
    33CONSOLE MESSAGE: line 14: Object %o
    4 CONSOLE MESSAGE: line 19: test,test2,,,test4
    5 CONSOLE MESSAGE: line 49: /^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i
    6 CONSOLE MESSAGE: line 50: /^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i
    7 CONSOLE MESSAGE: line 49: /foo\\bar\sbaz/i
    8 CONSOLE MESSAGE: line 50: /foo\\bar\sbaz/i
    9 CONSOLE MESSAGE: line 49: test
    10 CONSOLE MESSAGE: line 50: test
    11 CONSOLE MESSAGE: line 49: Error: Unknown error
    12 CONSOLE MESSAGE: line 50: Error: Unknown error
    13 CONSOLE MESSAGE: line 49: [object HTMLBodyElement]
    14 CONSOLE MESSAGE: line 50: [object HTMLBodyElement]
    15 CONSOLE MESSAGE: line 49: function () { return 1; }
    16 CONSOLE MESSAGE: line 50: function () { return 1; }
    17 CONSOLE MESSAGE: line 49: function () {
     4CONSOLE MESSAGE: line 20: test,test2,,,test4
     5CONSOLE MESSAGE: line 21: %o
     6CONSOLE MESSAGE: line 22: %O
     7CONSOLE MESSAGE: line 52: /^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i
     8CONSOLE MESSAGE: line 53: /^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i
     9CONSOLE MESSAGE: line 52: /foo\\bar\sbaz/i
     10CONSOLE MESSAGE: line 53: /foo\\bar\sbaz/i
     11CONSOLE MESSAGE: line 52: test
     12CONSOLE MESSAGE: line 53: test
     13CONSOLE MESSAGE: line 52: test named "test"
     14CONSOLE MESSAGE: line 53: test named "test"
     15CONSOLE MESSAGE: line 52: Error: Unknown error
     16CONSOLE MESSAGE: line 53: Error: Unknown error
     17CONSOLE MESSAGE: line 52: [object HTMLBodyElement]
     18CONSOLE MESSAGE: line 53: [object HTMLBodyElement]
     19CONSOLE MESSAGE: line 52: function () { return 1; }
     20CONSOLE MESSAGE: line 53: function () { return 1; }
     21CONSOLE MESSAGE: line 52: function () {
    1822        return 2;
    1923    }
    20 CONSOLE MESSAGE: line 50: function () {
     24CONSOLE MESSAGE: line 53: function () {
    2125        return 2;
    2226    }
    23 CONSOLE MESSAGE: line 49: 0.12
    24 CONSOLE MESSAGE: line 50: 0.12
    25 CONSOLE MESSAGE: line 49: http://webkit.org/
    26 CONSOLE MESSAGE: line 50: http://webkit.org/
    27 CONSOLE MESSAGE: line 49: null
    28 CONSOLE MESSAGE: line 50:
    29 CONSOLE MESSAGE: line 49: undefined
    30 CONSOLE MESSAGE: line 50:
     27CONSOLE MESSAGE: line 52: 0.12
     28CONSOLE MESSAGE: line 53: 0.12
     29CONSOLE MESSAGE: line 52: http://webkit.org/
     30CONSOLE MESSAGE: line 53: http://webkit.org/
     31CONSOLE MESSAGE: line 52: null
     32CONSOLE MESSAGE: line 53:
     33CONSOLE MESSAGE: line 52: undefined
     34CONSOLE MESSAGE: line 53:
    3135Tests that console logging dumps proper messages.
    3236
     
    3438console-format.html:13Message format for string
    3539console-format.html:14Object Object
    36 console-format.html:19["test", "test2", undefined, undefined, "test4"]
    37 console-format.html:49/^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i
    38 console-format.html:50[/^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i]
    39 "/^url\(\s*(?:(?:\"(?:[^\\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*\"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i"
    40 console-format.html:49/foo\\bar\sbaz/i
    41 console-format.html:50[/foo\\bar\sbaz/i]
     40console-format.html:20["test", "test2", undefined, undefined, "test4"]
     41console-format.html:21["test", "test2", undefined, undefined, "test4"]
     42console-format.html:22Array
     43console-format.html:52/^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i
     44console-format.html:53[/^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i]
     45"/^url\(\s*(?:(?:"(?:[^\\\"]|(?:\\[\da-f]{1,6}\s?|\.))*"|'(?:[^\\\']|(?:\\[\da-f]{1,6}\s?|\.))*')|(?:[!#$%&*-~\w]|(?:\\[\da-f]{1,6}\s?|\.))*)\s*\)/i"
     46console-format.html:52/foo\\bar\sbaz/i
     47console-format.html:53[/foo\\bar\sbaz/i]
    4248"/foo\\bar\sbaz/i"
    43 console-format.html:49test
    44 console-format.html:50["test"]
     49console-format.html:52test
     50console-format.html:53["test"]
    4551"test"
    46 console-format.html:49Error: Unknown error
    47 console-format.html:50[Error: Unknown error]
     52console-format.html:52test named "test"
     53console-format.html:53["test named "test""]
     54"test named "test""
     55console-format.html:52Error: Unknown error
     56console-format.html:53[Error: Unknown error]
    4857Error: Unknown error
    49 console-format.html:49<body onload="onload()">
    50 console-format.html:50[<body onload="onload()">]
     58console-format.html:52<body onload="onload()">
     59console-format.html:53[<body onload="onload()">]
    5160"HTMLBodyElement"
    52 console-format.html:49function () { return 1; }
    53 console-format.html:50[function () { return 1; }]
     61console-format.html:52function () { return 1; }
     62console-format.html:53[function () { return 1; }]
    5463"function () { return 1; }"
    55 console-format.html:49function () { return 2; }
    56 console-format.html:50[function () {]
     64console-format.html:52function () { return 2; }
     65console-format.html:53[function () { return 2; }]
    5766"function () {<br> return 2;<br> }"
    58 console-format.html:490.12
    59 console-format.html:50[0.12]
     67console-format.html:520.12
     68console-format.html:53[0.12]
    6069"0.12"
    61 console-format.html:49http://webkit.org/
    62 console-format.html:50["http://webkit.org/"]
     70console-format.html:52http://webkit.org/
     71console-format.html:53["http://webkit.org/"]
    6372"http://webkit.org/"
    64 console-format.html:49null
    65 console-format.html:50[null]
     73console-format.html:52null
     74console-format.html:53[null]
    6675"null"
    67 console-format.html:49undefined
    68 console-format.html:50[undefined]
     76console-format.html:52undefined
     77console-format.html:53[undefined]
    6978"undefined"
    7079
  • trunk/LayoutTests/inspector/console-format.html

    r51506 r52544  
    1515
    1616    var array = ["test", "test2"];
    17     array.foo = "bar";
     17    array.foo = "bar"; 
    1818    array[4] = "test4";
     19
    1920    console.log(array);
     21    console.log("%o", array);
     22    console.log("%O", array);
    2023
    2124    // Populate Globals
     
    2326    var regex2 = new RegExp("foo\\\\bar\\sbaz", "i");
    2427    var str = "test";
     28    var str2 = "test named \"test\"";
    2529    var error = new Error;
    2630    var node = document.body;
     
    3236    var linkify = "http://webkit.org/";
    3337
    34     globals = [regex1, regex2, str, error, node, func, multilinefunc, num, linkify, null, undefined];
     38    globals = [regex1, regex2, str, str2, error, node, func, multilinefunc, num, linkify, null, undefined];
    3539    loopOverGlobals(0);
    3640}
     
    4650            loopOverGlobals(next);
    4751    }
    48 
    4952    console.log(globals[current]);
    5053    console.log([globals[current]]);
  • trunk/WebCore/ChangeLog

    r52542 r52544  
     12009-12-23  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: Console dumps strings in escaped form.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=32488
     8
     9        * inspector/front-end/ConsoleView.js:
     10        (WebInspector.ConsoleMessage.prototype._formatIndividualValue):
     11
    1122009-12-23  Alexey Proskuryakov  <ap@apple.com>
    213
  • trunk/WebCore/inspector/InspectorController.cpp

    r52415 r52544  
    18731873}
    18741874
    1875 } // namespace WebCore
     1875}  // namespace WebCore
    18761876   
    18771877#endif // ENABLE(INSPECTOR)
  • trunk/WebCore/inspector/front-end/ConsoleView.js

    r52217 r52544  
    110110        "object": this._formatobject,
    111111        "array":  this._formatarray,
    112         "node":   this._formatnode
     112        "node":   this._formatnode,
     113        "string": this._formatstring
    113114    };
    114115}
     
    497498            formatter = this._formatvalue;
    498499            output = output.description || output;
    499             type = "undecorated";
    500500        }
    501501
     
    536536    _formatarray: function(arr, elem)
    537537    {
    538         InjectedScriptAccess.getProperties(arr, false, this._printArray.bind(this, elem));
     538        InjectedScriptAccess.getProperties(arr, false, false, this._printArray.bind(this, elem));
     539    },
     540
     541    _formatstring: function(output, elem)
     542    {
     543        var span = document.createElement("span");
     544        span.className = "console-formatted-string source-code";
     545        span.appendChild(WebInspector.linkifyStringAsFragment(output.description));
     546
     547        // Make black quotes.
     548        elem.removeStyleClass("console-formatted-string");
     549        elem.appendChild(document.createTextNode("\""));
     550        elem.appendChild(span);
     551        elem.appendChild(document.createTextNode("\""));
    539552    },
    540553
     
    627640                parameters[i] = WebInspector.ObjectProxy.wrapPrimitiveValue(parameters[i]);
    628641
     642        // There can be string log and string eval result. We distinguish between them based on message type.
     643        var shouldFormatMessage = Object.proxyType(parameters[0]) === "string" && this.type !== WebInspector.ConsoleMessage.MessageType.Result;
     644
    629645        // Multiple parameters with the first being a format string. Save unused substitutions.
    630         if (parameters.length > 1 && Object.proxyType(parameters[0]) === "string") {
    631             var result = this._formatWithSubstitutionString(parameters, formattedResult)
     646        if (shouldFormatMessage) {
     647            // Multiple parameters with the first being a format string. Save unused substitutions.
     648            var result = this._formatWithSubstitutionString(parameters, formattedResult);
    632649            parameters = result.unusedSubstitutions;
    633650            if (parameters.length)
     
    637654        // Single parameter, or unused substitutions from above.
    638655        for (var i = 0; i < parameters.length; ++i) {
    639             this._formatIndividualValue(parameters[i], formattedResult);
     656            // Inline strings when formatting.
     657            if (shouldFormatMessage && parameters[i].type === "string")
     658                formattedResult.appendChild(document.createTextNode(parameters[i].description));
     659            else
     660                formattedResult.appendChild(WebInspector.console._format(parameters[i]));
    640661            if (i < parameters.length - 1)
    641662                formattedResult.appendChild(document.createTextNode(" "));
    642663        }
    643 
    644664        return formattedResult;
    645665    },
     
    678698    },
    679699
    680     _formatIndividualValue: function(param, formattedResult)
    681     {
    682         if (Object.proxyType(param) === "string") {
    683             if (this.originatingCommand && this.level === WebInspector.ConsoleMessage.MessageLevel.Log) {
    684                 var quotedString = "\"" + param.description.replace(/"/g, "\\\"") + "\"";
    685                 formattedResult.appendChild(WebInspector.linkifyStringAsFragment(quotedString));
    686             } else
    687                 formattedResult.appendChild(WebInspector.linkifyStringAsFragment(param.description));
    688         } else
    689             formattedResult.appendChild(WebInspector.console._format(param));
    690     },
    691 
    692700    toMessageElement: function()
    693701    {
     
    833841            case WebInspector.ConsoleMessage.MessageType.Assert:
    834842                typeString = "Assert";
     843                break;
     844            case WebInspector.ConsoleMessage.MessageType.Result:
     845                typeString = "Result";
    835846                break;
    836847        }
     
    890901    StartGroup: 3,
    891902    EndGroup: 4,
    892     Assert: 5
     903    Assert: 5,
     904    Result: 6
    893905}
    894906
     
    934946    var level = (exception ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log);
    935947    var message = result;
     948    if (exception) {
     949        // Distinguish between strings and errors (no need to quote latter).
     950        message = WebInspector.ObjectProxy.wrapPrimitiveValue(result);
     951        message.type = "error";
     952    }
    936953    var line = (exception ? result.line : -1);
    937954    var url = (exception ? result.sourceURL : null);
     
    939956    this.originatingCommand = originatingCommand;
    940957
    941     WebInspector.ConsoleMessage.call(this, WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageType.Log, level, line, url, null, 1, message);
     958    WebInspector.ConsoleMessage.call(this, WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageType.Result, level, line, url, null, 1, message);
    942959}
    943960
  • trunk/WebCore/inspector/front-end/InjectedScript.js

    r52108 r52544  
    443443}
    444444
    445 InjectedScript.getProperties = function(objectProxy, ignoreHasOwnProperty)
     445InjectedScript.getProperties = function(objectProxy, ignoreHasOwnProperty, abbreviate)
    446446{
    447447    var object = InjectedScript._resolveObject(objectProxy);
     
    462462        if (!property.isGetter) {
    463463            var childObject = object[propertyName];
    464             var childObjectProxy = new InjectedScript.createProxyObject(childObject, objectProxy.objectId, true);
     464            var childObjectProxy = new InjectedScript.createProxyObject(childObject, objectProxy.objectId, abbreviate);
    465465            childObjectProxy.path = objectProxy.path ? objectProxy.path.slice() : [];
    466466            childObjectProxy.path.push(propertyName);
  • trunk/WebCore/inspector/front-end/ObjectPropertiesSection.js

    r51946 r52544  
    5151            self.updateProperties(properties);
    5252        };
    53         InjectedScriptAccess.getProperties(this.object, this.ignoreHasOwnProperty, callback);
     53        InjectedScriptAccess.getProperties(this.object, this.ignoreHasOwnProperty, true, callback);
    5454    },
    5555
     
    148148            }
    149149        };
    150         InjectedScriptAccess.getProperties(this.property.value, false, callback.bind(this));
     150        InjectedScriptAccess.getProperties(this.property.value, false, true, callback.bind(this));
    151151    },
    152152
  • trunk/WebCore/inspector/front-end/ObjectProxy.js

    r51420 r52544  
    6161        callback(result);
    6262    };
    63     InjectedScriptAccess.getProperties(objectProxy, true, createPropertiesMapThenCallback);
     63    InjectedScriptAccess.getProperties(objectProxy, true, false, createPropertiesMapThenCallback);
    6464}
    6565
  • trunk/WebCore/inspector/front-end/inspector.css

    r52427 r52544  
    721721}
    722722
     723.console-formatted-number {
     724    color: rgb(28, 0, 207);
     725}
     726
     727.console-formatted-string, .console-formatted-regexp {
     728    color: rgb(196, 26, 22);
     729}
     730
     731.console-formatted-null, .console-formatted-undefined {
     732    color: rgb(128, 128, 128);
     733}
     734
    723735.error-message {
    724736    color: red;
Note: See TracChangeset for help on using the changeset viewer.