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

Commit 372fa69

Browse files
committed
fix($injector): ensure $get method invoked with provider context
0d3b69a broke this by calling $get with an undefined context, which in strict mode would be undefined. This fixes this by ensuring that the provider is used as the context, as it was originally. Closes #9511 Closes #9512
1 parent 7b10232 commit 372fa69

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/auto/injector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ function createInjector(modulesToLoad, strictDi) {
664664

665665
function enforceReturnValue(name, factory) {
666666
return function enforcedReturnValue() {
667-
var result = instanceInjector.invoke(factory);
667+
var result = instanceInjector.invoke(factory, this, undefined, name);
668668
if (isUndefined(result)) {
669669
throw $injectorMinErr('undef', "Provider '{0}' must return a value from $get factory method.", name);
670670
}

test/auto/injectorSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -993,4 +993,21 @@ describe('strict-di injector', function() {
993993
inject(function($test) {});
994994
}).toThrowMinErr('$injector', 'undef');
995995
});
996+
997+
998+
it('should always use provider as `this` when invoking a factory', function() {
999+
var called = false;
1000+
function factoryFn() {
1001+
called = true;
1002+
// jshint -W040
1003+
expect(typeof this.$get).toBe('function');
1004+
// jshint +W040
1005+
return this;
1006+
}
1007+
module(function($provide) {
1008+
$provide.factory('$test', factoryFn);
1009+
});
1010+
inject(function($test) {});
1011+
expect(called).toBe(true);
1012+
});
9961013
});

0 commit comments

Comments
 (0)