Re: AspectScript jp.proceed question

1 view
Skip to first unread message
Message has been deleted
Message has been deleted

Rodolfo Toledo

unread,
Mar 4, 2010, 10:27:45 AM3/4/10
to AspectScript
(This question was sent to my personal e-mail. I post it here so it
can help others too).
------

Hi,

Played with AspectScript, and had unexpected result with the code
below in the scratchpad (it prints 5 rather than 8):

//----------
var x = 5;
var f = function(){
x=8;

};

var pc = function(jp){
return true;
};

var adv = function(jp){
jp.proceed();
document.getElementById("jps").innerHTML = x;

};

AspectScript.around(pc, adv);

f();
//----------

Is this the expected behavior?

Rodolfo Toledo

unread,
Mar 4, 2010, 10:28:13 AM3/4/10
to AspectScript
Hi,

Yes, the behavior is correct :)

The reason is the join points AspectScript generates: your pointcut is
not only matching the call to "f", but also the property read of "f",
then the call to "f", then the execution of "f", and then the property
write of "x".

So the problem is that the advice don't return the value resulting
from jp.proceed(). Therefore, the first join point (the property read
of "f") resolves to undefined, and then, no function can be called
(you can observe this error in the error console).

To solve the problem, I changed your code a little bit to return the
value resulting from jp.proceed():

-------------------------


var x = 5;
var f = function(){
x=8;

};

var pc = function(jp){
return true;
};

var adv = function(jp){
var z = jp.proceed();


document.getElementById("jps").innerHTML = x;

return z;

};

AspectScript.around(pc, adv);

f();
-------------------------

The result of running this program is what you expected: 8.

I hope this answers your question. Anyway, if you have further
questions, do not hesitate to ask.

Regards,
Rodolfo Toledo.

Reply all
Reply to author
Forward
0 new messages