tracer.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // wrapped by build app
  2. define("dojox/lang/aspect/tracer", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.lang.aspect.tracer");
  4. (function(){
  5. var aop = dojox.lang.aspect;
  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. aop.tracer = function(/*Boolean*/ grouping){
  34. // summary:
  35. // Returns an object, which can be used to trace calls with Firebug's console.
  36. // Prints argument, a return value, or an exception.
  37. //
  38. // grouping:
  39. // The flag to group output. If true, indents embedded console messages.
  40. return new Tracer(grouping); // Object
  41. };
  42. })();
  43. });