Reviewed by timothy.
[WebKit-https.git] / LayoutTests / fast / js / window-properties.html
1 <html>
2 <body>
3 <div id="log"></div>
4 <script type="text/javascript">
5
6 if (window.layoutTestController)
7   layoutTestController.dumpAsText();
8
9 var logDiv = document.getElementById("log");
10 var lastLogLine = 0;
11
12 function log(string) {
13   var newDiv = document.createElement('DIV');
14   newDiv.appendChild(document.createTextNode(string));
15   logDiv.appendChild(newDiv);
16   lastLogLine++;
17 }
18
19 function shouldSkipProperty(fullPropertyName, propertyValue) {
20   if (fullPropertyName.match(/_childrenPrintedUnderName$/))
21     return true;
22 }
23
24 function shouldSkipChildren(fullPropertyName, propertyValue) {
25   if (propertyValue == logDiv
26     || fullPropertyName == 'window.document.body.lastChild')
27     return true;
28 }
29
30 function havePrintedChildren(fullPropertyName, propertyValue) {
31   try {
32     var childrenPrintedUnderName = propertyValue._childrenPrintedUnderName;
33     if (!childrenPrintedUnderName)
34       propertyValue._childrenPrintedUnderName = fullPropertyName;
35     return childrenPrintedUnderName;
36   } catch (e) {
37     log(fullPropertyName + " : ERROR determining if we have already printed children, assuming true");
38     return true;
39   }
40 }
41
42 function printProperties(object, parentString) {
43   for (propertyName in object) {
44     var fullPropertyName = parentString + '.' + propertyName;
45     var propertyValue;
46     try {
47       propertyValue = object[propertyName]; // Firefox throws here for certain unimplemented DOM3 properties
48     } catch (e) {
49       log(fullPropertyName + " : ERROR accessing property, exception thrown: " + e);
50       continue;
51     }
52     if (shouldSkipProperty(fullPropertyName, propertyValue))
53       continue;
54     var type = (propertyValue === null ? 'null' : typeof(propertyValue));
55     log(fullPropertyName + " : " + type);
56     var previousPropertyName = '';
57     if (propertyValue && type == 'object') {
58       if (shouldSkipChildren(fullPropertyName, propertyValue))
59         log(fullPropertyName + ' *** children skipped (explicitly)');
60       else if (previousPropertyName = havePrintedChildren(fullPropertyName, propertyValue))
61         log(fullPropertyName + " *** children skipped, already printed above under '" + previousPropertyName + "'");
62       else
63         printProperties(propertyValue, fullPropertyName);
64     }
65   }
66 }
67
68 log('window : ' + typeof(window));
69 havePrintedChildren(window, 'window');
70 printProperties(window, 'window');
71
72 </script>
73 </body>
74 </html>