~ubuntu-branches/ubuntu/karmic/firebug/karmic

« back to all changes in this revision

Viewing changes to content/firebug/trace.js

  • Committer: Bazaar Package Importer
  • Author(s): Jared Greenwald
  • Date: 2008-02-21 17:34:24 UTC
  • Revision ID: james.westby@ubuntu.com-20080221173424-illircvfpyvnp4uo
Tags: upstream-1.1.0~b11+svn317
ImportĀ upstreamĀ versionĀ 1.1.0~b11+svn317

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* See license.txt for terms of usage */
 
2
 
 
3
// Debug Logging for Firebug internals
 
4
 
 
5
var FBTrace = {};
 
6
try {
 
7
(function() {
 
8
 
 
9
const consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces["nsIConsoleService"]);
 
10
 
 
11
 
 
12
this.initializeTrace = function(context)
 
13
{
 
14
    if (FBTrace.dumpToPanel && context)
 
15
    {
 
16
        FBTrace.sysout = function(msg) {
 
17
            var noThrottle = true;
 
18
            Firebug.TraceModule.log(msg, context, "info", FirebugReps.Text, noThrottle);
 
19
        }
 
20
        dump("trace.initializeTrace Set to panel\n");
 
21
    }
 
22
    else
 
23
    {
 
24
        FBTrace.sysout = function(msg)
 
25
        {
 
26
            dump(msg);
 
27
        }
 
28
        dump("trace.initializeTrace Set to stdout for context="+context+"\n");
 
29
    }
 
30
}
 
31
this.dumpToPanel = false;
 
32
 
 
33
 
 
34
this.dumpProperties = function(header, obj)
 
35
{
 
36
    try {
 
37
        var noThrottle = true;
 
38
        this.sysout(header+" sees object with typeof: \'"+typeof(obj)+"\'; object contains:\n");
 
39
        if (obj instanceof Array)
 
40
        {
 
41
            if (FBTrace.dumpToPanel && FirebugContext)
 
42
                return Firebug.TraceModule.log(obj, FirebugContext, "info", FirebugReps.Array, noThrottle);
 
43
 
 
44
            for (var p = 0; p < obj.length; p++)
 
45
            {
 
46
                try
 
47
                {
 
48
                    this.sysout("["+p+"]="+obj[p]+";\n");
 
49
                }
 
50
                catch (e)
 
51
                {
 
52
                    this.sysout("dumpProperties failed:"+e+"\n");
 
53
                }
 
54
            }
 
55
        }
 
56
        else if (typeof(obj) == 'string')
 
57
        {
 
58
            if (FBTrace.dumpToPanel && FirebugContext)
 
59
                return Firebug.TraceModule.log(obj, FirebugContext, "info", FirebugReps.Text, noThrottle);
 
60
 
 
61
            this.sysout(obj+"\n");
 
62
        }
 
63
        //else if (obj.name && obj.name == 'NS_ERROR_XPC_JS_THREW_JS_OBJECT')
 
64
        //{
 
65
        //
 
66
        //}
 
67
        else
 
68
        {
 
69
            if (FBTrace.dumpToPanel && FirebugContext)
 
70
                return Firebug.TraceModule.log(obj, FirebugContext, "info", FirebugReps.Obj, noThrottle);
 
71
 
 
72
            for (var p in obj)
 
73
            {
 
74
                                if (p.match("QueryInterface"))
 
75
                                {
 
76
                                        if (this.dumpInterfaces(obj))
 
77
                                                continue;
 
78
                                        else
 
79
                                                this.sysout("dumpInterfaces found NONE\n");
 
80
                                }
 
81
                try
 
82
                {
 
83
                    this.sysout("["+p+"]="+obj[p]+";\n");
 
84
                }
 
85
                catch (e)
 
86
                {
 
87
                    this.sysout("dumpProperties failed:"+e+"\n");
 
88
                }
 
89
            }
 
90
        }
 
91
    }
 
92
    catch(exc)
 
93
    {
 
94
        this.dumpStack("dumpProperties failed:"+exc+" trying with header="+header);
 
95
    }
 
96
},
 
97
 
 
98
this.dumpInterfaces = function(obj)
 
99
{
 
100
        var found = false;
 
101
        // could try for classInfo
 
102
        for(iface in Components.interfaces)
 
103
        {
 
104
                if (obj instanceof Components.interfaces[iface])
 
105
                {
 
106
                        found = true;
 
107
                        for (p in Components.interfaces[iface])
 
108
                        {
 
109
                                this.sysout("["+iface+"."+p+"]="+obj[p]+";\n");
 
110
                        }
 
111
                }
 
112
 
 
113
        }
 
114
        return found;
 
115
},
 
116
 
 
117
this.consoleOut = function(text)
 
118
{
 
119
    consoleService.logStringMessage(text + "");
 
120
},
 
121
 
 
122
this.dumpStack = function(optional_header) {
 
123
    if (optional_header)
 
124
        this.sysout(optional_header + "\n");
 
125
    this.sysout(this.getComponentsStack(2));
 
126
    this.sysout("\n");
 
127
}
 
128
 
 
129
this.getComponentsStack = function(strip)
 
130
{
 
131
    var lines = [];
 
132
    for (var frame = Components.stack; frame; frame = frame.caller)
 
133
        lines.push(frame.filename + " (" + frame.lineNumber + ")");
 
134
 
 
135
    if (strip)
 
136
        lines.splice(0, strip);
 
137
 
 
138
    return lines.join("\n");
 
139
};
 
140
 
 
141
 
 
142
// ************************************************************************************************
 
143
this.initializeTrace();
 
144
 
 
145
}).apply(FBTrace);
 
146
} catch (exc) { alert(exc);}
 
 
b'\\ No newline at end of file'