source: Dev/trunk/src/client/dojox/lang/oo/aop.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.8 KB
Line 
1dojo.provide("dojox.lang.oo.aop");
2
3dojo.require("dojox.lang.oo.Decorator");
4dojo.require("dojox.lang.oo.general");
5
6(function(){
7        var oo = dojox.lang.oo, md = oo.makeDecorator, oog = oo.general, ooa = oo.aop,
8                isF = dojo.isFunction;
9
10        // five decorators implementing light-weight AOP weaving
11
12        // reuse existing decorators
13        ooa.before = oog.before;
14        ooa.around = oog.wrap;
15
16        /*=====
17        ooa.before = md(function(name, newValue, oldValue){
18                // summary:
19                //              creates a "before" advise, by calling new function
20                //              before the old one
21
22                // dummy body
23        });
24
25        ooa.around = md(function(name, newValue, oldValue){
26                // summary:
27                //              creates an "around" advise,
28                //              the previous value is passed as a first argument and can be null,
29                //              arguments are passed as a second argument
30
31                // dummy body
32        });
33        =====*/
34
35
36        ooa.afterReturning = md(function(name, newValue, oldValue){
37                // summary:
38                //              creates an "afterReturning" advise,
39                //              the returned value is passed as the only argument
40                return isF(oldValue) ?
41                        function(){
42                                var ret = oldValue.apply(this, arguments);
43                                newValue.call(this, ret);
44                                return ret;
45                        } : function(){ newValue.call(this); };
46        });
47
48        ooa.afterThrowing = md(function(name, newValue, oldValue){
49                // summary:
50                //              creates an "afterThrowing" advise,
51                //              the exception is passed as the only argument
52                return isF(oldValue) ?
53                        function(){
54                                var ret;
55                                try{
56                                        ret = oldValue.apply(this, arguments);
57                                }catch(e){
58                                        newValue.call(this, e);
59                                        throw e;
60                                }
61                                return ret;
62                        } : oldValue;
63        });
64
65        ooa.after = md(function(name, newValue, oldValue){
66                // summary:
67                //              creates an "after" advise,
68                //              it takes no arguments
69                return isF(oldValue) ?
70                        function(){
71                                var ret;
72                                try{
73                                        ret = oldValue.apply(this, arguments);
74                                }finally{
75                                        newValue.call(this);
76                                }
77                                return ret;
78                        } : function(){ newValue.call(this); }
79        });
80})();
Note: See TracBrowser for help on using the repository browser.