Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(parse): fix context access and double function call
Browse files Browse the repository at this point in the history
Fix a context duplication and invocation to a previous context when
doing an access modifier function on the result of a function
Currently, when doing `foo().bar()`, `foo` is called twice, the first
time to get the context and the second one for `bar` to get the
underlying object. Then the call to `bar` is called using the second
instance as self
This is equivalent to doing:
```
var instance1 = foo();
var instance2 = foo();
instance2.bar.apply(instance1);
```

Closes #2496
  • Loading branch information
lgalfaso authored and petebacondarwin committed Apr 29, 2013
1 parent cf38d8c commit dcdf4fc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ function parser(text, json, $filter, csp){
text.substring(0, token.index) + "] can not be assigned to", token);
}
right = logicalOR();
return function(self, locals){
return left.assign(self, right(self, locals), locals);
return function(scope, locals){
return left.assign(scope, right(scope, locals), locals);
};
} else {
return left;
Expand Down Expand Up @@ -542,12 +542,12 @@ function parser(text, json, $filter, csp){
var field = expect().text;
var getter = getterFn(field, csp);
return extend(
function(self, locals) {
return getter(object(self, locals), locals);
function(scope, locals, self) {
return getter(self || object(scope, locals), locals);
},
{
assign:function(self, value, locals) {
return setter(object(self, locals), field, value);
assign:function(scope, value, locals) {
return setter(object(scope, locals), field, value);
}
}
);
Expand Down Expand Up @@ -588,14 +588,14 @@ function parser(text, json, $filter, csp){
} while (expect(','));
}
consume(')');
return function(self, locals){
return function(scope, locals){
var args = [],
context = contextGetter ? contextGetter(self, locals) : self;
context = contextGetter ? contextGetter(scope, locals) : scope;

for ( var i = 0; i < argsFn.length; i++) {
args.push(argsFn[i](self, locals));
args.push(argsFn[i](scope, locals));
}
var fnPtr = fn(self, locals) || noop;
var fnPtr = fn(scope, locals, context) || noop;
// IE stupidity!
return fnPtr.apply
? fnPtr.apply(context, args)
Expand Down

0 comments on commit dcdf4fc

Please sign in to comment.