dom/tests/js/DumpTree.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 //
     8 // travers the html tree and dump out the type of element
     9 //
    10 function traverse(node, indent)
    11 {
    12     dump("\n")
    13     indent += "  "
    14     var type = node.nodeType;
    16     // if it's an element dump the tag and recurse the children
    17     if (type == Node.ELEMENT_NODE) {
    19         dump(indent + node.tagName)
    21         // go through the children
    22         if (node.hasChildNodes()) {
    23             var children = node.childNodes;
    24             var length = children.length;
    25             var count = 0;
    26             while(count < length) {
    27                 child = children[count]
    28                 traverse(child, indent)
    29                 count++
    30             }
    31         }
    32     }
    33     // it's just text, no tag, dump "Text"
    34     else if (type == Node.TEXT_NODE) {
    35         dump(indent + "Text")
    36     }
    37 }
    39 var node = document.documentElement
    41 traverse(node, "")
    42 dump("\n")

mercurial