MCPcopy
hub / github.com/angular-ui/ui-grid / createInternalInjector

Function createInternalInjector

lib/test/angular/1.4.3/angular.js:4396–4472  ·  view source on GitHub ↗
(cache, factory)

Source from the content-addressed store, hash-verified

4394 ////////////////////////////////////
4395
4396 function createInternalInjector(cache, factory) {
4397
4398 function getService(serviceName, caller) {
4399 if (cache.hasOwnProperty(serviceName)) {
4400 if (cache[serviceName] === INSTANTIATING) {
4401 throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
4402 serviceName + ' <- ' + path.join(' <- '));
4403 }
4404 return cache[serviceName];
4405 } else {
4406 try {
4407 path.unshift(serviceName);
4408 cache[serviceName] = INSTANTIATING;
4409 return cache[serviceName] = factory(serviceName, caller);
4410 } catch (err) {
4411 if (cache[serviceName] === INSTANTIATING) {
4412 delete cache[serviceName];
4413 }
4414 throw err;
4415 } finally {
4416 path.shift();
4417 }
4418 }
4419 }
4420
4421 function invoke(fn, self, locals, serviceName) {
4422 if (typeof locals === 'string') {
4423 serviceName = locals;
4424 locals = null;
4425 }
4426
4427 var args = [],
4428 $inject = createInjector.$$annotate(fn, strictDi, serviceName),
4429 length, i,
4430 key;
4431
4432 for (i = 0, length = $inject.length; i < length; i++) {
4433 key = $inject[i];
4434 if (typeof key !== 'string') {
4435 throw $injectorMinErr('itkn',
4436 'Incorrect injection token! Expected service name as string, got {0}', key);
4437 }
4438 args.push(
4439 locals && locals.hasOwnProperty(key)
4440 ? locals[key]
4441 : getService(key, serviceName)
4442 );
4443 }
4444 if (isArray(fn)) {
4445 fn = fn[length];
4446 }
4447
4448 // http://jsperf.com/angularjs-invoke-apply-vs-switch
4449 // #5388
4450 return fn.apply(self, args);
4451 }
4452
4453 function instantiate(Type, locals, serviceName) {

Callers 1

createInjectorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected