MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / createInternalInjector

Function createInternalInjector

code/songhop/www/lib/angular/angular.js:4115–4191  ·  view source on GitHub ↗
(cache, factory)

Source from the content-addressed store, hash-verified

4113 ////////////////////////////////////
4114
4115 function createInternalInjector(cache, factory) {
4116
4117 function getService(serviceName, caller) {
4118 if (cache.hasOwnProperty(serviceName)) {
4119 if (cache[serviceName] === INSTANTIATING) {
4120 throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
4121 serviceName + ' <- ' + path.join(' <- '));
4122 }
4123 return cache[serviceName];
4124 } else {
4125 try {
4126 path.unshift(serviceName);
4127 cache[serviceName] = INSTANTIATING;
4128 return cache[serviceName] = factory(serviceName, caller);
4129 } catch (err) {
4130 if (cache[serviceName] === INSTANTIATING) {
4131 delete cache[serviceName];
4132 }
4133 throw err;
4134 } finally {
4135 path.shift();
4136 }
4137 }
4138 }
4139
4140 function invoke(fn, self, locals, serviceName) {
4141 if (typeof locals === 'string') {
4142 serviceName = locals;
4143 locals = null;
4144 }
4145
4146 var args = [],
4147 $inject = annotate(fn, strictDi, serviceName),
4148 length, i,
4149 key;
4150
4151 for (i = 0, length = $inject.length; i < length; i++) {
4152 key = $inject[i];
4153 if (typeof key !== 'string') {
4154 throw $injectorMinErr('itkn',
4155 'Incorrect injection token! Expected service name as string, got {0}', key);
4156 }
4157 args.push(
4158 locals && locals.hasOwnProperty(key)
4159 ? locals[key]
4160 : getService(key, serviceName)
4161 );
4162 }
4163 if (isArray(fn)) {
4164 fn = fn[length];
4165 }
4166
4167 // http://jsperf.com/angularjs-invoke-apply-vs-switch
4168 // #5388
4169 return fn.apply(self, args);
4170 }
4171
4172 function instantiate(Type, locals, serviceName) {

Callers 1

createInjectorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected