Skip to content
Permalink
Browse files

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
  • Loading branch information
lgalfaso committed Dec 2, 2014
1 parent a75537d commit 429938da1f45b8a649b8c77762fb0ae59b6d0cea
Showing with 10 additions and 3 deletions.
  1. +1 −1 src/ng/parse.js
  2. +9 −2 test/ng/parseSpec.js
@@ -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) {
@@ -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;

0 comments on commit 429938d

Please sign in to comment.
You can’t perform that action at this time.