counter.js 890 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.lang.aspect.counter"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.lang.aspect.counter"] = true;
  8. dojo.provide("dojox.lang.aspect.counter");
  9. (function(){
  10. var aop = dojox.lang.aspect;
  11. var Counter = function(){
  12. this.reset();
  13. };
  14. dojo.extend(Counter, {
  15. before: function(/*arguments*/){
  16. ++this.calls;
  17. },
  18. afterThrowing: function(/*excp*/){
  19. ++this.errors;
  20. },
  21. reset: function(){
  22. this.calls = this.errors = 0;
  23. }
  24. });
  25. aop.counter = function(){
  26. // summary:
  27. // Returns an object, which can be used to count calls to methods.
  28. return new Counter; // Object
  29. };
  30. })();
  31. }