1 | dojo.provide("dojox.lang.aspect.tracer"); |
---|
2 | |
---|
3 | (function(){ |
---|
4 | var aop = dojox.lang.aspect; |
---|
5 | |
---|
6 | var Tracer = function(/*Boolean*/ grouping){ |
---|
7 | this.method = grouping ? "group" : "log"; |
---|
8 | if(grouping){ |
---|
9 | this.after = this._after; |
---|
10 | } |
---|
11 | }; |
---|
12 | dojo.extend(Tracer, { |
---|
13 | before: function(/*arguments*/){ |
---|
14 | var context = aop.getContext(), joinPoint = context.joinPoint, |
---|
15 | args = Array.prototype.join.call(arguments, ", "); |
---|
16 | console[this.method](context.instance, "=>", joinPoint.targetName + "(" + args + ")"); |
---|
17 | }, |
---|
18 | afterReturning: function(retVal){ |
---|
19 | var joinPoint = aop.getContext().joinPoint; |
---|
20 | if(typeof retVal != "undefined"){ |
---|
21 | console.log(joinPoint.targetName + "() returns:", retVal); |
---|
22 | }else{ |
---|
23 | console.log(joinPoint.targetName + "() returns"); |
---|
24 | } |
---|
25 | }, |
---|
26 | afterThrowing: function(excp){ |
---|
27 | console.log(aop.getContext().joinPoint.targetName + "() throws:", excp); |
---|
28 | }, |
---|
29 | _after: function(excp){ |
---|
30 | console.groupEnd(); |
---|
31 | } |
---|
32 | }); |
---|
33 | |
---|
34 | aop.tracer = function(/*Boolean*/ grouping){ |
---|
35 | // summary: |
---|
36 | // Returns an object, which can be used to trace calls with Firebug's console. |
---|
37 | // Prints argument, a return value, or an exception. |
---|
38 | // |
---|
39 | // grouping: |
---|
40 | // The flag to group output. If true, indents embedded console messages. |
---|
41 | |
---|
42 | return new Tracer(grouping); // Object |
---|
43 | }; |
---|
44 | })(); |
---|