MCPcopy Index your code
hub / github.com/ampproject/amphtml / getAuthorScript_

Method getAuthorScript_

extensions/amp-script/0.1/amp-script.js:397–429  ·  view source on GitHub ↗

* Query local or fetch remote author script. * * Returns promise that resolves with the script contents or rejected if the * fetch fails or if the script fails CORS checks. * * Returns null if script reference is missing. * * @param {string} debugId An element identifier for err

(debugId)

Source from the content-addressed store, hash-verified

395 * @private
396 */
397 getAuthorScript_(debugId) {
398 const authorUrl = this.element.getAttribute('src');
399 if (authorUrl) {
400 return this.fetchAuthorScript_(authorUrl, debugId);
401 } else {
402 const id = this.element.getAttribute('script');
403 if (id) {
404 const local = this.getAmpDoc().getElementById(id);
405 userAssert(
406 local,
407 '[%s] %s could not find element with #%s.',
408 TAG,
409 debugId,
410 id
411 );
412 const target = local.getAttribute('target');
413 userAssert(
414 target === 'amp-script',
415 '[%s] script#%s must have target="amp-script".',
416 TAG,
417 id
418 );
419 const text = local.textContent;
420 if (this.development_ || this.sandboxed_) {
421 return Promise.resolve(text);
422 } else {
423 return this.service_.checkSha384(text, debugId).then(() => text);
424 }
425 }
426 }
427 // No [src] or [script].
428 return null;
429 }
430
431 /**
432 * @param {string} authorUrl

Callers 1

layoutCallbackMethod · 0.95

Calls 8

fetchAuthorScript_Method · 0.95
userAssertFunction · 0.90
getAttributeMethod · 0.80
resolveMethod · 0.80
checkSha384Method · 0.80
getElementByIdMethod · 0.45
getAmpDocMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected