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.

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

mercurial