| 4514 | //////////////////////////////////// |
| 4515 | |
| 4516 | function createInternalInjector(cache, factory) { |
| 4517 | |
| 4518 | function getService(serviceName, caller) { |
| 4519 | if (cache.hasOwnProperty(serviceName)) { |
| 4520 | if (cache[serviceName] === INSTANTIATING) { |
| 4521 | throw $injectorMinErr('cdep', 'Circular dependency found: {0}', |
| 4522 | serviceName + ' <- ' + path.join(' <- ')); |
| 4523 | } |
| 4524 | return cache[serviceName]; |
| 4525 | } else { |
| 4526 | try { |
| 4527 | path.unshift(serviceName); |
| 4528 | cache[serviceName] = INSTANTIATING; |
| 4529 | return cache[serviceName] = factory(serviceName, caller); |
| 4530 | } catch (err) { |
| 4531 | if (cache[serviceName] === INSTANTIATING) { |
| 4532 | delete cache[serviceName]; |
| 4533 | } |
| 4534 | throw err; |
| 4535 | } finally { |
| 4536 | path.shift(); |
| 4537 | } |
| 4538 | } |
| 4539 | } |
| 4540 | |
| 4541 | function invoke(fn, self, locals, serviceName) { |
| 4542 | if (typeof locals === 'string') { |
| 4543 | serviceName = locals; |
| 4544 | locals = null; |
| 4545 | } |
| 4546 | |
| 4547 | var args = [], |
| 4548 | $inject = createInjector.$$annotate(fn, strictDi, serviceName), |
| 4549 | length, i, |
| 4550 | key; |
| 4551 | |
| 4552 | for (i = 0, length = $inject.length; i < length; i++) { |
| 4553 | key = $inject[i]; |
| 4554 | if (typeof key !== 'string') { |
| 4555 | throw $injectorMinErr('itkn', |
| 4556 | 'Incorrect injection token! Expected service name as string, got {0}', key); |
| 4557 | } |
| 4558 | args.push( |
| 4559 | locals && locals.hasOwnProperty(key) |
| 4560 | ? locals[key] |
| 4561 | : getService(key, serviceName) |
| 4562 | ); |
| 4563 | } |
| 4564 | if (isArray(fn)) { |
| 4565 | fn = fn[length]; |
| 4566 | } |
| 4567 | |
| 4568 | // http://jsperf.com/angularjs-invoke-apply-vs-switch |
| 4569 | // #5388 |
| 4570 | return fn.apply(self, args); |
| 4571 | } |
| 4572 | |
| 4573 | function instantiate(Type, locals, serviceName) { |