cflow.js 1.4 KB

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