cflow.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.cflow"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.lang.aspect.cflow"] = true;
  8. dojo.provide("dojox.lang.aspect.cflow");
  9. (function(){
  10. var aop = dojox.lang.aspect;
  11. aop.cflow = function(/*Object*/ instance, /*String|RegExp|Array?*/ method){
  12. // summary:
  13. // Returns true if the context stack contains a context for a given
  14. // instance that satisfies a given method name criteria.
  15. //
  16. // instance:
  17. // An instance to be matched. If null, any context will be examined.
  18. // Otherwise the context should belong to this instance.
  19. //
  20. // method:
  21. // An optional pattern to be matched against a method name. Can be a string,
  22. // a RegExp object or an array of strings and RegExp objects.
  23. // If it is omitted, any name will satisfy the criteria.
  24. if(arguments.length > 1 && !(method instanceof Array)){
  25. method = [method];
  26. }
  27. var contextStack = aop.getContextStack();
  28. for(var i = contextStack.length - 1; i >= 0; --i){
  29. var c = contextStack[i];
  30. // check if instance matches
  31. if(instance && c.instance != instance){ continue; }
  32. if(!method){ return true; }
  33. var n = c.joinPoint.targetName;
  34. for(var j = method.length - 1; j >= 0; --j){
  35. var m = method[j];
  36. if(m instanceof RegExp){
  37. if(m.test(n)){ return true; }
  38. }else{
  39. if(n == m){ return true; }
  40. }
  41. }
  42. }
  43. return false; // Boolean
  44. };
  45. })();
  46. }