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

Function getExperiments

third_party/subscriptions-project/swg.js:7486–7517  ·  view source on GitHub ↗

* Ensures that the experiments have been initialized and returns them. * @param {!Window} win * @return {!Object }

(win)

Source from the content-addressed store, hash-verified

7484 * @return {!Object<string, boolean>}
7485 */
7486function getExperiments(win) {
7487 if (!experimentMap) {
7488 experimentMap = {};
7489 let combinedExperimentString = experimentsString;
7490 try {
7491 const query = parseQueryString(win.location.hash);
7492 const experimentStringFromHash = query['swg.experiments'];
7493 if (experimentStringFromHash) {
7494 combinedExperimentString += ',' + experimentStringFromHash;
7495 }
7496 } catch (e) {
7497 // Ignore: experiment parsing cannot block runtime.
7498 ErrorUtils.throwAsync(e);
7499 }
7500
7501 // Format:
7502 // - experimentString = (experimentSpec,)*
7503 for (let experimentString of combinedExperimentString.split(',')) {
7504 experimentString = experimentString.trim();
7505 if (!experimentString) {
7506 continue;
7507 }
7508 try {
7509 parseSetExperiment(win, experimentMap, experimentString);
7510 } catch (e) {
7511 // Ignore: experiment parsing cannot block runtime.
7512 ErrorUtils.throwAsync(e);
7513 }
7514 }
7515 }
7516 return experimentMap;
7517}
7518
7519/**
7520 * @param {!Window} win

Callers 3

isExperimentOnFunction · 0.85
setExperimentFunction · 0.85
getOnExperimentsFunction · 0.85

Calls 3

parseSetExperimentFunction · 0.85
throwAsyncMethod · 0.80
parseQueryStringFunction · 0.70

Tested by

no test coverage detected