isearch-backspace, isearch-done: docstrings
[conkeror.git] / modules / debug.js
blob7f989b89d84fe5fa7d6d7a34fa4b9f327894ade5
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 var MAX_DUMP_DEPTH = 1;
10 function dump_obj_r (obj, name, indent, depth) {
11     if (depth > MAX_DUMP_DEPTH) {
12         return indent + name + ": <Maximum Depth Reached>\n";
13     }
14     if (typeof obj == "object") {
15         var child = null;
16         var output = indent + name + "\n";
17         indent += "\t";
18         for (var item in obj) {
19             try {
20                 child = obj[item];
21             } catch (e) {
22                 child = "<Unable to Evaluate>";
23             }
24             if (typeof child == "object") {
25                 output += dump_obj_r(child, item, indent, depth + 1);
26             } else {
27                 output += indent + item + ": " + child + "\n";
28             }
29         }
30         return output;
31     } else {
32         return obj;
33     }
36 function dump_obj (obj, name) {
37     if (typeof obj == "object") {
38         var child = null;
39         var output = name + "\n";
40         for (var item in obj) {
41             try {
42                 child = obj[item];
43             } catch (e) {
44                 child = "<Unable to Evaluate>";
45             }
46             output += item + ": " + child + "\n";
47         }
48         return output;
49     } else {
50         return obj;
51     }
54 function get_interface_info (o) {
55     var output = "";
56     for (let x in Ci) {
57         try {
58             o.QueryInterface(Ci[x]);
59             output += x + "\n";
60         } catch (e)  {
61             try {
62                 o.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci[x]);
63                 output += x + " (getInterface)\n";
64             } catch (e2) {
65             }
66         }
67     }
68     return output;
71 /**
72  * This simple facility can be used to execute arbitrary expression in the context of some point that you'd like to debug.
73  * At that point, simply set some global variable to the result of: eval(DEBUG_HERE);
74  * For example:  conkeror.my_debug_ref = eval(DEBUG_HERE);
75  * Then if you call:  conkeror.my_debug_ref("some expression"), the specified expression is evaluated in the context
76  * at which eval(DEBUG_HERE) was called.
77  *
78  * Note that the unusual identifier __DEBUG_HERE is simply used to
79  * avoid clobbering any identifiers that you might want to examine in
80  * the local context.
81  */
82 const DEBUG_HERE = "function (__DEBUG_HERE) { return eval(__DEBUG_HERE); }";
86 let (console = Cc["@mozilla.org/consoleservice;1"]
87                    .getService(Ci.nsIConsoleService)) {
88     console.registerListener({
89         observe: function (msg) {
90             if (msg instanceof Ci.nsIScriptError) {
91                 switch (msg.category) {
92                 case "CSS Parser":
93                 case "content javascript":
94                     return;
95                 }
96                 msg.QueryInterface(Ci.nsIScriptError);
97                 dumpln("Console error: " + msg.message);
98                 dumpln("  Category: " + msg.category);
99             }
100         }});
103 provide("debug");