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

Commit 7812ae7

Browse files
lgalfasopetebacondarwin
authored andcommittedApr 29, 2013
fix(parse): Fix context access and double function call
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
1 parent da8c320 commit 7812ae7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed
 

‎src/ng/parse.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ function parser(text, json, $filter, csp){
438438
text.substring(0, token.index) + "] can not be assigned to", token);
439439
}
440440
right = logicalOR();
441-
return function(self, locals){
442-
return left.assign(self, right(self, locals), locals);
441+
return function(scope, locals){
442+
return left.assign(scope, right(scope, locals), locals);
443443
};
444444
} else {
445445
return left;
@@ -559,12 +559,12 @@ function parser(text, json, $filter, csp){
559559
var field = expect().text;
560560
var getter = getterFn(field, csp);
561561
return extend(
562-
function(self, locals) {
563-
return getter(object(self, locals), locals);
562+
function(scope, locals, self) {
563+
return getter(self || object(scope, locals), locals);
564564
},
565565
{
566-
assign:function(self, value, locals) {
567-
return setter(object(self, locals), field, value);
566+
assign:function(scope, value, locals) {
567+
return setter(object(scope, locals), field, value);
568568
}
569569
}
570570
);
@@ -605,14 +605,14 @@ function parser(text, json, $filter, csp){
605605
} while (expect(','));
606606
}
607607
consume(')');
608-
return function(self, locals){
608+
return function(scope, locals){
609609
var args = [],
610-
context = contextGetter ? contextGetter(self, locals) : self;
610+
context = contextGetter ? contextGetter(scope, locals) : scope;
611611

612612
for ( var i = 0; i < argsFn.length; i++) {
613-
args.push(argsFn[i](self, locals));
613+
args.push(argsFn[i](scope, locals));
614614
}
615-
var fnPtr = fn(self, locals) || noop;
615+
var fnPtr = fn(scope, locals, context) || noop;
616616
// IE stupidity!
617617
return fnPtr.apply
618618
? fnPtr.apply(context, args)

0 commit comments

Comments
 (0)
This repository has been archived.