Skip to content

Commit

Permalink
fix($compile): fix memory leak
Browse files Browse the repository at this point in the history
For functions that have a '&' binding on the scope, change the function
from an inline definition to an external definition so the function
closure has no access to the parent scope.
Backport of fix on 1.3.x

Closes angular#6794
  • Loading branch information
btesser committed Mar 23, 2014
1 parent a9b5a10 commit f80a3b1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,9 +1462,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {

case '&':
parentGet = $parse(attrs[attrName]);
isolateScope[scopeName] = function(locals) {
return parentGet(scope, locals);
};
isolateScope[scopeName] = parentGetFn(parentGet, scope);
break;

default:
Expand Down Expand Up @@ -1809,8 +1807,19 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
});
}
}


/**
* Wrapper for '&' One-way binding to prevent memory leak.
* Backport from 1.3.x fix for bug #6794.
* @param {function} parentGet Gets value from parent
* @param {ng.$rootScope.Scope} scope Target Scope
* @return {function} & Binding Fn
*/
function parentGetFn(parentGet, scope) {
return function (locals) {
return parentGet(scope, locals);
};
}

function getTrustedContext(node, attrNormalizedName) {
if (attrNormalizedName == "srcdoc") {
return $sce.HTML;
Expand Down

0 comments on commit f80a3b1

Please sign in to comment.