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

Commit 71f437c

Browse files
thorn0gkalpak
authored andcommitted
refactor($rootScope): remove extraneous call to $parse in $evalAsync
Closes #15682
1 parent 2c7400e commit 71f437c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/ng/rootScope.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,13 @@ function $RootScopeProvider() {
786786
current = target;
787787

788788
// It's safe for asyncQueuePosition to be a local variable here because this loop can't
789-
// be reentered recursively. Calling $digest from a function passed to $applyAsync would
789+
// be reentered recursively. Calling $digest from a function passed to $evalAsync would
790790
// lead to a '$digest already in progress' error.
791791
for (var asyncQueuePosition = 0; asyncQueuePosition < asyncQueue.length; asyncQueuePosition++) {
792792
try {
793793
asyncTask = asyncQueue[asyncQueuePosition];
794-
asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals);
794+
fn = asyncTask.fn;
795+
fn(asyncTask.scope, asyncTask.locals);
795796
} catch (e) {
796797
$exceptionHandler(e);
797798
}
@@ -1025,7 +1026,7 @@ function $RootScopeProvider() {
10251026
});
10261027
}
10271028

1028-
asyncQueue.push({scope: this, expression: $parse(expr), locals: locals});
1029+
asyncQueue.push({scope: this, fn: $parse(expr), locals: locals});
10291030
},
10301031

10311032
$$postDigest: function(fn) {

test/ng/rootScopeSpec.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1444,9 +1444,9 @@ describe('Scope', function() {
14441444
expect(childScope.$$asyncQueue).toBe($rootScope.$$asyncQueue);
14451445
expect(isolateScope.$$asyncQueue).toBeUndefined();
14461446
expect($rootScope.$$asyncQueue).toEqual([
1447-
{scope: $rootScope, expression: $parse('rootExpression'), locals: undefined},
1448-
{scope: childScope, expression: $parse('childExpression'), locals: undefined},
1449-
{scope: isolateScope, expression: $parse('isolateExpression'), locals: undefined}
1447+
{scope: $rootScope, fn: $parse('rootExpression'), locals: undefined},
1448+
{scope: childScope, fn: $parse('childExpression'), locals: undefined},
1449+
{scope: isolateScope, fn: $parse('isolateExpression'), locals: undefined}
14501450
]);
14511451
}));
14521452

@@ -1499,6 +1499,14 @@ describe('Scope', function() {
14991499
expect(log).toEqual(['eval-ed 1!', 'eval-ed 2!']);
15001500
});
15011501
});
1502+
1503+
it('should not pass anything as `this` to scheduled functions', inject(function($rootScope) {
1504+
var this1 = {};
1505+
var this2 = (function() { return this; })();
1506+
$rootScope.$evalAsync(function() { this1 = this; });
1507+
$rootScope.$digest();
1508+
expect(this1).toEqual(this2);
1509+
}));
15021510
});
15031511

15041512

0 commit comments

Comments
 (0)