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

Commit a13f83e

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.
1 parent 7b10232 commit a13f83e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-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

+16
Original file line numberDiff line numberDiff line change
@@ -993,4 +993,20 @@ 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+
'use strict';
1000+
var called = false;
1001+
function factoryFn() {
1002+
called = true;
1003+
expect(typeof this.$get).toBe('function');
1004+
return this;
1005+
}
1006+
module(function($provide) {
1007+
$provide.factory('$test', factoryFn);
1008+
});
1009+
inject(function($test) {});
1010+
expect(called).toBe(true);
1011+
});
9961012
});

0 commit comments

Comments
 (0)