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

Function maybeLoadCorrectVersion

src/runtime.js:466–501  ·  view source on GitHub ↗

* For a given extension, checks that its version is the same * as the version of the main AMP binary. * If yes, returns false and does nothing else. * If they are different, returns false, and initiates a load * of the respective extension via a versioned URL. * * @param {!Window} win * @para

(win, fnOrStruct)

Source from the content-addressed store, hash-verified

464 * @return {boolean}
465 */
466function maybeLoadCorrectVersion(win, fnOrStruct) {
467 if (getMode().localDev && isExperimentOn(win, 'disable-version-locking')) {
468 return false;
469 }
470 if (typeof fnOrStruct == 'function') {
471 return false;
472 }
473
474 if (mode.isEsm()) {
475 // If we're in a module runtime, trying to execute a nomodule extension
476 // simply remove the nomodule extension so that it is not executed.
477 if (!fnOrStruct.m) {
478 return true;
479 }
480 } else {
481 // If we're in a nomodule runtime, trying to execute a module extension
482 // simply remove the module extension so that it is not executed.
483 if (fnOrStruct.m) {
484 return true;
485 }
486 }
487
488 const {v} = fnOrStruct;
489 // This is non-obvious, but we only care about the release version,
490 // not about the full rtv version, because these only differ
491 // in the config that is fully determined by the primary binary.
492 if (mode.version() == v) {
493 return false;
494 }
495 Services.extensionsFor(win).reloadExtension(
496 fnOrStruct.n,
497 fnOrStruct.ev,
498 fnOrStruct.l
499 );
500 return true;
501}
502
503/**
504 * If it makes sense, let the browser paint the current frame before

Callers 1

adoptSharedFunction · 0.85

Calls 3

getModeFunction · 0.90
reloadExtensionMethod · 0.80
isExperimentOnFunction · 0.50

Tested by

no test coverage detected