MCPcopy
hub / github.com/ampproject/amphtml / getServiceInternal

Function getServiceInternal

src/service-helpers.js:340–360  ·  view source on GitHub ↗

* Get service `id` from `holder`. Assumes the service * has already been registered. * @param {!Object} holder Object holding the service instance. * @param {string} id of the service. * @return {object}

(holder, id)

Source from the content-addressed store, hash-verified

338 * @return {object}
339 */
340function getServiceInternal(holder, id) {
341 devAssert(
342 isServiceRegistered(holder, id),
343 `Expected service ${id} to be registered`
344 );
345 const services = getServices(holder);
346 const s = services[id];
347 if (!s.obj) {
348 devAssert(s.ctor, `Service ${id} registered without ctor nor impl.`);
349 devAssert(s.context, `Service ${id} registered without context.`);
350 s.obj = new s.ctor(s.context);
351 devAssert(s.obj, `Service ${id} constructed to null.`);
352 s.context = null;
353 // The service may have been requested already, in which case we have a
354 // pending promise we need to fulfill.
355 if (s.resolve) {
356 s.resolve(s.obj);
357 }
358 }
359 return s.obj;
360}
361
362/**
363 * @param {!Object} holder Object holding the service instance.

Callers 10

registerServiceBuilderFunction · 0.85
getServiceFunction · 0.85
getServiceInEmbedWinFunction · 0.85
getExistingServiceOrNullFunction · 0.85
getServiceForDocFunction · 0.85
getServiceForDocOrNullFunction · 0.85
registerServiceInternalFunction · 0.85
adoptServiceForEmbedDocFunction · 0.85

Calls 4

devAssertFunction · 0.90
isServiceRegisteredFunction · 0.85
getServicesFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected