| 4163 | //////////////////////////////////// |
| 4164 | |
| 4165 | function createInternalInjector(cache, factory) { |
| 4166 | |
| 4167 | function getService(serviceName, caller) { |
| 4168 | if (cache.hasOwnProperty(serviceName)) { |
| 4169 | if (cache[serviceName] === INSTANTIATING) { |
| 4170 | throw $injectorMinErr('cdep', 'Circular dependency found: {0}', |
| 4171 | serviceName + ' <- ' + path.join(' <- ')); |
| 4172 | } |
| 4173 | return cache[serviceName]; |
| 4174 | } else { |
| 4175 | try { |
| 4176 | path.unshift(serviceName); |
| 4177 | cache[serviceName] = INSTANTIATING; |
| 4178 | return cache[serviceName] = factory(serviceName, caller); |
| 4179 | } catch (err) { |
| 4180 | if (cache[serviceName] === INSTANTIATING) { |
| 4181 | delete cache[serviceName]; |
| 4182 | } |
| 4183 | throw err; |
| 4184 | } finally { |
| 4185 | path.shift(); |
| 4186 | } |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | function invoke(fn, self, locals, serviceName) { |
| 4191 | if (typeof locals === 'string') { |
| 4192 | serviceName = locals; |
| 4193 | locals = null; |
| 4194 | } |
| 4195 | |
| 4196 | var args = [], |
| 4197 | $inject = createInjector.$$annotate(fn, strictDi, serviceName), |
| 4198 | length, i, |
| 4199 | key; |
| 4200 | |
| 4201 | for (i = 0, length = $inject.length; i < length; i++) { |
| 4202 | key = $inject[i]; |
| 4203 | if (typeof key !== 'string') { |
| 4204 | throw $injectorMinErr('itkn', |
| 4205 | 'Incorrect injection token! Expected service name as string, got {0}', key); |
| 4206 | } |
| 4207 | args.push( |
| 4208 | locals && locals.hasOwnProperty(key) |
| 4209 | ? locals[key] |
| 4210 | : getService(key, serviceName) |
| 4211 | ); |
| 4212 | } |
| 4213 | if (isArray(fn)) { |
| 4214 | fn = fn[length]; |
| 4215 | } |
| 4216 | |
| 4217 | // http://jsperf.com/angularjs-invoke-apply-vs-switch |
| 4218 | // #5388 |
| 4219 | return fn.apply(self, args); |
| 4220 | } |
| 4221 | |
| 4222 | function instantiate(Type, locals, serviceName) { |