dom/xslt/tests/buster/DumpDOM.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 // ----------------------
michael@0 2 // DumpDOM(node)
michael@0 3 //
michael@0 4 // Call this function to dump the contents of the DOM starting at the specified node.
michael@0 5 // Use node = document.documentElement to dump every element of the current document.
michael@0 6 // Use node = top.window.document.documentElement to dump every element.
michael@0 7 //
michael@0 8 // 8-13-99 Updated to dump almost all attributes of every node. There are still some attributes
michael@0 9 // that are purposely skipped to make it more readable.
michael@0 10 // ----------------------
michael@0 11 function DumpDOM(node)
michael@0 12 {
michael@0 13 dump("--------------------- DumpDOM ---------------------\n");
michael@0 14
michael@0 15 DumpNodeAndChildren(node, "");
michael@0 16
michael@0 17 dump("------------------- End DumpDOM -------------------\n");
michael@0 18 }
michael@0 19
michael@0 20
michael@0 21 // This function does the work of DumpDOM by recursively calling itself to explore the tree
michael@0 22 function DumpNodeAndChildren(node, prefix)
michael@0 23 {
michael@0 24 dump(prefix + "<" + node.nodeName);
michael@0 25
michael@0 26 var attributes = node.attributes;
michael@0 27
michael@0 28 if ( attributes && attributes.length )
michael@0 29 {
michael@0 30 var item, name, value;
michael@0 31
michael@0 32 for ( var index = 0; index < attributes.length; index++ )
michael@0 33 {
michael@0 34 item = attributes.item(index);
michael@0 35 name = item.nodeName;
michael@0 36 value = item.nodeValue;
michael@0 37
michael@0 38 if ( (name == 'lazycontent' && value == 'true') ||
michael@0 39 (name == 'xulcontentsgenerated' && value == 'true') ||
michael@0 40 (name == 'id') ||
michael@0 41 (name == 'instanceOf') )
michael@0 42 {
michael@0 43 // ignore these
michael@0 44 }
michael@0 45 else
michael@0 46 {
michael@0 47 dump(" " + name + "=\"" + value + "\"");
michael@0 48 }
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 if ( node.nodeType == 1 )
michael@0 53 {
michael@0 54 // id
michael@0 55 var text = node.getAttribute('id');
michael@0 56 if ( text && text[0] != '$' )
michael@0 57 dump(" id=\"" + text + "\"");
michael@0 58 }
michael@0 59
michael@0 60 if ( node.nodeType == Node.TEXT_NODE )
michael@0 61 dump(" = \"" + node.data + "\"");
michael@0 62
michael@0 63 dump(">\n");
michael@0 64
michael@0 65 // dump IFRAME && FRAME DOM
michael@0 66 if ( node.nodeName == "IFRAME" || node.nodeName == "FRAME" )
michael@0 67 {
michael@0 68 if ( node.name )
michael@0 69 {
michael@0 70 var wind = top.frames[node.name];
michael@0 71 if ( wind && wind.document && wind.document.documentElement )
michael@0 72 {
michael@0 73 dump(prefix + "----------- " + node.nodeName + " -----------\n");
michael@0 74 DumpNodeAndChildren(wind.document.documentElement, prefix + " ");
michael@0 75 dump(prefix + "--------- End " + node.nodeName + " ---------\n");
michael@0 76 }
michael@0 77 }
michael@0 78 }
michael@0 79 // children of nodes (other than frames)
michael@0 80 else if ( node.childNodes )
michael@0 81 {
michael@0 82 for ( var child = 0; child < node.childNodes.length; child++ )
michael@0 83 DumpNodeAndChildren(node.childNodes[child], prefix + " ");
michael@0 84 }
michael@0 85 }

mercurial