fix($parse): Follow JavaScript context for unbound functions

Use `undefined` as the context when a function is ounbound.
E.g. when executing `foo()()`, then `foo()` is executed using the
scope as the context, the function returned by `foo()` will
have an `undefined` context
This commit is contained in:
Lucas Galfaso
2014-12-02 10:46:09 +01:00
parent a75537d461
commit 429938da1f
2 changed files with 10 additions and 3 deletions

View File

@@ -709,7 +709,7 @@ Parser.prototype = {
var args = argsFn.length ? [] : null;
return function $parseFunctionCall(scope, locals) {
var context = contextGetter ? contextGetter(scope, locals) : scope;
var context = contextGetter ? contextGetter(scope, locals) : isDefined(contextGetter) ? undefined : scope;
var fn = fnGetter(scope, locals, context) || noop;
if (args) {

View File

@@ -508,11 +508,18 @@ describe('parser', function() {
});
it('should evaluate function call from a return value', function() {
scope.val = 33;
scope.getter = function() { return function() { return this.val; }; };
scope.getter = function() { return function() { return 33; }; };
expect(scope.$eval("getter()()")).toBe(33);
});
// There is no "strict mode" in IE9
if (!msie || msie > 9) {
it('should set no context to functions returned by other functions', function() {
scope.getter = function() { return function() { expect(this).toBeUndefined(); }; };
scope.$eval("getter()()");
});
}
it('should evaluate multiplication and division', function() {
scope.taxRate = 8;
scope.subTotal = 100;