B2G/gecko/browser/devtools/webconsole/webconsole.js
/**
   * Given a category and message body, creates a DOM node to represent an
   * incoming message. The timestamp is automatically added.
   *
   * @param number aCategory
   *        The category of the message: one of the CATEGORY_* constants.
   * @param number aSeverity
   *        The severity of the message: one of the SEVERITY_* constants;
   * @param string|nsIDOMNode aBody
   *        The body of the message, either a simple string or a DOM node.
   * @param string aSourceURL [optional]
   *        The URL of the source file that emitted the error.
   * @param number aSourceLine [optional]
   *        The line number on which the error occurred. If zero or omitted,
   *        there is no line number associated with this message.
   * @param string aClipboardText [optional]
   *        The text that should be copied to the clipboard when this node is
   *        copied. If omitted, defaults to the body text. If `aBody` is not
   *        a string, then the clipboard text must be supplied.
   * @param number aLevel [optional]
   *        The level of the console API message.
   * @param number aTimeStamp [optional]
   *        The timestamp to use for this message node. If omitted, the current
   *        date and time is used.
   * @return nsIDOMNode
   *         The message node: a XUL richlistitem ready to be inserted into
   *         the Web Console output node.
   */
Given a category and message body, creates a DOM node to represent an
incoming message. The timestamp is automatically added.

@param number aCategory
The category of the message: one of the CATEGORY_* constants.
@param number aSeverity
The severity of the message: one of the SEVERITY_* constants;
@param string|nsIDOMNode aBody
The body of the message, either a simple string or a DOM node.
@param string aSourceURL [optional]
The URL of the source file that emitted the error.
@param number aSourceLine [optional]
The line number on which the error occurred. If zero or omitted,
there is no line number associated with this message.
@param string aClipboardText [optional]
The text that should be copied to the clipboard when this node is
copied. If omitted, defaults to the body text. If `aBody` is not
a string, then the clipboard text must be supplied.
@param number aLevel [optional]
The level of the console API message.
@param number aTimeStamp [optional]
The timestamp to use for this message node. If omitted, the current
date and time is used.
@return nsIDOMNode
The message node: a XUL richlistitem ready to be inserted into
the Web Console output node.
Given a category and message body creates a DOM node to represent an incoming message . The timestamp is automatically added . @param number aCategory The category of the message : one of the CATEGORY_ * constants . @param number aSeverity The severity of the message : one of the SEVERITY_ * constants ; @param string|nsIDOMNode aBody The body of the message either a simple string or a DOM node . @param string aSourceURL [ optional ] The URL of the source file that emitted the error . @param number aSourceLine [ optional ] The line number on which the error occurred . If zero or omitted there is no line number associated with this message . @param string aClipboardText [ optional ] The text that should be copied to the clipboard when this node is copied . If omitted defaults to the body text . If ` aBody ` is not a string then the clipboard text must be supplied . @param number aLevel [ optional ] The level of the console API message . @param number aTimeStamp [ optional ] The timestamp to use for this message node . If omitted the current date and time is used . @return nsIDOMNode The message node : a XUL richlistitem ready to be inserted into the Web Console output node .
function WCF_createMessageNode(aCategory, aSeverity, aBody, aSourceURL,
                                 aSourceLine, aClipboardText, aLevel, aTimeStamp)
  {
    if (typeof aBody != "string" && aClipboardText == null && aBody.innerText) {
      aClipboardText = aBody.innerText;
    }
    let iconContainer = this.document.createElementNS(XUL_NS, "vbox");
    iconContainer.classList.add("webconsole-msg-icon-container");
    iconContainer.style.marginLeft = this.groupDepth * GROUP_INDENT + "px";
    let iconNode = this.document.createElementNS(XUL_NS, "image");
    iconNode.classList.add("webconsole-msg-icon");
    iconContainer.appendChild(iconNode);
    let spacer = this.document.createElementNS(XUL_NS, "spacer");
    spacer.flex = 1;
    iconContainer.appendChild(spacer);
    let bodyNode = this.document.createElementNS(XUL_NS, "description");
    bodyNode.flex = 1;
    bodyNode.classList.add("webconsole-msg-body");
    let body = aBody;
    aClipboardText = aClipboardText ||
                     (aBody + (aSourceURL ? " @ " + aSourceURL : "") +
                              (aSourceLine ? ":" + aSourceLine : ""));
    let node = this.document.createElementNS(XUL_NS, "richlistitem");
    if (aBody instanceof Ci.nsIDOMNode) {
      bodyNode.appendChild(aBody);
    }
    else {
      let str = undefined;
      if (aLevel == "dir") {
        str = WebConsoleUtils.objectActorGripToString(aBody.arguments[0]);
      }
      else if (["log", "info", "warn", "error", "debug"].indexOf(aLevel) > -1 &&
               typeof aBody == "object") {
        this._makeConsoleLogMessageBody(node, bodyNode, aBody);
      }
      else {
        str = aBody;
      }
      if (str !== undefined) {
        aBody = this.document.createTextNode(str);
        bodyNode.appendChild(aBody);
      }
    }
    let repeatContainer = this.document.createElementNS(XUL_NS, "hbox");
    repeatContainer.setAttribute("align", "start");
    let repeatNode = this.document.createElementNS(XUL_NS, "label");
    repeatNode.setAttribute("value", "1");
    repeatNode.classList.add("webconsole-msg-repeat");
    repeatContainer.appendChild(repeatNode);
    let timestampNode = this.document.createElementNS(XUL_NS, "label");
    timestampNode.classList.add("webconsole-timestamp");
    let timestamp = aTimeStamp || Date.now();
    let timestampString = l10n.timestampString(timestamp);
    timestampNode.setAttribute("value", timestampString);
    let locationNode;
    if (aSourceURL) {
      locationNode = this.createLocationNode(aSourceURL, aSourceLine);
    }
    node.clipboardText = aClipboardText;
    node.classList.add("hud-msg-node");
    node.timestamp = timestamp;
    this.setMessageType(node, aCategory, aSeverity);
    node.appendChild(timestampNode);
    node.appendChild(iconContainer);
    if (aLevel == "dir") {
      let bodyContainer = this.document.createElement("vbox");
      bodyContainer.flex = 1;
      bodyContainer.appendChild(bodyNode);
      let tree = this.document.createElement("tree");
      tree.setAttribute("hidecolumnpicker", "true");
      tree.flex = 1;
      let treecols = this.document.createElement("treecols");
      let treecol = this.document.createElement("treecol");
      treecol.setAttribute("primary", "true");
      treecol.setAttribute("hideheader", "true");
      treecol.setAttribute("ignoreincolumnpicker", "true");
      treecol.flex = 1;
      treecols.appendChild(treecol);
      tree.appendChild(treecols);
      tree.appendChild(this.document.createElement("treechildren"));
      bodyContainer.appendChild(tree);
      node.appendChild(bodyContainer);
      node.classList.add("webconsole-msg-inspector");
      let treeView = node.propertyTreeView = new PropertyTreeView();
      treeView.data = {
        objectPropertiesProvider: this.objectPropertiesProvider.bind(this),
        releaseObject: this._releaseObject.bind(this),
        objectProperties: body.objectProperties,
      };
      tree.setAttribute("rows", treeView.rowCount);
    }
    else {
      node.appendChild(bodyNode);
    }
    node.appendChild(repeatContainer);
    if (locationNode) {
      node.appendChild(locationNode);
    }
    node.setAttribute("id", "console-msg-" + gSequenceId());
    return node;
  }
function WCF_createMessageNode ( aCategory , aSeverity , aBody , aSourceURL , aSourceLine , aClipboardText , aLevel , aTimeStamp ) { if ( typeof aBody != "string" && aClipboardText == null && aBody . innerText ) { aClipboardText = aBody . innerText ; } let iconContainer = this . document . createElementNS ( XUL_NS , "vbox" ) ; iconContainer . classList . add ( "webconsole-msg-icon-container" ) ; iconContainer . style . marginLeft = this . groupDepth * GROUP_INDENT + "px" ; let iconNode = this . document . createElementNS ( XUL_NS , "image" ) ; iconNode . classList . add ( "webconsole-msg-icon" ) ; iconContainer . appendChild ( iconNode ) ; let spacer = this . document . createElementNS ( XUL_NS , "spacer" ) ; spacer . flex = 1 ; iconContainer . appendChild ( spacer ) ; let bodyNode = this . document . createElementNS ( XUL_NS , "description" ) ; bodyNode . flex = 1 ; bodyNode . classList . add ( "webconsole-msg-body" ) ; let body = aBody ; aClipboardText = aClipboardText || ( aBody + ( aSourceURL ? " @ " + aSourceURL : "" ) + ( aSourceLine ? ":" + aSourceLine : "" ) ) ; let node = this . document . createElementNS ( XUL_NS , "richlistitem" ) ; if ( aBody instanceof Ci . nsIDOMNode ) { bodyNode . appendChild ( aBody ) ; } else { let str = undefined ; if ( aLevel == "dir" ) { str = WebConsoleUtils . objectActorGripToString ( aBody . arguments [ 0 ] ) ; } else if ( [ "log" , "info" , "warn" , "error" , "debug" ] . indexOf ( aLevel ) > - 1 && typeof aBody == "object" ) { this . _makeConsoleLogMessageBody ( node , bodyNode , aBody ) ; } else { str = aBody ; } if ( str !== undefined ) { aBody = this . document . createTextNode ( str ) ; bodyNode . appendChild ( aBody ) ; } } let repeatContainer = this . document . createElementNS ( XUL_NS , "hbox" ) ; repeatContainer . setAttribute ( "align" , "start" ) ; let repeatNode = this . document . createElementNS ( XUL_NS , "label" ) ; repeatNode . setAttribute ( "value" , "1" ) ; repeatNode . classList . add ( "webconsole-msg-repeat" ) ; repeatContainer . appendChild ( repeatNode ) ; let timestampNode = this . document . createElementNS ( XUL_NS , "label" ) ; timestampNode . classList . add ( "webconsole-timestamp" ) ; let timestamp = aTimeStamp || Date . now ( ) ; let timestampString = l10n . timestampString ( timestamp ) ; timestampNode . setAttribute ( "value" , timestampString ) ; let locationNode ; if ( aSourceURL ) { locationNode = this . createLocationNode ( aSourceURL , aSourceLine ) ; } node . clipboardText = aClipboardText ; node . classList . add ( "hud-msg-node" ) ; node . timestamp = timestamp ; this . setMessageType ( node , aCategory , aSeverity ) ; node . appendChild ( timestampNode ) ; node . appendChild ( iconContainer ) ; if ( aLevel == "dir" ) { let bodyContainer = this . document . createElement ( "vbox" ) ; bodyContainer . flex = 1 ; bodyContainer . appendChild ( bodyNode ) ; let tree = this . document . createElement ( "tree" ) ; tree . setAttribute ( "hidecolumnpicker" , "true" ) ; tree . flex = 1 ; let treecols = this . document . createElement ( "treecols" ) ; let treecol = this . document . createElement ( "treecol" ) ; treecol . setAttribute ( "primary" , "true" ) ; treecol . setAttribute ( "hideheader" , "true" ) ; treecol . setAttribute ( "ignoreincolumnpicker" , "true" ) ; treecol . flex = 1 ; treecols . appendChild ( treecol ) ; tree . appendChild ( treecols ) ; tree . appendChild ( this . document . createElement ( "treechildren" ) ) ; bodyContainer . appendChild ( tree ) ; node . appendChild ( bodyContainer ) ; node . classList . add ( "webconsole-msg-inspector" ) ; let treeView = node . propertyTreeView = new PropertyTreeView ( ) ; treeView . data = { objectPropertiesProvider : this . objectPropertiesProvider . bind ( this ) , releaseObject : this . _releaseObject . bind ( this ) , objectProperties : body . objectProperties , } ; tree . setAttribute ( "rows" , treeView . rowCount ) ; } else { node . appendChild ( bodyNode ) ; } node . appendChild ( repeatContainer ) ; if ( locationNode ) { node . appendChild ( locationNode ) ; } node . setAttribute ( "id" , "console-msg-" + gSequenceId ( ) ) ; return node ; }
Given a category and message body, creates a DOM node to represent an
 incoming message.
Given a category and message body creates a DOM node to represent an incoming message .
// Make the icon container, which is a vertical box. Its purpose is to // ensure that the icon stays anchored at the top of the message even for // long multi-line messages. // Apply the curent group by indenting appropriately. // Make the icon node. It's sprited and the actual region of the image is // determined by CSS rules. // Make the spacer that positions the icon. // Create the message body, which contains the actual text of the message. // Store the body text, since it is needed later for the property tree // case. // If a string was supplied for the body, turn it into a DOM node and an // associated clipboard string now. // Create the containing node and append all its elements to it. // Create the timestamp. // Create the source location (e.g. www.example.com:6) that sits on the // right side of the message, if applicable. // Display the object tree after the message node. // Make the body container, which is a vertical box, for grouping the text // and tree widgets. // Create the tree. // Create the treeView object.