Changeset 41404 in webkit


Ignore:
Timestamp:
Mar 3, 2009 2:24:14 PM (15 years ago)
Author:
timothy@apple.com
Message:

Fix a regression that broke dirxml and caused an ASSERT in debug builds. Also simplified
the console code and refactored things to have fewer code paths and duplication.

Reviewed by Kevin McCullough.

Test: manual-tests/inspector/console-dir.html

  • bindings/js/JSInspectedObjectWrapper.cpp: (WebCore::JSInspectedObjectWrapper::wrap): Use the lexicalGlobalObject instead of dynamicGlobalObject to fix an ASSERT about using a wrapper from the wrong ExecState.
  • bindings/js/JSQuarantinedObjectWrapper.cpp: (WebCore::JSQuarantinedObjectWrapper::JSQuarantinedObjectWrapper): Ditto. (WebCore::JSQuarantinedObjectWrapper::allowsUnwrappedAccessFrom): Ditto.
  • inspector/front-end/Console.js: (WebInspector.Console.prototype._format): Remove the inline argument and add forceObjectFormat. When forceObjectFormat is true, the only formatter used is _formatobject. (WebInspector.Console.prototype._formatvalue): Remove the inline argument. (WebInspector.Console.prototype._formatstring): Ditto. (WebInspector.Console.prototype._formatregexp): Ditto. (WebInspector.Console.prototype._formatarray): Ditto. (WebInspector.Console.prototype._formatnode): Remove the inline argument and make a DOM tree instead of an anchor. (WebInspector.Console.prototype._formatobject): Remove the inline argument and always make a property graph. (WebInspector.Console.prototype._formaterror): Remove the inline argument. (WebInspector.ConsoleMessage): Remove the case for MessageLevel.Node and simplify the case for MessageLevel.Object to use the normal _format code path with the %O formatter. (WebInspector.ConsoleMessage.prototype._format.formatForConsole): Don't pass an additional true argument for inline. (WebInspector.ConsoleMessage.prototype._format.formatAsObjectForConsole): Added. Pass a true argument for forceObjectFormat. (WebInspector.ConsoleMessage.prototype._format): Added support for the %O formatter. Use formatForConsole for all arguments. (WebInspector.ConsoleMessage.prototype.toString): Add the other message levels.
  • inspector/front-end/inspector.css: Tweak styles to look and work correctly.
  • inspector/front-end/utilities.js: (Object.type): Return "node" for Node objects. (Object.describe): Handle the "node" type.
  • page/Console.cpp: (WebCore::printMessageSourceAndLevelPrefix): Fix an assert by adding the other message level types. (WebCore::Console::dirxml): Use the standard log fuction since it prints a DOM tree for nodes by default.
  • page/Console.h: (WebCore::enum MessageLevel): Removed NodeMessageLevel. Added a FIXME.
Location:
trunk/WebCore
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r41403 r41404  
     12009-03-03  Timothy Hatcher  <timothy@apple.com>
     2
     3        Fix a regression that broke dirxml and caused an ASSERT in debug builds. Also simplified
     4        the console code and refactored things to have fewer code paths and duplication.
     5
     6        Reviewed by Kevin McCullough.
     7
     8        Test: manual-tests/inspector/console-dir.html
     9
     10        * bindings/js/JSInspectedObjectWrapper.cpp:
     11        (WebCore::JSInspectedObjectWrapper::wrap): Use the lexicalGlobalObject instead of dynamicGlobalObject
     12        to fix an ASSERT about using a wrapper from the wrong ExecState.
     13        * bindings/js/JSQuarantinedObjectWrapper.cpp:
     14        (WebCore::JSQuarantinedObjectWrapper::JSQuarantinedObjectWrapper): Ditto.
     15        (WebCore::JSQuarantinedObjectWrapper::allowsUnwrappedAccessFrom): Ditto.
     16        * inspector/front-end/Console.js:
     17        (WebInspector.Console.prototype._format): Remove the inline argument and add forceObjectFormat.
     18        When forceObjectFormat is true, the only formatter used is _formatobject.
     19        (WebInspector.Console.prototype._formatvalue): Remove the inline argument.
     20        (WebInspector.Console.prototype._formatstring): Ditto.
     21        (WebInspector.Console.prototype._formatregexp): Ditto.
     22        (WebInspector.Console.prototype._formatarray): Ditto.
     23        (WebInspector.Console.prototype._formatnode): Remove the inline argument and make a DOM tree instead of an anchor.
     24        (WebInspector.Console.prototype._formatobject): Remove the inline argument and always make a property graph.
     25        (WebInspector.Console.prototype._formaterror): Remove the inline argument.
     26        (WebInspector.ConsoleMessage): Remove the case for MessageLevel.Node and
     27        simplify the case for MessageLevel.Object to use the normal _format code path with the %O formatter.
     28        (WebInspector.ConsoleMessage.prototype._format.formatForConsole): Don't pass an additional true argument for inline.
     29        (WebInspector.ConsoleMessage.prototype._format.formatAsObjectForConsole): Added. Pass a true argument for forceObjectFormat.
     30        (WebInspector.ConsoleMessage.prototype._format): Added support for the %O formatter. Use formatForConsole for all arguments.
     31        (WebInspector.ConsoleMessage.prototype.toString): Add the other message levels.
     32        * inspector/front-end/inspector.css: Tweak styles to look and work correctly.
     33        * inspector/front-end/utilities.js:
     34        (Object.type): Return "node" for Node objects.
     35        (Object.describe): Handle the "node" type.
     36        * page/Console.cpp:
     37        (WebCore::printMessageSourceAndLevelPrefix): Fix an assert by adding the other message level types.
     38        (WebCore::Console::dirxml): Use the standard log fuction since it prints a DOM tree for nodes by default.
     39        * page/Console.h:
     40        (WebCore::enum MessageLevel): Removed NodeMessageLevel. Added a FIXME.
     41
    1422009-03-03  Scott Violet  <sky@google.com>
    243
  • trunk/WebCore/bindings/js/JSInspectedObjectWrapper.cpp

    r40046 r41404  
    5858        return unwrappedObject;
    5959
    60     if (WrapperMap* wrapperMap = wrappers().get(unwrappedExec->dynamicGlobalObject()))
     60    if (WrapperMap* wrapperMap = wrappers().get(unwrappedExec->lexicalGlobalObject()))
    6161        if (JSInspectedObjectWrapper* wrapper = wrapperMap->get(unwrappedObject))
    6262            return wrapper;
  • trunk/WebCore/bindings/js/JSQuarantinedObjectWrapper.cpp

    r41353 r41404  
    5959JSQuarantinedObjectWrapper::JSQuarantinedObjectWrapper(ExecState* unwrappedExec, JSObject* unwrappedObject, PassRefPtr<Structure> structure)
    6060    : JSObject(structure)
    61     , m_unwrappedGlobalObject(unwrappedExec->dynamicGlobalObject())
     61    , m_unwrappedGlobalObject(unwrappedExec->lexicalGlobalObject())
    6262    , m_unwrappedObject(unwrappedObject)
    6363{
     
    7373bool JSQuarantinedObjectWrapper::allowsUnwrappedAccessFrom(ExecState* exec) const
    7474{
    75     return m_unwrappedGlobalObject->profileGroup() == exec->dynamicGlobalObject()->profileGroup();
     75    return m_unwrappedGlobalObject->profileGroup() == exec->lexicalGlobalObject()->profileGroup();
    7676}
    7777
  • trunk/WebCore/inspector/front-end/Console.js

    r41365 r41404  
    466466    },
    467467
    468     _mouseOverNode: function(event)
    469     {
    470         var anchorElement = event.target.enclosingNodeOrSelfWithNodeName("a");
    471         WebInspector.hoveredDOMNode = (anchorElement ? anchorElement.representedNode : null);
    472     },
    473 
    474     _mouseOutOfNode: function(event)
    475     {
    476         var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
    477         var anchorElement = nodeUnderMouse.enclosingNodeOrSelfWithNodeName("a");
    478         if (!anchorElement || !anchorElement.representedNode)
    479             WebInspector.hoveredDOMNode = null;
    480     },
    481 
    482     _format: function(output, inline)
    483     {
    484         var type = Object.type(output, InspectorController.inspectedWindow());
    485         if (type === "object") {
    486             if (output instanceof InspectorController.inspectedWindow().Node)
    487                 type = "node";
    488         }
     468    _format: function(output, forceObjectFormat)
     469    {
     470        var type = (forceObjectFormat ? "object" : Object.type(output, InspectorController.inspectedWindow()));
    489471
    490472        // We don't perform any special formatting on these types, so we just
     
    500482
    501483        var formatter;
    502         if (type in undecoratedTypes)
     484        if (forceObjectFormat)
     485            formatter = "_formatobject";
     486        else if (type in undecoratedTypes)
    503487            formatter = "_formatvalue";
    504488        else {
     
    512496        var span = document.createElement("span");
    513497        span.addStyleClass("console-formatted-" + type);
    514         this[formatter](output, span, inline);
     498        this[formatter](output, span);
    515499        return span;
    516500    },
    517501
    518     _formatvalue: function(val, elem, inline)
     502    _formatvalue: function(val, elem)
    519503    {
    520504        elem.appendChild(document.createTextNode(val));
    521505    },
    522506
    523     _formatstring: function(str, elem, inline)
     507    _formatstring: function(str, elem)
    524508    {
    525509        elem.appendChild(document.createTextNode("\"" + str + "\""));
    526510    },
    527511
    528     _formatregexp: function(re, elem, inline)
     512    _formatregexp: function(re, elem)
    529513    {
    530514        var formatted = String(re).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/, "$1").substring(1);
     
    532516    },
    533517
    534     _formatarray: function(arr, elem, inline)
     518    _formatarray: function(arr, elem)
    535519    {
    536520        elem.appendChild(document.createTextNode("["));
    537521        for (var i = 0; i < arr.length; ++i) {
    538             elem.appendChild(this._format(arr[i], true));
     522            elem.appendChild(this._format(arr[i]));
    539523            if (i < arr.length - 1)
    540524                elem.appendChild(document.createTextNode(", "));
     
    543527    },
    544528
    545     _formatnode: function(node, elem, inline)
    546     {
    547         var anchor = document.createElement("a");
    548         anchor.className = "inspectable-node";
    549         anchor.innerHTML = nodeTitleInfo.call(node).title;
    550         anchor.representedNode = node;
    551         anchor.addEventListener("mouseover", this._mouseOverNode.bind(this), false);
    552         anchor.addEventListener("mouseout", this._mouseOutOfNode.bind(this), false);
    553 
    554         if (inline)
    555             elem.appendChild(anchor);
    556         else
    557             elem.appendChild(new WebInspector.ObjectPropertiesSection(node, anchor, null, null, true).element);
    558     },
    559 
    560     _formatobject: function(obj, elem, inline)
    561     {
    562         if (inline)
    563             elem.appendChild(document.createTextNode(Object.describe(obj)));
    564         else
    565             elem.appendChild(new WebInspector.ObjectPropertiesSection(obj, null, null, null, true).element);
    566     },
    567 
    568     _formaterror: function(obj, elem, inline)
     529    _formatnode: function(node, elem)
     530    {
     531        var treeOutline = new WebInspector.ElementsTreeOutline();
     532        treeOutline.rootDOMNode = node;
     533        treeOutline.element.addStyleClass("outline-disclosure");
     534        if (!treeOutline.children[0].hasChildren)
     535            treeOutline.element.addStyleClass("single-node");
     536        elem.appendChild(treeOutline.element);
     537    },
     538
     539    _formatobject: function(obj, elem)
     540    {
     541        elem.appendChild(new WebInspector.ObjectPropertiesSection(obj, null, null, null, true).element);
     542    },
     543
     544    _formaterror: function(obj, elem)
    569545    {
    570546        var messageElement = document.createElement("span");
     
    604580
    605581    switch (this.level) {
    606         case WebInspector.ConsoleMessage.MessageLevel.Object:
    607             var propertiesSection = new WebInspector.ObjectPropertiesSection(arguments[6], null, null, null, true);
    608             propertiesSection.element.addStyleClass("console-message");
    609             this.propertiesSection = propertiesSection;
    610             break;
    611         case WebInspector.ConsoleMessage.MessageLevel.Node:
    612             var node = arguments[6];
    613             if (!(node instanceof InspectorController.inspectedWindow().Node))
    614                 return;
    615             this.elementsTreeOutline = new WebInspector.ElementsTreeOutline();
    616             this.elementsTreeOutline.rootDOMNode = node;
    617             break;
    618582        case WebInspector.ConsoleMessage.MessageLevel.Trace:
    619583            var span = document.createElement("span");
     
    626590            this.formattedMessage = span;
    627591            break;
     592        case WebInspector.ConsoleMessage.MessageLevel.Object:
     593            this.formattedMessage = this._format(["%O", arguments[6]]);
     594            break;
    628595        default:
    629             // The formatedMessage property is used for the rich and interactive console.
    630596            this.formattedMessage = this._format(Array.prototype.slice.call(arguments, 6));
    631 
    632             // This is used for inline message bubbles in SourceFrames, or other plain-text representations.
    633             this.message = this.formattedMessage.textContent;
    634597            break;
    635598    }
     599
     600    // This is used for inline message bubbles in SourceFrames, or other plain-text representations.
     601    this.message = this.formattedMessage.textContent;
    636602}
    637603
     
    650616
    651617        function formatForConsole(obj)
     618        {
     619            return WebInspector.console._format(obj);
     620        }
     621
     622        function formatAsObjectForConsole(obj)
    652623        {
    653624            return WebInspector.console._format(obj, true);
     
    663634            // Firebug allows both %i and %d for formatting integers.
    664635            formatters.i = formatters.d;
     636            // Support %O to force object formating, instead of the type-based %o formatting.
     637            formatters.O = formatAsObjectForConsole;
    665638
    666639            function append(a, b)
     
    683656            if (typeof parameters[i] === "string")
    684657                formattedResult.appendChild(WebInspector.linkifyStringAsFragment(parameters[i]));
    685             else if (parameters.length === 1)
    686                 formattedResult.appendChild(WebInspector.console._format(parameters[0]));
    687658            else
    688659                formattedResult.appendChild(formatForConsole(parameters[i]));
     660
    689661            if (i < parameters.length - 1)
    690662                formattedResult.appendChild(document.createTextNode(" "));
     
    822794                levelString = "Object";
    823795                break;
    824             case WebInspector.ConsoleMessage.MessageLevel.GroupTitle:
    825                 levelString = "GroupTitle";
     796            case WebInspector.ConsoleMessage.MessageLevel.Trace:
     797                levelString = "Trace";
     798                break;
     799            case WebInspector.ConsoleMessage.MessageLevel.StartGroup:
     800                levelString = "Start Group";
     801                break;
     802            case WebInspector.ConsoleMessage.MessageLevel.EndGroup:
     803                levelString = "End Group";
    826804                break;
    827805        }
     
    829807        return sourceString + " " + levelString + ": " + this.formattedMessage.textContent + "\n" + this.url + " line " + this.line;
    830808    },
    831    
     809
    832810    isEqual: function(msg, disreguardGroup)
    833811    {
     
    861839    Error: 3,
    862840    Object: 4,
    863     Node: 5,
    864     Trace: 6,
    865     StartGroup: 7,
    866     EndGroup: 8
     841    Trace: 5,
     842    StartGroup: 6,
     843    EndGroup: 7
    867844}
    868845
  • trunk/WebCore/inspector/front-end/inspector.css

    r41364 r41404  
    416416    display: none;
    417417    position: absolute;
     418    z-index: 1;
    418419    bottom: 0;
    419420    left: 0;
     
    613614.console-group-messages .section .header .title {
    614615    color: black;
     616    font-weight: normal;
     617}
     618
     619.console-group-messages .section .properties li .info {
     620    padding-top: 0;
     621    padding-bottom: 0;
     622    color: rgb(60%, 60%, 60%);
     623}
     624
     625.console-group-messages .outline-disclosure {
     626    padding-left: 0;
     627}
     628
     629.console-group-messages .outline-disclosure > ol {
     630    padding: 0 0 0 12px !important;
    615631}
    616632
     
    620636}
    621637
    622 .console-group-messages .outline-disclosure li {
    623     padding-top: 2px;
    624     padding-bottom: 2px;
     638.console-group-messages .outline-disclosure.single-node li {
     639    padding-left: 2px;
    625640}
    626641
    627642.console-group-messages .outline-disclosure li .selection {
    628     z-index: 0;
    629     margin-top: -1px;
     643    margin-left: -6px;
     644    margin-right: -6px;
    630645}
    631646
    632647.console-formatted-object, .console-formatted-node {
    633648    position: relative;
    634     display: block;
     649    display: inline-block;
     650    vertical-align: top;
    635651}
    636652
     
    651667    -webkit-user-select: none;
    652668    -webkit-user-modify: read-only;
    653 }
    654 
    655 .inspectable-node {
    656     color: black !important;
    657 }
    658 
    659 .inspectable-node:hover {
    660     background-color: rgba(56, 121, 217, 0.1);
    661     -webkit-border-radius: 5px;
    662     padding: 0 5px 1px;
    663     margin: 0 -5px -1px;
    664669}
    665670
  • trunk/WebCore/inspector/front-end/utilities.js

    r41335 r41404  
    3838    win = win || window;
    3939
     40    if (obj instanceof win.Node)
     41        return "node";
    4042    if (obj instanceof win.String)
    4143        return "string";
     
    7173    switch (type1) {
    7274    case "object":
     75    case "node":
    7376        return type2;
    7477    case "array":
  • trunk/WebCore/page/Console.cpp

    r39177 r41404  
    100100            sourceString = "CSS";
    101101            break;
     102        case OtherMessageSource:
     103            sourceString = "OTHER";
     104            break;
    102105        default:
    103106            ASSERT_NOT_REACHED();
    104             // Fall thru.
    105         case OtherMessageSource:
    106             sourceString = "OTHER";
     107            sourceString = "UNKNOWN";
    107108            break;
    108109    }
     
    113114            levelString = "TIP";
    114115            break;
     116        case LogMessageLevel:
     117            levelString = "LOG";
     118            break;
     119        case WarningMessageLevel:
     120            levelString = "WARN";
     121            break;
     122        case ErrorMessageLevel:
     123            levelString = "ERROR";
     124            break;
     125        case ObjectMessageLevel:
     126            levelString = "OBJECT";
     127            break;
     128        case TraceMessageLevel:
     129            levelString = "TRACE";
     130            break;
     131        case StartGroupMessageLevel:
     132            levelString = "START GROUP";
     133            break;
     134        case EndGroupMessageLevel:
     135            levelString = "END GROUP";
     136            break;
    115137        default:
    116138            ASSERT_NOT_REACHED();
    117             // Fall thru.
    118         case LogMessageLevel:
    119             levelString = "LOG";
    120             break;
    121         case WarningMessageLevel:
    122             levelString = "WARN";
    123             break;
    124         case ErrorMessageLevel:
    125             levelString = "ERROR";
     139            levelString = "UNKNOWN";
    126140            break;
    127141    }
     
    208222void Console::dirxml(ScriptCallStack* callStack)
    209223{
    210     addMessage(NodeMessageLevel, callStack);
     224    // The standard behavior of our console.log will print the DOM tree for nodes.
     225    log(callStack);
    211226}
    212227
  • trunk/WebCore/page/Console.h

    r39142 r41404  
    6565        WarningMessageLevel,
    6666        ErrorMessageLevel,
     67        // FIXME: the remaining levels should become a new MessageType enum.
    6768        ObjectMessageLevel,
    68         NodeMessageLevel,
    6969        TraceMessageLevel,
    7070        StartGroupMessageLevel,
Note: See TracChangeset for help on using the changeset viewer.