Debian package: Support xulrunner 9+10 in debian/conkeror.bin, drop support for unver...
[conkeror.git] / modules / debug.js
blobee255ef46d2a002b6316d65a374199d53dce9e5c
1 /**
2  * (C) Copyright 2007 John J. Foerch
3  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
4  *
5  * Use, modification, and distribution are subject to the terms specified in the
6  * COPYING file.
7 **/
9 in_module(null);
11 var MAX_DUMP_DEPTH = 1;
12 function dump_obj_r (obj, name, indent, depth) {
13     if (depth > MAX_DUMP_DEPTH) {
14         return indent + name + ": <Maximum Depth Reached>\n";
15     }
16     if (typeof obj == "object") {
17         var child = null;
18         var output = indent + name + "\n";
19         indent += "\t";
20         for (var item in obj) {
21             try {
22                 child = obj[item];
23             } catch (e) {
24                 child = "<Unable to Evaluate>";
25             }
26             if (typeof child == "object") {
27                 output += dump_obj_r(child, item, indent, depth + 1);
28             } else {
29                 output += indent + item + ": " + child + "\n";
30             }
31         }
32         return output;
33     } else {
34         return obj;
35     }
38 function dump_obj (obj, name) {
39     if (typeof obj == "object") {
40         var child = null;
41         var output = name + "\n";
42         for (var item in obj) {
43             try {
44                 child = obj[item];
45             } catch (e) {
46                 child = "<Unable to Evaluate>";
47             }
48             output += item + ": " + child + "\n";
49         }
50         return output;
51     } else {
52         return obj;
53     }
56 function get_interface_info (o) {
57     var output = "";
58     for (let x in Ci) {
59         try {
60             o.QueryInterface(Ci[x]);
61             output += x + "\n";
62         } catch (e)  {
63             try {
64                 o.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci[x]);
65                 output += x + " (getInterface)\n";
66             } catch (e2) {
67             }
68         }
69     }
70     return output;
73 /**
74  * This simple facility can be used to execute arbitrary expression in the context of some point that you'd like to debug.
75  * At that point, simply set some global variable to the result of: eval(DEBUG_HERE);
76  * For example:  conkeror.my_debug_ref = eval(DEBUG_HERE);
77  * Then if you call:  conkeror.my_debug_ref("some expression"), the specified expression is evaluated in the context
78  * at which eval(DEBUG_HERE) was called.
79  *
80  * Note that the unusual identifier __DEBUG_HERE is simply used to
81  * avoid clobbering any identifiers that you might want to examine in
82  * the local context.
83  */
84 const DEBUG_HERE = "function (__DEBUG_HERE) { return eval(__DEBUG_HERE); }";
88 let (console = Cc["@mozilla.org/consoleservice;1"]
89                    .getService(Ci.nsIConsoleService)) {
90     console.registerListener({
91         observe: function (msg) {
92             if (msg instanceof Ci.nsIScriptError) {
93                 switch (msg.category) {
94                 case "CSS Parser":
95                 case "content javascript":
96                     return;
97                 }
98                 msg.QueryInterface(Ci.nsIScriptError);
99                 dumpln("Console error: " + msg.message);
100                 dumpln("  Category: " + msg.category);
101             }
102         }});
105 provide("debug");