diff options
Diffstat (limited to 'js/dojo/dojox/lang/aspect')
| -rw-r--r-- | js/dojo/dojox/lang/aspect/cflow.js | 47 | ||||
| -rw-r--r-- | js/dojo/dojox/lang/aspect/counter.js | 31 | ||||
| -rw-r--r-- | js/dojo/dojox/lang/aspect/memoizer.js | 49 | ||||
| -rw-r--r-- | js/dojo/dojox/lang/aspect/memoizerGuard.js | 37 | ||||
| -rw-r--r-- | js/dojo/dojox/lang/aspect/profiler.js | 37 | ||||
| -rw-r--r-- | js/dojo/dojox/lang/aspect/timer.js | 37 | ||||
| -rw-r--r-- | js/dojo/dojox/lang/aspect/tracer.js | 48 |
7 files changed, 286 insertions, 0 deletions
diff --git a/js/dojo/dojox/lang/aspect/cflow.js b/js/dojo/dojox/lang/aspect/cflow.js new file mode 100644 index 0000000..90bb134 --- /dev/null +++ b/js/dojo/dojox/lang/aspect/cflow.js @@ -0,0 +1,47 @@ +//>>built +// wrapped by build app +define("dojox/lang/aspect/cflow", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.aspect.cflow"); + + +(function(){ + var aop = dojox.lang.aspect; + + aop.cflow = function(/*Object*/ instance, /*String|RegExp|Array?*/ method){ + // summary: + // Returns true if the context stack contains a context for a given + // instance that satisfies a given method name criteria. + // + // instance: + // An instance to be matched. If null, any context will be examined. + // Otherwise the context should belong to this instance. + // + // method: + // An optional pattern to be matched against a method name. Can be a string, + // a RegExp object or an array of strings and RegExp objects. + // If it is omitted, any name will satisfy the criteria. + + if(arguments.length > 1 && !(method instanceof Array)){ + method = [method]; + } + + var contextStack = aop.getContextStack(); + for(var i = contextStack.length - 1; i >= 0; --i){ + var c = contextStack[i]; + // check if instance matches + if(instance && c.instance != instance){ continue; } + if(!method){ return true; } + var n = c.joinPoint.targetName; + for(var j = method.length - 1; j >= 0; --j){ + var m = method[j]; + if(m instanceof RegExp){ + if(m.test(n)){ return true; } + }else{ + if(n == m){ return true; } + } + } + } + return false; // Boolean + }; +})(); +}); diff --git a/js/dojo/dojox/lang/aspect/counter.js b/js/dojo/dojox/lang/aspect/counter.js new file mode 100644 index 0000000..cb17981 --- /dev/null +++ b/js/dojo/dojox/lang/aspect/counter.js @@ -0,0 +1,31 @@ +//>>built +// wrapped by build app +define("dojox/lang/aspect/counter", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.aspect.counter"); + +(function(){ + var aop = dojox.lang.aspect; + + var Counter = function(){ + this.reset(); + }; + dojo.extend(Counter, { + before: function(/*arguments*/){ + ++this.calls; + }, + afterThrowing: function(/*excp*/){ + ++this.errors; + }, + reset: function(){ + this.calls = this.errors = 0; + } + }); + + aop.counter = function(){ + // summary: + // Returns an object, which can be used to count calls to methods. + + return new Counter; // Object + }; +})(); +}); diff --git a/js/dojo/dojox/lang/aspect/memoizer.js b/js/dojo/dojox/lang/aspect/memoizer.js new file mode 100644 index 0000000..4692aed --- /dev/null +++ b/js/dojo/dojox/lang/aspect/memoizer.js @@ -0,0 +1,49 @@ +//>>built +// wrapped by build app +define("dojox/lang/aspect/memoizer", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.aspect.memoizer"); + +(function(){ + var aop = dojox.lang.aspect; + + var memoize1 = { + around: function(key){ + var ctx = aop.getContext(), self = ctx.joinPoint, that = ctx.instance, t, u, ret; + if((t = that.__memoizerCache) && (t = t[self.targetName]) && (key in t)){ + return t[key]; + } + var ret = aop.proceed.apply(null, arguments); + if(!(t = that.__memoizerCache)){ t = that.__memoizerCache = {}; } + if(!(u = t[self.targetName])){ u = t[self.targetName] = {}; } + return u[key] = ret; + } + }; + + var memoizeN = function(/*Function*/keyMaker){ + return { + around: function(/*arguments*/){ + var ctx = aop.getContext(), self = ctx.joinPoint, that = ctx.instance, t, u, ret, + key = keyMaker.apply(that, arguments); + if((t = that.__memoizerCache) && (t = t[self.targetName]) && (key in t)){ + return t[key]; + } + var ret = aop.proceed.apply(null, arguments); + if(!(t = that.__memoizerCache)){ t = that.__memoizerCache = {}; } + if(!(u = t[self.targetName])){ u = t[self.targetName] = {}; } + return u[key] = ret; + } + }; + }; + + aop.memoizer = function(/*Function?*/ keyMaker){ + // summary: + // Returns an object, which can be used to count calls to methods. + // + // keyMaker: + // the function, which takes method's arguments and returns a key, + // which can be used to index the result. + + return arguments.length == 0 ? memoize1 : memoizeN(keyMaker); // Object + }; +})(); +}); diff --git a/js/dojo/dojox/lang/aspect/memoizerGuard.js b/js/dojo/dojox/lang/aspect/memoizerGuard.js new file mode 100644 index 0000000..81f5e52 --- /dev/null +++ b/js/dojo/dojox/lang/aspect/memoizerGuard.js @@ -0,0 +1,37 @@ +//>>built +// wrapped by build app +define("dojox/lang/aspect/memoizerGuard", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.aspect.memoizerGuard"); + +(function(){ + var aop = dojox.lang.aspect, + reset = function(/*String|Array?*/ method){ + var that = aop.getContext().instance, t; + if(!(t = that.__memoizerCache)){ return; } + if(arguments.length == 0){ + delete that.__memoizerCache; + }else if(dojo.isArray(method)){ + dojo.forEach(method, function(m){ delete t[m]; }); + }else{ + delete t[method]; + } + }; + + + aop.memoizerGuard = function(/*String|Array?*/ method){ + // summary: + // Invalidates the memoizer's cache (see dojox.lang.aspect.memoizer) + // after calling certain methods. + // + // method: + // Optional method's name to be guarded: only cache for + // this method will be invalidated on call. Can be a string + // or an array of method names. If omitted the whole cache + // will be invalidated. + + return { // Object + after: function(){ reset(method); } + }; + }; +})(); +}); diff --git a/js/dojo/dojox/lang/aspect/profiler.js b/js/dojo/dojox/lang/aspect/profiler.js new file mode 100644 index 0000000..cec4500 --- /dev/null +++ b/js/dojo/dojox/lang/aspect/profiler.js @@ -0,0 +1,37 @@ +//>>built +// wrapped by build app +define("dojox/lang/aspect/profiler", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.aspect.profiler"); + +(function(){ + var aop = dojox.lang.aspect, + uniqueNumber = 0; + + var Profiler = function(title){ + this.args = title ? [title] : []; + this.inCall = 0; + }; + dojo.extend(Profiler, { + before: function(/*arguments*/){ + if(!(this.inCall++)){ + console.profile.apply(console, this.args); + } + }, + after: function(/*excp*/){ + if(!--this.inCall){ + console.profileEnd(); + } + } + }); + + aop.profiler = function(/*String?*/ title){ + // summary: + // Returns an object, which can be used to time calls to methods. + // + // title: + // The optional name of the profile section. + + return new Profiler(title); // Object + }; +})(); +}); diff --git a/js/dojo/dojox/lang/aspect/timer.js b/js/dojo/dojox/lang/aspect/timer.js new file mode 100644 index 0000000..6989932 --- /dev/null +++ b/js/dojo/dojox/lang/aspect/timer.js @@ -0,0 +1,37 @@ +//>>built +// wrapped by build app +define("dojox/lang/aspect/timer", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.aspect.timer"); + +(function(){ + var aop = dojox.lang.aspect, + uniqueNumber = 0; + + var Timer = function(name){ + this.name = name || ("DojoAopTimer #" + ++uniqueNumber); + this.inCall = 0; + }; + dojo.extend(Timer, { + before: function(/*arguments*/){ + if(!(this.inCall++)){ + console.time(this.name); + } + }, + after: function(/*excp*/){ + if(!--this.inCall){ + console.timeEnd(this.name); + } + } + }); + + aop.timer = function(/*String?*/ name){ + // summary: + // Returns an object, which can be used to time calls to methods. + // + // name: + // The optional unique name of the timer. + + return new Timer(name); // Object + }; +})(); +}); diff --git a/js/dojo/dojox/lang/aspect/tracer.js b/js/dojo/dojox/lang/aspect/tracer.js new file mode 100644 index 0000000..9186bcf --- /dev/null +++ b/js/dojo/dojox/lang/aspect/tracer.js @@ -0,0 +1,48 @@ +//>>built +// wrapped by build app +define("dojox/lang/aspect/tracer", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.aspect.tracer"); + +(function(){ + var aop = dojox.lang.aspect; + + var Tracer = function(/*Boolean*/ grouping){ + this.method = grouping ? "group" : "log"; + if(grouping){ + this.after = this._after; + } + }; + dojo.extend(Tracer, { + before: function(/*arguments*/){ + var context = aop.getContext(), joinPoint = context.joinPoint, + args = Array.prototype.join.call(arguments, ", "); + console[this.method](context.instance, "=>", joinPoint.targetName + "(" + args + ")"); + }, + afterReturning: function(retVal){ + var joinPoint = aop.getContext().joinPoint; + if(typeof retVal != "undefined"){ + console.log(joinPoint.targetName + "() returns:", retVal); + }else{ + console.log(joinPoint.targetName + "() returns"); + } + }, + afterThrowing: function(excp){ + console.log(aop.getContext().joinPoint.targetName + "() throws:", excp); + }, + _after: function(excp){ + console.groupEnd(); + } + }); + + aop.tracer = function(/*Boolean*/ grouping){ + // summary: + // Returns an object, which can be used to trace calls with Firebug's console. + // Prints argument, a return value, or an exception. + // + // grouping: + // The flag to group output. If true, indents embedded console messages. + + return new Tracer(grouping); // Object + }; +})(); +}); |
