| 3916 | //////////////////////////////////// |
| 3917 | |
| 3918 | function createInternalInjector(cache, factory) { |
| 3919 | |
| 3920 | function getService(serviceName) { |
| 3921 | if (cache.hasOwnProperty(serviceName)) { |
| 3922 | if (cache[serviceName] === INSTANTIATING) { |
| 3923 | throw $injectorMinErr('cdep', 'Circular dependency found: {0}', |
| 3924 | serviceName + ' <- ' + path.join(' <- ')); |
| 3925 | } |
| 3926 | return cache[serviceName]; |
| 3927 | } else { |
| 3928 | try { |
| 3929 | path.unshift(serviceName); |
| 3930 | cache[serviceName] = INSTANTIATING; |
| 3931 | return cache[serviceName] = factory(serviceName); |
| 3932 | } catch (err) { |
| 3933 | if (cache[serviceName] === INSTANTIATING) { |
| 3934 | delete cache[serviceName]; |
| 3935 | } |
| 3936 | throw err; |
| 3937 | } finally { |
| 3938 | path.shift(); |
| 3939 | } |
| 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | function invoke(fn, self, locals){ |
| 3944 | var args = [], |
| 3945 | $inject = annotate(fn), |
| 3946 | length, i, |
| 3947 | key; |
| 3948 | |
| 3949 | for(i = 0, length = $inject.length; i < length; i++) { |
| 3950 | key = $inject[i]; |
| 3951 | if (typeof key !== 'string') { |
| 3952 | throw $injectorMinErr('itkn', |
| 3953 | 'Incorrect injection token! Expected service name as string, got {0}', key); |
| 3954 | } |
| 3955 | args.push( |
| 3956 | locals && locals.hasOwnProperty(key) |
| 3957 | ? locals[key] |
| 3958 | : getService(key) |
| 3959 | ); |
| 3960 | } |
| 3961 | if (isArray(fn)) { |
| 3962 | fn = fn[length]; |
| 3963 | } |
| 3964 | |
| 3965 | // http://jsperf.com/angularjs-invoke-apply-vs-switch |
| 3966 | // #5388 |
| 3967 | return fn.apply(self, args); |
| 3968 | } |
| 3969 | |
| 3970 | function instantiate(Type, locals) { |
| 3971 | var Constructor = function() {}, |
| 3972 | instance, returnedValue; |
| 3973 | |
| 3974 | // Check if Type is annotated and use just the given function at n-1 as parameter |
| 3975 | // e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]); |