why meld need push joinpoint to stack and remove it again (question about meld.js)

27 views
Skip to first unread message

Edwin Liu

unread,
Apr 22, 2013, 2:37:15 PM4/22/13
to cuj...@googlegroups.com

the follow code, first push joinpoint to a stack , and then remove it

so what's the reason?

// TODO: Use Object.freeze once v8 perf problem is fixed
                joinpoint = pushJoinpoint({
                    target: context,
                    method: method,
                    args: args,
                    proceed: proceedCall,
                    proceedApply: proceedApply,
                    proceedCount: proceedCount
                });

                try {
                    // Call supplied around advice function
                    return around.call(context, joinpoint);
                } finally {
                    popJoinpoint();
                }

Brian Cavalier

unread,
Apr 22, 2013, 3:59:59 PM4/22/13
to cuj...@googlegroups.com
Hey Edwin,

This allows meld to provide access to the current joinpoint, with instances of proceedCall, proceedApply, and proceedCount that are specific to the particular around advice that is about to be executed.  Since around advices are nested (they are like layers around the original function), that prevents one around advice from calling meld.joinpoint() and gaining access to the proceedCall and proceedCount functions that are specific to another around advice.

Hope that helps!
Message has been deleted

Edwin Liu

unread,
Apr 22, 2013, 4:14:40 PM4/22/13
to cuj...@googlegroups.com
can you show me some example , I did not find any difference with the follow code
joinpoint = {
                    target: context,
                    method: method,
                    args: args,
                    proceed: proceedCall,
                    proceedApply: proceedApply,
                    proceedCount: proceedCount
                }
return around.call(context, joinpoint);

在 2013年4月23日星期二UTC+8上午2时37分15秒,Edwin Liu写道:

Brian Cavalier

unread,
Apr 23, 2013, 8:45:52 AM4/23/13
to
Edwin,

Since meld provides access to the current jointpoint via meld.joinpoint() (this is useful in advises like before/after/etc to which the joinpoint is not passed directly), it's important that meld.joinpoint() provide the *same* joinpoint as the one that is passed into around advice.  Here's an example:

var meld = require('meld');

// A simple test fixture object to advise
var o1 = {
method: function(x) {}
};

meld.around(o1, 'method', function(joinpoint) {
// meld.joinpoint() here MUST provide the new args
// This should log true
console.log(meld.joinpoint().args[0] === joinpoint.args[0]);
});

meld.around(o1, 'method', function(joinpoint) {
// Proceed with different args
return joinpoint.proceed(2);
});

// Call advised
o1.method(1);

If you run that test with your version, it will log false.  Does that help to clarify?
Reply all
Reply to author
Forward
0 new messages