Changeset 30146 in webkit


Ignore:
Timestamp:
Feb 11, 2008 11:58:18 AM (16 years ago)
Author:
Adam Roben
Message:

Fix Bug 14316: Inspector's Console truncates long strings

<http://bugs.webkit.org/show_bug.cgi?id=14316>
<rdar://5357695>

We no longer call Object.describe to format all the output of commands
enetered into the Console. The ConsolePanel object now has a set of
formatting functions that append a formatted representation of the
passed-in object to the passed-in container node.

Reviewed by Sam.

  • page/inspector/ConsolePanel.js: (WebInspector.ConsolePanel._onEnterPressed): Updated for rename of _outputToNode to _format. (WebInspector.ConsolePanel._format): Renamed from _outputToNode. Use Object.type to get the type of the object, then call the appropriate formatting function. (WebInspector.ConsolePanel._formatvalue): Added. (WebInspector.ConsolePanel._formatstring): Added. This function contains the actual fix for the bug, since it doesn't truncate the string no matter how long it is. (WebInspector.ConsolePanel._formatregexp): Added. (WebInspector.ConsolePanel._formatarray): Added. This is a bit more functional than Object.describe for arrays, since it recursively formats each item in the array. One advantage of this is that Nodes in arrays will be linkified instead of just turning into "[Object HTMLBodyElement]" or similar. (WebInspector.ConsolePanel._formatnode): Added. (WebInspector.ConsolePanel._formatobject): Added. (WebInspector.ConsolePanel.
  • page/inspector/utilities.js: (Object.type): Added. Code was pulled out of Object.describe and reorganized slightly. (Object.describe): Call Object.type. There should be no change in behavior of this function.
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r30145 r30146  
     12008-02-11  Adam Roben  <aroben@apple.com>
     2
     3        Fix Bug 14316: Inspector's Console truncates long strings
     4
     5        <http://bugs.webkit.org/show_bug.cgi?id=14316>
     6        <rdar://5357695>
     7
     8        We no longer call Object.describe to format all the output of commands
     9        enetered into the Console. The ConsolePanel object now has a set of
     10        formatting functions that append a formatted representation of the
     11        passed-in object to the passed-in container node.
     12
     13        Reviewed by Sam.
     14
     15        * page/inspector/ConsolePanel.js:
     16        (WebInspector.ConsolePanel._onEnterPressed): Updated for rename of
     17        _outputToNode to _format.
     18        (WebInspector.ConsolePanel._format): Renamed from _outputToNode. Use
     19        Object.type to get the type of the object, then call the appropriate
     20        formatting function.
     21        (WebInspector.ConsolePanel._formatvalue): Added.
     22        (WebInspector.ConsolePanel._formatstring): Added. This function
     23        contains the actual fix for the bug, since it doesn't truncate the
     24        string no matter how long it is.
     25        (WebInspector.ConsolePanel._formatregexp): Added.
     26        (WebInspector.ConsolePanel._formatarray): Added. This is a bit more
     27        functional than Object.describe for arrays, since it recursively
     28        formats each item in the array. One advantage of this is that Nodes in
     29        arrays will be linkified instead of just turning into "[Object
     30        HTMLBodyElement]" or similar.
     31        (WebInspector.ConsolePanel._formatnode): Added.
     32        (WebInspector.ConsolePanel._formatobject): Added.
     33        (WebInspector.ConsolePanel.
     34        * page/inspector/utilities.js:
     35        (Object.type): Added. Code was pulled out of Object.describe and
     36        reorganized slightly.
     37        (Object.describe): Call Object.type. There should be no change in
     38        behavior of this function.
     39
    1402008-02-11  Alp Toker  <alp@atoker.com>
    241
  • trunk/WebCore/page/inspector/ConsolePanel.js

    r28918 r30146  
    184184        var level = exception ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log;
    185185
    186         this.addMessage(new WebInspector.ConsoleCommand(str, this._outputToNode(result)));
     186        this.addMessage(new WebInspector.ConsoleCommand(str, this._format(result)));
    187187    },
    188188
     
    224224    },
    225225
    226     _outputToNode: function(output)
    227     {
    228         if (output instanceof Node) {
    229             var anchor = document.createElement("a");
    230             anchor.innerHTML = output.titleInfo().title;
    231             anchor.representedNode = output;
    232             return anchor;
    233         }
    234         return document.createTextNode(Object.describe(output));
    235     }
     226    _format: function(output)
     227    {
     228        var type = Object.type(output);
     229        if (type === "object") {
     230            if (output instanceof Node)
     231                type = "node";
     232        }
     233
     234        // We don't perform any special formatting on these types, so we just
     235        // pass them through the simple _formatvalue function.
     236        var undecoratedTypes = {
     237            "undefined": 1,
     238            "null": 1,
     239            "boolean": 1,
     240            "number": 1,
     241            "date": 1,
     242            "function": 1,
     243        };
     244
     245        var formatter;
     246        if (type in undecoratedTypes)
     247            formatter = "_formatvalue";
     248        else {
     249            formatter = "_format" + type;
     250            if (!(formatter in this)) {
     251                formatter = "_formatobject";
     252                type = "object";
     253            }
     254        }
     255
     256        var span = document.createElement("span");
     257        span.addStyleClass("console-formatted-" + type);
     258        this[formatter](output, span);
     259        return span;
     260    },
     261
     262    _formatvalue: function(val, elem)
     263    {
     264        elem.appendChild(document.createTextNode(val));
     265    },
     266
     267    _formatstring: function(str, elem)
     268    {
     269        elem.appendChild(document.createTextNode("\"" + str + "\""));
     270    },
     271
     272    _formatregexp: function(re, elem)
     273    {
     274        var formatted = String(re).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/, "$1").substring(1);
     275        elem.appendChild(document.createTextNode(formatted));
     276    },
     277
     278    _formatarray: function(arr, elem)
     279    {
     280        elem.appendChild(document.createTextNode("["));
     281        for (var i = 0; i < arr.length; ++i) {
     282            elem.appendChild(this._format(arr[i]));
     283            if (i < arr.length - 1)
     284                elem.appendChild(document.createTextNode(", "));
     285        }
     286        elem.appendChild(document.createTextNode("]"));
     287    },
     288
     289    _formatnode: function(node, elem)
     290    {
     291        var anchor = document.createElement("a");
     292        anchor.innerHTML = node.titleInfo().title;
     293        anchor.representedNode = node;
     294        elem.appendChild(anchor);
     295    },
     296
     297    _formatobject: function(obj, elem)
     298    {
     299        elem.appendChild(document.createTextNode(Object.describe(obj)));
     300    },
    236301}
    237302
  • trunk/WebCore/page/inspector/utilities.js

    r28004 r30146  
    2727 */
    2828
    29 Object.describe = function(obj, abbreviated)
    30 {
    31     if (obj === undefined)
    32         return "undefined";
     29Object.type = function(obj)
     30{
    3331    if (obj === null)
    3432        return "null";
    3533
    36     var type1 = typeof obj;
    37     var type2 = "";
    38     if (type1 == "object" || type1 == "function") {
    39         if (obj instanceof String)
    40             type1 = "string";
    41         else if (obj instanceof Array)
    42             type1 = "array";
    43         else if (obj instanceof Boolean)
    44             type1 = "boolean";
    45         else if (obj instanceof Number)
    46             type1 = "number";
    47         else if (obj instanceof Date)
    48             type1 = "date";
    49         else if (obj instanceof RegExp)
    50             type1 = "regexp";
    51         else if (obj instanceof Error)
    52             type1 = "error";
    53         type2 = Object.prototype.toString.call(obj).replace(/^\[object (.*)\]$/i, "$1");
    54     }
    55 
    56     switch (type1) {
     34    var type = typeof obj;
     35    if (type !== "object" && type !== "function")
     36        return type;
     37
     38    if (obj instanceof String)
     39        return "string";
     40    if (obj instanceof Array)
     41        return "array";
     42    if (obj instanceof Boolean)
     43        return "boolean";
     44    if (obj instanceof Number)
     45        return "number";
     46    if (obj instanceof Date)
     47        return "date";
     48    if (obj instanceof RegExp)
     49        return "regexp";
     50    if (obj instanceof Error)
     51        return "error";
     52    return type;
     53}
     54
     55Object.describe = function(obj, abbreviated)
     56{
     57    switch (Object.type(obj)) {
    5758    case "object":
    58         return type2;
     59        return Object.prototype.toString.call(obj).replace(/^\[object (.*)\]$/i, "$1");
    5960    case "array":
    6061        return "[" + obj.toString() + "]";
Note: See TracChangeset for help on using the changeset viewer.