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?
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.