'this' being set incorrectly

Oct 16, 2013 at 2:16 AM
Edited Oct 16, 2013 at 2:17 AM
The following code incorrectly results in the variable 'result' pointing to the arguments pseudo variable of the anonymous function assigned to f:
var result;
var f = function(g) { g(); }
function h() { result=this };
The problem is that ExecutionVisitor.Visit(Identifier expression) when processing a LinkedDescriptor stores the target of the linked descriptor in the current CallTarget property, hence after looking up 'g' and finding it's a LinkedDescriptor for the 'arguments' pseudo-variable, CallTarget is set to 'arguments', and hence when the function g is called, "this" gets set to arguments. This is definitely incorrect and in fact I don't believe there are any circumstances under which resolving an identifier to a LinkedDescriptor should cause the current CallTarget to change, so I've changed the code as follows:
                LinkedDescriptor r = result as LinkedDescriptor;
                SetResult(r.Get(CurrentScope), null);
where 'null' used to be r.targetObject. I think the only time CallTarget should be changed is while processing a PropertyExpression, i.e. when executing FOO.BAR(), 'this' should point to FOO when BAR is called.